Popular recipes by Michal Niklas http://code.activestate.com/recipes/users/186902/2014-12-11T10:07:39-08:00ActiveState Code RecipesPrinting list of ODBC data sources with pyodbc module (Python) 2014-01-28T10:40:56-08:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/578815-printing-list-of-odbc-data-sources-with-pyodbc-mod/ <p style="color: grey"> Python recipe 578815 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/odbc/">odbc</a>, <a href="/recipes/tags/sql/">sql</a>). </p> <p>I have similar recipe but with <code>odbc</code> module: <a href="http://code.activestate.com/recipes/578782-printing-list-of-odbc-data-sources/" rel="nofollow">http://code.activestate.com/recipes/578782-printing-list-of-odbc-data-sources/</a></p> Printing list of ODBC data sources (Python) 2013-12-10T11:07:37-08:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/578782-printing-list-of-odbc-data-sources/ <p style="color: grey"> Python recipe 578782 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/odbc/">odbc</a>, <a href="/recipes/tags/sql/">sql</a>). </p> <p>This simple code shows ODBC data sources. It uses <code>odbc</code> module.</p> Mazovia encoding for Polish text from MS-DOS era (Python) 2012-02-15T09:24:13-08:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/578040-mazovia-encoding-for-polish-text-from-ms-dos-era/ <p style="color: grey"> Python recipe 578040 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/encoding/">encoding</a>, <a href="/recipes/tags/mazovia/">mazovia</a>, <a href="/recipes/tags/polish/">polish</a>). </p> <p>Some MS-DOS era text or databases in Poland use Mazovia encoding for letters such as: ą, ę, ś, ż, ź. It is very well described on Polish wikipedia: <a href="http://pl.wikipedia.org/wiki/Mazovia_%28kod%29" rel="nofollow">http://pl.wikipedia.org/wiki/Mazovia_(kod)</a></p> <p>There is <code>mazovia.py</code> with Polish encoding. Copy it to the Python <code>Lib/encodings</code> directory. Tested with Python 2.7. For Python 3.2 I had to remove unicode string u prefix.</p> <p>Usage:</p> <pre class="prettyprint"><code>def conv_file(fname): f = codecs.open(fname, 'rb', 'mazovia') s = f.read() f.close() f = codecs.open(fname + '_utf8', 'wb', 'utf8') f.write(s) f.close() </code></pre> Binary BCD clock using curses (Python) 2010-10-19T10:40:36-07:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/577430-binary-bcd-clock-using-curses/ <p style="color: grey"> Python recipe 577430 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/curses/">curses</a>, <a href="/recipes/tags/time/">time</a>). </p> <p>Converts actual time to vertical BCD digits. So actual time, 12:37:51 looks like:</p> <pre class="prettyprint"><code>...... ...**. .***.. *.**** </code></pre> Python program that show .class files from *.jar (Python) 2010-07-22T09:13:59-07:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/577328-python-program-that-show-class-files-from-jar/ <p style="color: grey"> Python recipe 577328 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/jar/">jar</a>, <a href="/recipes/tags/java/">java</a>). </p> <p>This program iterate through .jar files and print .class files from it</p> Redate source files using SVN info from $Id:$ (Python) 2010-07-30T10:00:25-07:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/577341-redate-source-files-using-svn-info-from-id/ <p style="color: grey"> Python recipe 577341 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/datetime/">datetime</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/svn/">svn</a>). </p> <p>Iterates through a directory, reading the data from svn info that looks like:</p> <pre class="prettyprint"><code>$Id: svn_redater.py 747 2010-07-30 09:56:08Z mn $ </code></pre> <p>from source files.</p> <p>Parses the datetime from svn info and if it differs from file modification datetime then changes file datetime</p> Calculate distance from .kmz files (Python) 2009-05-31T23:59:34-07:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/576782-calculate-distance-from-kmz-files/ <p style="color: grey"> Python recipe 576782 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/distance/">distance</a>, <a href="/recipes/tags/geocoding/">geocoding</a>, <a href="/recipes/tags/google_earth/">google_earth</a>, <a href="/recipes/tags/kmz/">kmz</a>, <a href="/recipes/tags/points/">points</a>). Revision 2. </p> <p>Calculates distance in kilometers from points saved in .kmz file. Such files can be created by Google Earth</p> Dump Oracle db schema to text (Python) 2014-02-21T09:18:55-08:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/576534-dump-oracle-db-schema-to-text/ <p style="color: grey"> Python recipe 576534 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/oracle/">oracle</a>, <a href="/recipes/tags/schema/">schema</a>). Revision 19. </p> <p>Export Oracle schema to text. Usable to compare databases that should be the same</p> <p>Oracle schema info: <a href="http://www.eveandersson.com/writing/data-model-reverse-engineering" rel="nofollow">http://www.eveandersson.com/writing/data-model-reverse-engineering</a></p> <p>With <code>--separate-files</code> can save table information as <code>CREATE TABLE</code> statements and all view/function art objects are in separate files (sometime it is easier to compare directories with files than compare two big files)</p> Dump Informix schema to text (Python) 2014-02-21T09:16:15-08:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/576621-dump-informix-schema-to-text/ <p style="color: grey"> Python recipe 576621 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/informix/">informix</a>, <a href="/recipes/tags/schema/">schema</a>). Revision 6. </p> <p>I needed "normalized" dump of Informix database so I can easily compare two databases. I have similar tools for other databases:</p> <p>PostgreSQL: <a href="http://code.activestate.com/recipes/576557/" rel="nofollow">http://code.activestate.com/recipes/576557/</a></p> <p>Oracle: <a href="http://code.activestate.com/recipes/576534/" rel="nofollow">http://code.activestate.com/recipes/576534/</a></p> Dump PostgreSQL db schema to text (Python) 2014-02-21T09:17:23-08:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/576557-dump-postgresql-db-schema-to-text/ <p style="color: grey"> Python recipe 576557 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/postgres/">postgres</a>, <a href="/recipes/tags/postgresql/">postgresql</a>, <a href="/recipes/tags/schema/">schema</a>). Revision 7. </p> <p>With PostgreSQL there is:</p> <pre class="prettyprint"><code>pg_dump --schema_only </code></pre> <p>but I wanted to compare my PostgreSQL and Oracle database schema dumped by: <a href="http://code.activestate.com/recipes/576534/">http://code.activestate.com/recipes/576534/</a></p> Sort sections and keys in .ini file (Python) 2008-12-19T05:46:05-08:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/576587-sort-sections-and-keys-in-ini-file/ <p style="color: grey"> Python recipe 576587 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/config/">config</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/ini/">ini</a>, <a href="/recipes/tags/sort/">sort</a>). Revision 3. </p> <p>I use this program when I want to make .ini file more readable or compare two .ini files</p> Searching .dll and .exe files in PATH (Python) 2014-10-06T09:22:53-07:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/576522-searching-dll-and-exe-files-in-path/ <p style="color: grey"> Python recipe 576522 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/dll/">dll</a>, <a href="/recipes/tags/exe/">exe</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/version/">version</a>, <a href="/recipes/tags/windows/">windows</a>). Revision 7. </p> <p>Returns the pathnames of the file (.exe or .dll) which would be loaded/executed in the current environment. It uses some dirs from configuration (SystemDir, WindowsDir) and dirs from PATH.</p> <p>To obtain version info it uses code from: <a href="http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/tip/win32/Demos/getfilever.py" rel="nofollow">http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/tip/win32/Demos/getfilever.py</a></p> <p>Example of usage:</p> <pre class="prettyprint"><code> c:\tools\pyscripts\scripts&gt;which_dll.py libpq.dll 2008-06-09 02:58:26 167936 [b] c:\postgresql\8.3\bin\libpq.dll ver:8.3.3.8160 2008-03-17 01:47:50 167936 [b] c:\tools\libpq.dll ver:8.3.1.8075 2008-03-17 01:47:50 167936 [b] g:\public\libpq.dll ver:8.3.1.8075 trying to load "libpq.dll" ... c:\postgresql\8.3\bin\libpq.dll loaded </code></pre> JPG files redater by EXIF data (Python) 2014-12-11T10:07:39-08:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/550811-jpg-files-redater-by-exif-data/ <p style="color: grey"> Python recipe 550811 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/exif/">exif</a>, <a href="/recipes/tags/e_uae/">e_uae</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/jpeg/">jpeg</a>, <a href="/recipes/tags/jpg/">jpg</a>, <a href="/recipes/tags/pil/">pil</a>). Revision 6. </p> <p>Iterates through a directory, reading the EXIF data from each jpg/jpeg file. Parses the date/time from EXIF data and:</p> <ol> <li>if it differs from file modification date/time then changes file date/time</li> <li>moves file to <code>YYYY/YYYY_MM_DD</code> directory</li> </ol>