Popular recipes tagged "meta:loc=35"http://code.activestate.com/recipes/tags/meta:loc=35/2015-07-29T18:24:23-07:00ActiveState Code Recipesstupid trick: mimicking the python cgi library's FieldStorage() object for command line debuging (Python)
2015-06-18T20:46:32-07:00Jon Crumphttp://code.activestate.com/recipes/users/4174917/http://code.activestate.com/recipes/579069-stupid-trick-mimicking-the-python-cgi-librarys-fie/
<p style="color: grey">
Python
recipe 579069
by <a href="/recipes/users/4174917/">Jon Crump</a>
(<a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/urls/">urls</a>).
Revision 6.
</p>
<p>create dictionary-like object that mimics the cgi.FieldStorage() object having both a <code>.value</code> property, and a <code>.getvalue()</code> method</p>
Python script to find linux distros details from distrowatch (Python)
2015-07-29T18:24:23-07:00Emil george jameshttp://code.activestate.com/recipes/users/4191910/http://code.activestate.com/recipes/579038-python-script-to-find-linux-distros-details-from-d/
<p style="color: grey">
Python
recipe 579038
by <a href="/recipes/users/4191910/">Emil george james</a>
(<a href="/recipes/tags/beautifulsoup/">beautifulsoup</a>, <a href="/recipes/tags/internet/">internet</a>, <a href="/recipes/tags/module/">module</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/url/">url</a>, <a href="/recipes/tags/web/">web</a>).
</p>
<p>this script is a simlpe python script to find linux distros details from distrowatch using beautifulsoup,urllib2 modules.The script finds distros distribution details from <a href="http://distrowatch.com" rel="nofollow">distrowatch.com</a> when the distribution name is called as argument.</p>
Simple Linear Regression with Pure Python (Python)
2014-07-31T15:55:15-07:00Chaobin Tang (唐超斌)http://code.activestate.com/recipes/users/4174076/http://code.activestate.com/recipes/578914-simple-linear-regression-with-pure-python/
<p style="color: grey">
Python
recipe 578914
by <a href="/recipes/users/4174076/">Chaobin Tang (唐超斌)</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/machine_learning/">machine_learning</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/regression/">regression</a>).
</p>
<p>Linear regression is a very useful and simple to understand way for predicting values, given a set of training data. The outcome of the regression is a best fitting line function, which, by definition, is the line that minimizes the sum of the squared errors (When plotted on a 2 dimensional coordination system, the errors are the distance between the actual Y' and predicted Y' on the line.) In machine learning, this line equation Y' = b*x + A is solved using Gradient Descent to gradually approach to it. Also, there is a statistical approach that directly solves this line equation without using an iterative algorithm.</p>
<p>This recipe is a pure Python implementation of this statistical algorithm. It has no dependencies.</p>
<p>If you have pandas and numpy, you can test its result by uncommenting the assert lines.</p>
Calculating Swatch Internet Time (or Beats) (Python)
2013-02-25T11:58:05-08:00James Millshttp://code.activestate.com/recipes/users/4167757/http://code.activestate.com/recipes/578473-calculating-swatch-internet-time-or-beats/
<p style="color: grey">
Python
recipe 578473
by <a href="/recipes/users/4167757/">James Mills</a>
(<a href="/recipes/tags/beats/">beats</a>, <a href="/recipes/tags/internet_time/">internet_time</a>, <a href="/recipes/tags/swatch/">swatch</a>).
</p>
<p>Simple function calculating Swatch Internet Time (or no. of beats).</p>
Another way execute PowerShell script via batch file (Batch)
2013-10-10T16:24:14-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578496-another-way-execute-powershell-script-via-batch-fi/
<p style="color: grey">
Batch
recipe 578496
by <a href="/recipes/users/4184115/">greg zakharov</a>
.
Revision 2.
</p>
<p>Early I wrote about it, and now I want to go back and show you another way how to do it. This way more easly because all you need it just put your PowerShell script in the end of batch file.</p>
A Crude Baby Alarm For Standard Text Mode Python And Linux. (Python)
2012-08-02T18:05:29-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578232-a-crude-baby-alarm-for-standard-text-mode-python-a/
<p style="color: grey">
Python
recipe 578232
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/alarm/">alarm</a>, <a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/baby_alarm/">baby_alarm</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/sound/">sound</a>).
</p>
<p>This is a simple audio monitor that records about 1/2 second of sound then immediately plays it back in a continuous loop.</p>
<p>If you are testing with a laptop's, (etc), internal microphone be aware that acoustic feedback might occur...</p>
<p>This could be a use for your now aging netbook... ;o)</p>
<p>Bazza, G0LCU...</p>
A Python decorator that re-executes the function on condition (Python)
2012-07-24T09:51:48-07:00Chaobin Tang (唐超斌)http://code.activestate.com/recipes/users/4174076/http://code.activestate.com/recipes/578222-a-python-decorator-that-re-executes-the-function-o/
<p style="color: grey">
Python
recipe 578222
by <a href="/recipes/users/4174076/">Chaobin Tang (唐超斌)</a>
(<a href="/recipes/tags/closure/">closure</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/retry/">retry</a>).
Revision 3.
</p>
<p>Sometimes we want a function to be able to be retried automatically, such as a function that does networking trying to write/read data through a pre-established connection. Instead of writing try/except everywhere, a decorator would save much code and provide a single copy of code to do all the work.</p>
Python interpreter auto-completion and history (Python)
2014-01-09T10:04:47-08:00Giampaolo Rodolàhttp://code.activestate.com/recipes/users/4178764/http://code.activestate.com/recipes/578098-python-interpreter-auto-completion-and-history/
<p style="color: grey">
Python
recipe 578098
by <a href="/recipes/users/4178764/">Giampaolo Rodolà</a>
(<a href="/recipes/tags/bashrc/">bashrc</a>, <a href="/recipes/tags/completion/">completion</a>, <a href="/recipes/tags/history/">history</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/pythonstartup/">pythonstartup</a>).
Revision 5.
</p>
<p>Useful in case you don't want to install iPython.</p>
Easy ansi color plus more. (Ruby)
2014-04-16T15:36:04-07:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/578018-easy-ansi-color-plus-more/
<p style="color: grey">
Ruby
recipe 578018
by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a>
(<a href="/recipes/tags/ansi/">ansi</a>, <a href="/recipes/tags/clear/">clear</a>, <a href="/recipes/tags/console/">console</a>, <a href="/recipes/tags/cursor/">cursor</a>, <a href="/recipes/tags/formatting/">formatting</a>, <a href="/recipes/tags/movement/">movement</a>, <a href="/recipes/tags/output/">output</a>, <a href="/recipes/tags/ruby/">ruby</a>, <a href="/recipes/tags/screen/">screen</a>, <a href="/recipes/tags/string/">string</a>, <a href="/recipes/tags/underline/">underline</a>).
</p>
<p>This quick class extends the base String class to add the ability to chain escape codes onto your output. For instance: puts 'String'.bold.underline.blink.red for something truly hideous. Aside from the colors (all are supported, but I haven't put in support for background colors as of the time of this post), cursor placement (ymmv based on the term type), screen clearing, bold, underline, blink reverse, conceal are all handled as well.</p>
Find function in a ram.map file (Python)
2011-12-23T21:58:01-08:00Sharonhttp://code.activestate.com/recipes/users/4180356/http://code.activestate.com/recipes/577995-find-function-in-a-rammap-file/
<p style="color: grey">
Python
recipe 577995
by <a href="/recipes/users/4180356/">Sharon</a>
(<a href="/recipes/tags/map/">map</a>, <a href="/recipes/tags/ram/">ram</a>, <a href="/recipes/tags/vxworks/">vxworks</a>).
</p>
<p>The findCloseAddress() function receives an input parameter ram.map file "ramMapFile", and search inside it for the function with the closest address to the input parameter "reqAddress".</p>
Simple Abstract "Constants" to Use When @abstractproperty is Overkill or Misleading (Python)
2011-08-12T23:35:45-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577761-simple-abstract-constants-to-use-when-abstractprop/
<p style="color: grey">
Python
recipe 577761
by <a href="/recipes/users/4177816/">Eric Snow</a>
(<a href="/recipes/tags/attributes/">attributes</a>, <a href="/recipes/tags/classes/">classes</a>).
</p>
<p>Use these instead of abstract properties when you don't plan on the abstract attribute being implemented with a property. And you can still give your attribute a docstring!</p>
Mixins by Inheritance vs. by Decorator...Let's Try Decorators (Python)
2011-08-12T15:29:21-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577824-mixins-by-inheritance-vs-by-decoratorlets-try-deco/
<p style="color: grey">
Python
recipe 577824
by <a href="/recipes/users/4177816/">Eric Snow</a>
(<a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/mixins/">mixins</a>).
</p>
<p>Using mixin classes via inheritance has its pros and cons. Here is an easy alternative via a decorator. As a bonus, you can mix in attributes from any object, not just classes.</p>
Convert PyQt properties to Python properties (Python)
2011-01-09T02:02:30-08:00Miguel Turnerhttp://code.activestate.com/recipes/users/4176460/http://code.activestate.com/recipes/577539-convert-pyqt-properties-to-python-properties/
<p style="color: grey">
Python
recipe 577539
by <a href="/recipes/users/4176460/">Miguel Turner</a>
(<a href="/recipes/tags/property/">property</a>, <a href="/recipes/tags/pyqt/">pyqt</a>, <a href="/recipes/tags/pyside/">pyside</a>, <a href="/recipes/tags/python/">python</a>).
Revision 2.
</p>
<p>This recipe will find all attributes created as meta-object properties in Qt and will create a Python property of the same name for each of them. This is a quick way of providing some of the functionality suggested by <a href="http://www.pyside.org/docs/pseps/psep-0102.html">PSEP 102</a>, which I sincerely hope will be accepted, as it will make PySide considerably more pythonic.</p>
PyDON - An alternative to XML (Python)
2010-12-24T08:28:15-08:00Lost Protocolhttp://code.activestate.com/recipes/users/4176279/http://code.activestate.com/recipes/577508-pydon-an-alternative-to-xml/
<p style="color: grey">
Python
recipe 577508
by <a href="/recipes/users/4176279/">Lost Protocol</a>
(<a href="/recipes/tags/configuration/">configuration</a>, <a href="/recipes/tags/json/">json</a>, <a href="/recipes/tags/xml/">xml</a>, <a href="/recipes/tags/xmlrpc/">xmlrpc</a>).
Revision 2.
</p>
<p>Many use XML to store configuration data, some use INI files others use Windows Registries and some like JSON. But given the fact that Python is such a powerful language, its easy to create/use such representations. PyDON stands for Python Dictionary Object Notation. It LOOKS similar to JSON but doesn't require you to create any parsers. Plus it can contain Python code which is even better :-).</p>
<p>More on this here > <a href="http://lostp.99k.org/files/PyDON.pdf" rel="nofollow">http://lostp.99k.org/files/PyDON.pdf</a></p>
Basic Linux Menu (Bash)
2010-10-23T05:40:18-07:00Jonathan Fenechhttp://code.activestate.com/recipes/users/4169413/http://code.activestate.com/recipes/577437-basic-linux-menu/
<p style="color: grey">
Bash
recipe 577437
by <a href="/recipes/users/4169413/">Jonathan Fenech</a>
(<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/basic/">basic</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/menu/">menu</a>).
</p>
<p>A basic Linux menu which can do the following: </p>
<ul>
<li>Display Files and Directory's</li>
<li>Remove Files Displayed</li>
<li>Copy Files Displayed</li>
<li>Make Directory</li>
</ul>
Komodo JS Macro - delete marked lines (JavaScript)
2010-08-30T17:32:24-07:00Eric Promislowhttp://code.activestate.com/recipes/users/4166930/http://code.activestate.com/recipes/577378-komodo-js-macro-delete-marked-lines/
<p style="color: grey">
JavaScript
recipe 577378
by <a href="/recipes/users/4166930/">Eric Promislow</a>
(<a href="/recipes/tags/bookmarks/">bookmarks</a>, <a href="/recipes/tags/editor/">editor</a>, <a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/komodo/">komodo</a>).
</p>
<p>You can set bookmarks in Komodo, for ease ni revisiting certain lines. This recipe lets you
delete all the marked lines in the current buffer. This code is undoable, but the markers
are gone for good. They aren't restored by Scintilla, and having Komodo restore them
would be a pain.</p>
typesafe records (Python)
2010-07-10T01:43:38-07:00andrew johnsonhttp://code.activestate.com/recipes/users/4174071/http://code.activestate.com/recipes/577249-typesafe-records/
<p style="color: grey">
Python
recipe 577249
by <a href="/recipes/users/4174071/">andrew johnson</a>
(<a href="/recipes/tags/namedtuple/">namedtuple</a>, <a href="/recipes/tags/record/">record</a>, <a href="/recipes/tags/type/">type</a>, <a href="/recipes/tags/typesafe/">typesafe</a>).
Revision 4.
</p>
<p>A typesafe wrapper for namedtuple.</p>
Simulate number of flushes in a poker hand (Python)
2010-04-08T05:24:12-07:00Dudley G R Gentleshttp://code.activestate.com/recipes/users/4173603/http://code.activestate.com/recipes/577184-simulate-number-of-flushes-in-a-poker-hand/
<p style="color: grey">
Python
recipe 577184
by <a href="/recipes/users/4173603/">Dudley G R Gentles</a>
(<a href="/recipes/tags/cards/">cards</a>, <a href="/recipes/tags/flush/">flush</a>, <a href="/recipes/tags/poker/">poker</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/time/">time</a>).
</p>
<p>This program calculates the number of flushes in a number of deals of a poker hand. You can tell it to deal say 10,000 hands and see how many were flushes. This is basically my first Python program. </p>
Regular Polygon Fractals using Iteration method. (Python)
2010-03-20T14:47:54-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577131-regular-polygon-fractals-using-iteration-method/
<p style="color: grey">
Python
recipe 577131
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/math/">math</a>).
</p>
<p>It draws 6 regular polygon fractals.</p>
Brownian Motion of Stock (Python)
2009-05-19T05:16:29-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/576760-brownian-motion-of-stock/
<p style="color: grey">
Python
recipe 576760
by <a href="/recipes/users/4166679/">alexander baker</a>
(<a href="/recipes/tags/finance/">finance</a>).
</p>
<p>Brownian Motion of a Stock</p>