Popular recipes tagged "meta:loc=7"http://code.activestate.com/recipes/tags/meta:loc=7/2014-09-19T08:03:02-07:00ActiveState Code RecipesGreatest common divisor (Python)
2014-09-19T08:03:02-07:00juanhttp://code.activestate.com/recipes/users/4190606/http://code.activestate.com/recipes/578937-greatest-common-divisor/
<p style="color: grey">
Python
recipe 578937
by <a href="/recipes/users/4190606/">juan</a>
.
</p>
<p>Calculate the Greatest common divisor from two numbers</p>
Probably the fastest memoization decorator in the world (Python)
2012-08-02T07:27:12-07:00Oren Tiroshhttp://code.activestate.com/recipes/users/2033964/http://code.activestate.com/recipes/578231-probably-the-fastest-memoization-decorator-in-the-/
<p style="color: grey">
Python
recipe 578231
by <a href="/recipes/users/2033964/">Oren Tirosh</a>
(<a href="/recipes/tags/cache/">cache</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/memo/">memo</a>, <a href="/recipes/tags/memoization/">memoization</a>).
</p>
<p>With apologies to a certain European brand of beer, this is probably the fastest memoization decorator in the world. Implemented using the __missing__ method in a dict subclass. </p>
Caller and Callee (Python)
2013-03-07T08:37:32-08:00Deepakhttp://code.activestate.com/recipes/users/4183429/http://code.activestate.com/recipes/578483-caller-and-callee/
<p style="color: grey">
Python
recipe 578483
by <a href="/recipes/users/4183429/">Deepak</a>
(<a href="/recipes/tags/callee/">callee</a>, <a href="/recipes/tags/caller/">caller</a>, <a href="/recipes/tags/debugging/">debugging</a>).
</p>
<p>A recipe to find out which function is the caller of the current function. </p>
<p>The <code>caller</code> function can be helpful for debugging — if there is no real debugger available. In terms of software engineering (loose coupling etc.) this should not be used in production code though.</p>
Print letters with different case (Ruby)
2012-11-19T08:38:31-08:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578336-print-letters-with-different-case/
<p style="color: grey">
Ruby
recipe 578336
by <a href="/recipes/users/4184115/">greg zakharov</a>
(<a href="/recipes/tags/ironruby/">ironruby</a>, <a href="/recipes/tags/letters/">letters</a>).
</p>
<p>It seems just for fun but sometimes it very useful (for example, writing a script to generate random password).</p>
Singleton? We don't need no stinkin' singleton: the Borg design pattern (Python)
2011-09-18T18:47:59-07:00Anler Hernández Peralhttp://code.activestate.com/recipes/users/4176323/http://code.activestate.com/recipes/577870-singleton-we-dont-need-no-stinkin-singleton-the-bo/
<p style="color: grey">
Python
recipe 577870
by <a href="/recipes/users/4176323/">Anler Hernández Peral</a>
(<a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/pattern/">pattern</a>).
</p>
<p>The Singleton design pattern (DP) has a catchy name, but the wrong focus -- on identity rather than on state. The Borg design pattern has all instances share state instead, and Python makes it, literally, a snap.</p>
Base Expansion/Conversion Algorithm Python (Python)
2011-11-21T19:58:14-08:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/577939-base-expansionconversion-algorithm-python/
<p style="color: grey">
Python
recipe 577939
by <a href="/recipes/users/4179768/">Alexander James Wallar</a>
(<a href="/recipes/tags/base/">base</a>, <a href="/recipes/tags/base16/">base16</a>, <a href="/recipes/tags/base2/">base2</a>, <a href="/recipes/tags/base_conversion/">base_conversion</a>, <a href="/recipes/tags/base_expansion/">base_expansion</a>, <a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/lists/">lists</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/number_theory/">number_theory</a>, <a href="/recipes/tags/python/">python</a>).
Revision 3.
</p>
<p>This algorithm converts a base c number into a base b number. Parameters c and b are arbitrary are not constrained by any bounds. The input n is a list and the output is a list.</p>
slugify: make a string usable in a URL or filename (JavaScript)
2011-07-12T17:46:49-07:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/577787-slugify-make-a-string-usable-in-a-url-or-filename/
<p style="color: grey">
JavaScript
recipe 577787
by <a href="/recipes/users/4173505/">Trent Mick</a>
(<a href="/recipes/tags/filename/">filename</a>, <a href="/recipes/tags/nodejs/">nodejs</a>, <a href="/recipes/tags/slug/">slug</a>, <a href="/recipes/tags/slugify/">slugify</a>, <a href="/recipes/tags/url/">url</a>).
Revision 2.
</p>
<p>"Slugify" a string so it has only alphanumeric and hyphen characters. Useful for URLs and filenames. This is a JavaScript (node.js too) version of <a href="http://code.activestate.com/recipes/577257/">Recipe 577257</a>.</p>
<p>Note: It is missing the guarantee that only ascii characters are passed through. I don't know an NFKD equivalent in JavaScript-land.</p>
SleepSort (Timer version) (Python)
2011-06-18T05:37:06-07:00wong2http://code.activestate.com/recipes/users/4178345/http://code.activestate.com/recipes/577762-sleepsort-timer-version/
<p style="color: grey">
Python
recipe 577762
by <a href="/recipes/users/4178345/">wong2</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/interest/">interest</a>, <a href="/recipes/tags/sort/">sort</a>).
</p>
<p>Python version sleep sort by using threading.Timer</p>
YAML include support (Python)
2011-03-17T22:18:30-07:00Michael Grünewaldhttp://code.activestate.com/recipes/users/4172244/http://code.activestate.com/recipes/577613-yaml-include-support/
<p style="color: grey">
Python
recipe 577613
by <a href="/recipes/users/4172244/">Michael Grünewald</a>
(<a href="/recipes/tags/yaml/">yaml</a>).
</p>
<p>This recipe shows how one can add <em>include</em> support to applications that use PyYAML.</p>
Chek if a number is a power of two (Python)
2010-12-23T11:29:38-08:00A. Polinohttp://code.activestate.com/recipes/users/4176317/http://code.activestate.com/recipes/577514-chek-if-a-number-is-a-power-of-two/
<p style="color: grey">
Python
recipe 577514
by <a href="/recipes/users/4176317/">A. Polino</a>
(<a href="/recipes/tags/2/">2</a>, <a href="/recipes/tags/check/">check</a>, <a href="/recipes/tags/number/">number</a>, <a href="/recipes/tags/power/">power</a>, <a href="/recipes/tags/python/">python</a>).
Revision 2.
</p>
<p>Pretty good way to check if a number is a power of two or not.</p>
Sublists (Python)
2010-12-21T16:28:20-08:00Michael Pucketthttp://code.activestate.com/recipes/users/4176295/http://code.activestate.com/recipes/577510-sublists/
<p style="color: grey">
Python
recipe 577510
by <a href="/recipes/users/4176295/">Michael Puckett</a>
(<a href="/recipes/tags/grouping/">grouping</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/sublist/">sublist</a>).
</p>
<p>The opposite of list flattening. </p>
<p>Given a list and a length n return a list of sub lists of length n.</p>
Yet another 'enum' for Python (Python)
2010-01-28T18:23:11-08:00Gabriel Genellinahttp://code.activestate.com/recipes/users/924636/http://code.activestate.com/recipes/577024-yet-another-enum-for-python/
<p style="color: grey">
Python
recipe 577024
by <a href="/recipes/users/924636/">Gabriel Genellina</a>
(<a href="/recipes/tags/enum/">enum</a>).
Revision 5.
</p>
<p>There are quite a few 'enum' recipes already here. This one is short, cheap, and has neither bells nor whistles :)</p>
A simple login with dictionary (Python)
2009-07-06T14:38:46-07:00Christopher Scotthttp://code.activestate.com/recipes/users/4171003/http://code.activestate.com/recipes/576833-a-simple-login-with-dictionary/
<p style="color: grey">
Python
recipe 576833
by <a href="/recipes/users/4171003/">Christopher Scott</a>
.
</p>
<p>Just a simple login that uses a dictionary. Don't know if it would work on a console. Plus I can't figure out a way to add something to the dictionary while the program is running.</p>
Wait to tomorrow (Python)
2010-05-01T15:19:28-07:00vojta rylkohttp://code.activestate.com/recipes/users/4173557/http://code.activestate.com/recipes/577183-wait-to-tomorrow/
<p style="color: grey">
Python
recipe 577183
by <a href="/recipes/users/4173557/">vojta rylko</a>
.
Revision 3.
</p>
<p>Get tomorrow morning time, make delta from now and wait x seconds.</p>
Komodo Python Macro - select the current word under the cursor (Python)
2010-01-14T12:30:45-08:00Todd Whitemanhttp://code.activestate.com/recipes/users/2666241/http://code.activestate.com/recipes/577006-komodo-python-macro-select-the-current-word-under-/
<p style="color: grey">
Python
recipe 577006
by <a href="/recipes/users/2666241/">Todd Whiteman</a>
(<a href="/recipes/tags/cursor/">cursor</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/toddw/">toddw</a>, <a href="/recipes/tags/word/">word</a>).
Revision 6.
</p>
<p>A <a href="http://www.activestate.com/komodo">Komodo</a> Python macro that can be used to select the current word under the cursor position.</p>
<p>JavaScript version here: <a href="http://code.activestate.com/recipes/577007/">Recipe 577007</a>.</p>
Komodo JS Macro - show custom code completions (JavaScript)
2010-01-18T13:28:16-08:00Todd Whitemanhttp://code.activestate.com/recipes/users/2666241/http://code.activestate.com/recipes/577012-komodo-js-macro-show-custom-code-completions/
<p style="color: grey">
JavaScript
recipe 577012
by <a href="/recipes/users/2666241/">Todd Whiteman</a>
(<a href="/recipes/tags/code/">code</a>, <a href="/recipes/tags/codeintel/">codeintel</a>, <a href="/recipes/tags/completions/">completions</a>, <a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/scintilla/">scintilla</a>, <a href="/recipes/tags/toddw/">toddw</a>).
</p>
<p>A <a href="http://www.activestate.com/komodo">Komodo</a> JavaScript macro that can be used to display a custom completion pop-up.</p>
<p><img src="http://community.activestate.com/files/images/custom_completions.png" alt="Completions image" /></p>
Caller and Callee (Python)
2010-03-26T20:04:11-07:00Michael Grünewaldhttp://code.activestate.com/recipes/users/4172244/http://code.activestate.com/recipes/576925-caller-and-callee/
<p style="color: grey">
Python
recipe 576925
by <a href="/recipes/users/4172244/">Michael Grünewald</a>
(<a href="/recipes/tags/callee/">callee</a>, <a href="/recipes/tags/caller/">caller</a>, <a href="/recipes/tags/debugging/">debugging</a>).
Revision 4.
</p>
<p>A recipe to find out which function is the caller of the current function. </p>
<p>The <code>caller</code> function can be helpful for debugging — if there is no real debugger available. In terms of software engineering (loose coupling etc.) this should not be used in production code though.</p>
Sieve of Eratosthenes (Python)
2008-12-27T11:45:09-08:00Louis RIVIEREhttp://code.activestate.com/recipes/users/4035877/http://code.activestate.com/recipes/576596-sieve-of-eratosthenes/
<p style="color: grey">
Python
recipe 576596
by <a href="/recipes/users/4035877/">Louis RIVIERE</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/eratosthenes/">eratosthenes</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/primes/">primes</a>).
Revision 3.
</p>
<p>Returns primes < n.</p>
Modfying a local __dict__ (Python)
2008-06-25T10:00:10-07:00Oleg Sidorkinhttp://code.activestate.com/recipes/users/2785709/http://code.activestate.com/recipes/574426-modfying-a-local-__dict__/
<p style="color: grey">
Python
recipe 574426
by <a href="/recipes/users/2785709/">Oleg Sidorkin</a>
.
</p>
<p>Works in python 2.4 and 2.5</p>
Converting DBI results to a list of dictionaries (Python)
2007-09-09T17:59:17-07:00Andrew Smithhttp://code.activestate.com/recipes/users/4081514/http://code.activestate.com/recipes/528939-converting-dbi-results-to-a-list-of-dictionaries/
<p style="color: grey">
Python
recipe 528939
by <a href="/recipes/users/4081514/">Andrew Smith</a>
(<a href="/recipes/tags/database/">database</a>).
</p>
<p>One of the most frequently asked questions is how to efficiently get a list of Python dictionaries from a database query rather than the difficult-to-use list of tuples.</p>