Popular recipes tagged "meta:forkof"http://code.activestate.com/recipes/tags/meta:forkof/2016-09-18T20:39:20-07:00ActiveState Code RecipesDBF reader and writer -- selective fields and nullreplace (Python)
2016-09-18T20:39:20-07:00Tomas Nordinhttp://code.activestate.com/recipes/users/4189558/http://code.activestate.com/recipes/580696-dbf-reader-and-writer-selective-fields-and-nullrep/
<p style="color: grey">
Python
recipe 580696
by <a href="/recipes/users/4189558/">Tomas Nordin</a>
(<a href="/recipes/tags/database/">database</a>).
</p>
<p>This fork assumes a desire for limited selection of field names. With
huge files this might be necessary on some machines.</p>
<p>Also, assuming that the meaning of null in a dbf file means zero might
be a mistake, so the fork adds an argument nullreplace as way to
choose what to replace null with. Null is sometimes used to mean
missing value. This change is decoupled from the selective names
feature.</p>
Convert Spelled out Integers (e.g. three thousand two hundred fifty) into Integers (e.g. 3250) and Vice Versa (Python)
2016-07-14T21:08:01-07:00Chathura Gunasekarahttp://code.activestate.com/recipes/users/4194443/http://code.activestate.com/recipes/580689-convert-spelled-out-integers-eg-three-thousand-two/
<p style="color: grey">
Python
recipe 580689
by <a href="/recipes/users/4194443/">Chathura Gunasekara</a>
(<a href="/recipes/tags/integers/">integers</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/strings/">strings</a>).
</p>
<p>-Provides an isNumber function that can test if a floating point number is a number
-str_to_int can convert a spelled out integer (e.g. 'one hundred thirty five') to its numeric form (e.g. 135)
-int_to_str can convert an integer into its spelled out form.</p>
Hopfield Artificial Neural Network (C++)
2016-07-03T21:58:49-07:00Jay ballerhttp://code.activestate.com/recipes/users/4194368/http://code.activestate.com/recipes/580688-hopfield-artificial-neural-network/
<p style="color: grey">
C++
recipe 580688
by <a href="/recipes/users/4194368/">Jay baller</a>
(<a href="/recipes/tags/ai/">ai</a>, <a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/artificial_intelligence/">artificial_intelligence</a>, <a href="/recipes/tags/neural_network/">neural_network</a>).
</p>
<p>(Discrete (Binary)) Hopfield Artificial Neural Network (ANN).</p>
<p>For more info see:</p>
<p><a href="http://en.wikipedia.org/wiki/Hopfield_net" rel="nofollow">http://en.wikipedia.org/wiki/Hopfield_net</a></p>
<p><a href="http://www.scholarpedia.org/article/Hopfield_network" rel="nofollow">http://www.scholarpedia.org/article/Hopfield_network</a></p>
Persistent Queue (Python)
2015-11-12T06:45:12-08:00zhangkaizhaohttp://code.activestate.com/recipes/users/4189594/http://code.activestate.com/recipes/579124-persistent-queue/
<p style="color: grey">
Python
recipe 579124
by <a href="/recipes/users/4189594/">zhangkaizhao</a>
(<a href="/recipes/tags/sysadmin/">sysadmin</a>).
</p>
<p>A class for persistent queues.</p>
How to use super() effectively -- Python 3.2 version (Python)
2015-12-01T16:23:09-08:00Lance E Sloanhttp://code.activestate.com/recipes/users/4188012/http://code.activestate.com/recipes/579130-how-to-use-super-effectively-python-32-version/
<p style="color: grey">
Python
recipe 579130
by <a href="/recipes/users/4188012/">Lance E Sloan</a>
(<a href="/recipes/tags/cooperative/">cooperative</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/multiple/">multiple</a>, <a href="/recipes/tags/next_in_mro/">next_in_mro</a>, <a href="/recipes/tags/super/">super</a>).
</p>
<p>Python's super() provides a unique and amazing capability. It allows subclasses to be written to reorder a chain method calls. The recipe demonstrates all of the tradecraft needed to get super() to do your bidding.</p>
Print Hook (Python)
2015-12-04T02:51:42-08:00kauliehttp://code.activestate.com/recipes/users/4193226/http://code.activestate.com/recipes/579132-print-hook/
<p style="color: grey">
Python
recipe 579132
by <a href="/recipes/users/4193226/">kaulie</a>
(<a href="/recipes/tags/debugging/">debugging</a>).
</p>
<p>Hook on stdout and stderr so that we can handle
printing of text,error differently
e.g in GUI base application divert text to a log window.</p>
How to use super() effectively -- Python 2.7 version (Python)
2015-12-01T16:20:26-08:00Lance E Sloanhttp://code.activestate.com/recipes/users/4188012/http://code.activestate.com/recipes/579129-how-to-use-super-effectively-python-27-version/
<p style="color: grey">
Python
recipe 579129
by <a href="/recipes/users/4188012/">Lance E Sloan</a>
(<a href="/recipes/tags/cooperative/">cooperative</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/multiple/">multiple</a>, <a href="/recipes/tags/next_in_mro/">next_in_mro</a>, <a href="/recipes/tags/super/">super</a>).
</p>
<p>Python's super() provides a unique and amazing capability. It allows subclasses to be written to reorder a chain method calls. The recipe demonstrates all of the tradecraft needed to get super() to do your bidding.</p>
Python Gpa and Cgpa Calculator for Anna university : A forked python recepie (Python)
2015-07-31T02:37:19-07:00Emil george jameshttp://code.activestate.com/recipes/users/4191910/http://code.activestate.com/recipes/579089-python-gpa-and-cgpa-calculator-for-anna-university/
<p style="color: grey">
Python
recipe 579089
by <a href="/recipes/users/4191910/">Emil george james</a>
(<a href="/recipes/tags/calculator/">calculator</a>, <a href="/recipes/tags/cgpa/">cgpa</a>, <a href="/recipes/tags/gpa/">gpa</a>, <a href="/recipes/tags/python/">python</a>).
Revision 2.
</p>
<p>Actually this python script is a forked one from activestate code by abhijeeth vaidya.A slightly edited version of the script to calculate Gpa and Cgpa for Anna university Students.</p>
<p>Gpa and Cgpa Calculator</p>
<p>Gpa is Grade point average, which is use to determine the student academic pointer based on the value of the grade he/she acquired in single semester, where as cgpa is cumlative grade point average is to calculate the total credits and total grade acquired in his/her entire academics. Here i have determined to use grade scale of two values 5.0 and 10.0, many other academics may have different grading system.For a different grades and their grade values, You can change the value in method called getGradeData.For any bug report </p>
getch()-like unbuffered character reading from stdin on both Windows and Unix (Python)
2015-08-19T04:45:51-07:00jwhite88http://code.activestate.com/recipes/users/4192711/http://code.activestate.com/recipes/579095-getch-like-unbuffered-character-reading-from-stdin/
<p style="color: grey">
Python
recipe 579095
by <a href="/recipes/users/4192711/">jwhite88</a>
(<a href="/recipes/tags/sysadmin/">sysadmin</a>).
</p>
<p>A small utility class to read single characters from standard input, on both Windows and UNIX systems. It provides a getch() function-like instance.</p>
<p>This extends the original script by adding a timeout necessary for another project.</p>
edge-coloring of a bipartite graph (Python)
2015-07-30T13:40:41-07:00Praveenhttp://code.activestate.com/recipes/users/4192603/http://code.activestate.com/recipes/579088-edge-coloring-of-a-bipartite-graph/
<p style="color: grey">
Python
recipe 579088
by <a href="/recipes/users/4192603/">Praveen</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>Konig's theorem tells us that every bipartite graph with maximum vertex-degree d can be edge-colored with just d colors.
This recipe relies on a previous recipe by D.Eppstein (123641) : "Hopcroft-Karp bipartite matching".</p>
OrderedSet (Python)
2015-06-25T17:33:13-07:00Sanderhttp://code.activestate.com/recipes/users/4192426/http://code.activestate.com/recipes/579071-orderedset/
<p style="color: grey">
Python
recipe 579071
by <a href="/recipes/users/4192426/">Sander</a>
(<a href="/recipes/tags/ordered/">ordered</a>, <a href="/recipes/tags/set/">set</a>).
</p>
<p>Set that remembers original insertion order.</p>
Python Short URL Generator (Python)
2014-11-09T11:19:07-08:00Des Wagnerhttp://code.activestate.com/recipes/users/4191097/http://code.activestate.com/recipes/578961-python-short-url-generator/
<p style="color: grey">
Python
recipe 578961
by <a href="/recipes/users/4191097/">Des Wagner</a>
(<a href="/recipes/tags/deterministic/">deterministic</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/short/">short</a>, <a href="/recipes/tags/tiny/">tiny</a>, <a href="/recipes/tags/unique/">unique</a>, <a href="/recipes/tags/url/">url</a>).
</p>
<p>Python implementation for generating Tiny URL- and bit.ly-like URLs.</p>
Engineering notation. (Python)
2015-04-15T16:17:12-07:00Paul Sargenthttp://code.activestate.com/recipes/users/4192033/http://code.activestate.com/recipes/579046-engineering-notation/
<p style="color: grey">
Python
recipe 579046
by <a href="/recipes/users/4192033/">Paul Sargent</a>
(<a href="/recipes/tags/engineering/">engineering</a>, <a href="/recipes/tags/ipython/">ipython</a>).
</p>
<p>eng(x) returns a string representing x using the "engineering notation"</p>
Python AST to XML (Python)
2015-02-05T20:18:08-08:00Robert Stewarthttp://code.activestate.com/recipes/users/4191612/http://code.activestate.com/recipes/579019-python-ast-to-xml/
<p style="color: grey">
Python
recipe 579019
by <a href="/recipes/users/4191612/">Robert Stewart</a>
(<a href="/recipes/tags/ast/">ast</a>, <a href="/recipes/tags/xml/">xml</a>).
</p>
<p>Convert Python ASTs to XML files for reading in other languages.</p>
Check for package updates on PyPI (works best in pip+virtualenv) (Python)
2015-03-04T11:01:44-08:00migonzalvarhttp://code.activestate.com/recipes/users/4191750/http://code.activestate.com/recipes/579030-check-for-package-updates-on-pypi-works-best-in-pi/
<p style="color: grey">
Python
recipe 579030
by <a href="/recipes/users/4191750/">migonzalvar</a>
(<a href="/recipes/tags/pip/">pip</a>, <a href="/recipes/tags/pypi/">pypi</a>, <a href="/recipes/tags/virtualenv/">virtualenv</a>).
</p>
<p>Pip has an option to upgrade a package (_pip install -U_), however it always downloads sources even if there is already a newest version installed. If you want to check updates for all installed packages then some scripting is required.</p>
<p>This script checks if there is a newer version on PyPI for every installed package. It only prints information about available version and doesn't do any updates. Example output:</p>
<pre class="prettyprint"><code>distribute 0.6.15 0.6.16 available
Baker 1.1 up to date
Django 1.3 up to date
ipython 0.10.2 up to date
gunicorn 0.12.1 0.12.2 available
pyprof2calltree 1.1.0 up to date
profilestats 1.0.2 up to date
mercurial 1.8.3 up to date
</code></pre>
Python SQLSMO - Threading Example (Python)
2015-02-10T02:01:42-08:00Jorge Besadahttp://code.activestate.com/recipes/users/100038/http://code.activestate.com/recipes/579023-python-sqlsmo-threading-example/
<p style="color: grey">
Python
recipe 579023
by <a href="/recipes/users/100038/">Jorge Besada</a>
(<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/smo/">smo</a>, <a href="/recipes/tags/sql/">sql</a>, <a href="/recipes/tags/sqlsmo/">sqlsmo</a>, <a href="/recipes/tags/threading/">threading</a>).
</p>
<p>This is an example of the use of the SQLSMO module. Using a csv file DBLIST_ACTIONS.csv with list of databases where you can launch multiple different database operations in parallel</p>
<p>Some lines of the configuration file DBLIST_ACTIONS.csv used shown below:
SERVERNAME,DBNAME1,SOURCESERVER,DATAFOLDER,LOGFOLDER,DBNAME2,ACTIONS,ENABLED
(local)\sql2014,AdventureWorks2012,C:\SQL2014\BACKUPS,C:\SQL2014\DATA,C:\SQL2014\LOG,AdventureWorks_COPY1,RESTOREDBS1.CFG,Y
(local)\sql2014,AdventureWorks2012,C:\SQL2014\BACKUPS,C:\SQL2014\DATA,C:\SQL2014\LOG,AdventureWorks_COPY2,RESTOREDBS1.CFG,Y
(local)\sql2014,AdventureWorks2012,C:\SQL2014\BACKUPS,C:\SQL2014\DATA,C:\SQL2014\LOG,AdventureWorks_COPY3,RESTOREDBS1.CFG,Y
(local)\sql2014,AdventureWorks2012,C:\SQL2014\BACKUPS,C:\SQL2014\DATA,C:\SQL2014\LOG,AdventureWorks_COPY4,RESTOREDBS1.CFG,</p>
<p>Where:
SERVERNAME: server where the database to act upon resides</p>
<p>DBNAME1: source database</p>
<p>DBNAME2: destination database (may be different from source when we restore a copy with a different name)</p>
<p>SOURCESERVER: this is the network (or local) folder where backups are placed</p>
<p>DATAFOLDER: folder for data files</p>
<p>LOGFOLDER: folder for log files</p>
<p>ACTIONS: this is the name of the configuration file (.CFG) with the list of actions</p>
<p>ENABLED: a Y value here will mean we want to process the line</p>
<p>For each line (database) you specify a configuration file (in this case RESTOREDBS1.CFG), see sample below:
(one line for each, no blank lines)</p>
<p>RESTORE DATABASE</p>
<p>SET DBOWNER: sa</p>
<p>SYNC LOGINS</p>
<p>SET SIMPLE MODE</p>
<p>SHRINK LOG</p>
<p>The program will process each line in the source CSV file and for each one it will perform the set of operations described in the configuration file. This system is being used in my workplace with different configuration files for different databases (there are configuration files for restores, specific restores with more actions, backups, etc, not included here for brevity).</p>
<p>Every time you do a database task you just add a line in the DBLIST_ACTIONS.CSV and create (if needed) a configuration file). If you are going to actually use it include a "Y" in the ENABLED column
Note: every line action in the configuration file must have been implemented in the function ActionParsing as one the entries in the big if statement.</p>
<p>Special features:
You can specify at the start of the program if you want to really execute or not. You may want to do first a trial run setting NOEXECUTE_OPTION = 1 (instead of the default of 0). In this case the program will run and create the SQL script of the operations, not executing them.
Note: it has been implemented in the restores so far, will add it to the other options later.</p>
<p>Threading: by default it will run as many threads as lines in the DBLIST_ACTIONS.CSV file. But you can change this option by setting a value to THREAD_POOL different than 0. </p>
Python ADO Database Interface for MS SQL Server - Python 3 version 1.0 (Python)
2014-08-27T16:04:04-07:00Jorge Besadahttp://code.activestate.com/recipes/users/100038/http://code.activestate.com/recipes/578913-python-ado-database-interface-for-ms-sql-server-py/
<p style="color: grey">
Python
recipe 578913
by <a href="/recipes/users/100038/">Jorge Besada</a>
(<a href="/recipes/tags/ado/">ado</a>, <a href="/recipes/tags/database/">database</a>).
Revision 3.
</p>
<p>This DBI implements the Cursor and Connection objects. You can create connections, cursors, do fetchone, fetchall. It uses ADO. Will add more features later </p>
Bader-Offer Method (Hagenbach-Bischoff) (JavaScript)
2015-01-14T11:14:06-08:00elazarhttp://code.activestate.com/recipes/users/4187847/http://code.activestate.com/recipes/579002-bader-offer-method-hagenbach-bischoff/
<p style="color: grey">
JavaScript
recipe 579002
by <a href="/recipes/users/4187847/">elazar</a>
(<a href="/recipes/tags/calculation/">calculation</a>).
</p>
<p>A recipe for calculating the seats allocated to each party in the Knesset.</p>
<p>More information:</p>
<ul>
<li><a href="http://www.knesset.gov.il/lexicon/eng/seats_eng.htm" rel="nofollow">http://www.knesset.gov.il/lexicon/eng/seats_eng.htm</a></li>
<li><a href="https://en.wikipedia.org/wiki/Hagenbach-Bischoff_system" rel="nofollow">https://en.wikipedia.org/wiki/Hagenbach-Bischoff_system</a></li>
<li>(Hebrew) <a href="http://bechirot.gov.il/election/about/Pages/CalculatingSeatsMethod.aspx" rel="nofollow">http://bechirot.gov.il/election/about/Pages/CalculatingSeatsMethod.aspx</a></li>
<li>(Hebrew) <a href="http://main.knesset.gov.il/About/Lexicon/Pages/seats.aspx" rel="nofollow">http://main.knesset.gov.il/About/Lexicon/Pages/seats.aspx</a></li>
</ul>
Creating a single instance application (Python)
2014-11-20T11:59:46-08:00Matteo Bertinihttp://code.activestate.com/recipes/users/4191156/http://code.activestate.com/recipes/578966-creating-a-single-instance-application/
<p style="color: grey">
Python
recipe 578966
by <a href="/recipes/users/4191156/">Matteo Bertini</a>
(<a href="/recipes/tags/threads/">threads</a>).
</p>
<p>Sometimes it is necessary to ensure that only one instance of application is running. This quite simple solution uses mutex to achieve this, and will run only on Windows platform.</p>
Wait for network service to appear (Python)
2014-11-06T07:29:12-08:00Mohammad Taha Jahangirhttp://code.activestate.com/recipes/users/4188847/http://code.activestate.com/recipes/578955-wait-for-network-service-to-appear/
<p style="color: grey">
Python
recipe 578955
by <a href="/recipes/users/4188847/">Mohammad Taha Jahangir</a>
(<a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/socket/">socket</a>).
</p>
<p>This script allows you to wait until specified port is opened on remote server. This can be useful in automation jobs - restarting server, wake on lan etc. It can also be used for monitoring distant service/site.</p>
<p>The main problem that this script solves is that you need to handle two different timeouts when opening probing socket, and it is not described in python documentation. See <a href="http://bugs.python.org/issue5293" rel="nofollow">http://bugs.python.org/issue5293</a> for more information.</p>