Latest Python recipes tagged "meta:requires=numeric"http://code.activestate.com/recipes/langs/python/tags/meta:requires=numeric/new/2010-01-12T15:14:10-08:00ActiveState Code RecipesPurge Mysql binary logs (Python)
2010-01-12T15:14:10-08:00Umang Gopanihttp://code.activestate.com/recipes/users/4172787/http://code.activestate.com/recipes/577004-purge-mysql-binary-logs/
<p style="color: grey">
Python
recipe 577004
by <a href="/recipes/users/4172787/">Umang Gopani</a>
(<a href="/recipes/tags/automate/">automate</a>, <a href="/recipes/tags/binary_logs/">binary_logs</a>, <a href="/recipes/tags/master_slave/">master_slave</a>, <a href="/recipes/tags/mysql/">mysql</a>, <a href="/recipes/tags/purge/">purge</a>).
Revision 8.
</p>
<p>Being a MySQL DBA , one faces a common issue in replication environment -> Disk space issue on master, since the number of binary logs have increased.
Now, one of the solution to this would be using expire_logs_days parameter in your mysql config file.
But what if, the slave is lagging by few hours or if the slave is broken since few days and the binary logs are removed due to the parameter set. Whenever the salve comes up, it will go bonkers, knowing that the binary log where it last stopped no more exists.</p>
<p>I faced this issue a couple of time until I decided to automate it using a script. Herewith I am attaching a python script which can run regularly in cron.</p>
Floyd-Steinberg dithering algorithm (Python)
2009-06-02T01:28:46-07:00Alan Holthttp://code.activestate.com/recipes/users/4170480/http://code.activestate.com/recipes/576788-floyd-steinberg-dithering-algorithm/
<p style="color: grey">
Python
recipe 576788
by <a href="/recipes/users/4170480/">Alan Holt</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/dithering/">dithering</a>, <a href="/recipes/tags/floyd_steinberg/">floyd_steinberg</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/manipulation/">manipulation</a>).
</p>
<p>Floyd-Steinberg dithering is an image dithering algorithm (see <a href="http://en.wikipedia.org/wiki/Floyd-Steinberg" rel="nofollow">http://en.wikipedia.org/wiki/Floyd-Steinberg</a> for more details). While the algorithm is mainly for image manipulation, I use it to create random locations for sensor networt devices.</p>
min/max "peaks" with Numeric (Python)
2006-03-27T02:12:32-08:00Maxim Krikunhttp://code.activestate.com/recipes/users/1085177/http://code.activestate.com/recipes/475188-minmax-peaks-with-numeric/
<p style="color: grey">
Python
recipe 475188
by <a href="/recipes/users/1085177/">Maxim Krikun</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>Given a large one-dimensional array, break it into blocks of contstant length and compute min and max for each block, the so-called "peaks data".</p>
Extracting a low resolution grid from a high resolution grid (Python)
2005-05-23T15:28:15-07:00Gerry Wienerhttp://code.activestate.com/recipes/users/825001/http://code.activestate.com/recipes/414084-extracting-a-low-resolution-grid-from-a-high-resol/
<p style="color: grey">
Python
recipe 414084
by <a href="/recipes/users/825001/">Gerry Wiener</a>
(<a href="/recipes/tags/graphics/">graphics</a>).
Revision 3.
</p>
<p>This recipe illustrates how to extract a low resolution grid from a high resolution grid using the Numeric package. It presents an inefficient but straightforward solution and then a more efficient solution that employs the functionality in Numeric.</p>
Matlab-like 'spy' and 'pcolor' functions (Python)
2005-03-02T15:23:38-08:00Rick Mullerhttp://code.activestate.com/recipes/users/1461790/http://code.activestate.com/recipes/390208-matlab-like-spy-and-pcolor-functions/
<p style="color: grey">
Python
recipe 390208
by <a href="/recipes/users/1461790/">Rick Muller</a>
(<a href="/recipes/tags/graphics/">graphics</a>).
</p>
<p>I really like the 'spy' and 'pcolor' functions, which are useful in viewing matrices. 'spy' prints colored blocks for values that are above a threshold, and 'pcolor' prints out each element in a continuous range of colors.
The attached is a little Python/PIL script that does these functions for Numpy arrays.</p>
Vpython example (Python)
2004-12-29T20:08:26-08:00Matthew Sherbornehttp://code.activestate.com/recipes/users/2235063/http://code.activestate.com/recipes/361168-vpython-example/
<p style="color: grey">
Python
recipe 361168
by <a href="/recipes/users/2235063/">Matthew Sherborne</a>
(<a href="/recipes/tags/programs/">programs</a>).
</p>
<p>An example done to solve this problem:</p>
<p><a href="http://acm.uva.es/p/v1/101.html" rel="nofollow">http://acm.uva.es/p/v1/101.html</a></p>
<p>Animation by vpython (visual python): <a href="http://vpython.org/" rel="nofollow">http://vpython.org/</a></p>
<p>Provides some 3d coolness for new pythonists. Shows some stack usage. Probably should be shorter.</p>
<p>In the __main__ statement at the bottom, replace test2() with parse(), then type something like this on each line:
10
move 5 onto 1
pile 1 onto 3
move 6 over 2
pile 3 over 2
etc.</p>
<p>See the problem link at the top for full instructions...</p>
A Sinus Plasma, using Pygame (Python)
2004-11-07T23:38:22-08:00S Whttp://code.activestate.com/recipes/users/1759688/http://code.activestate.com/recipes/334696-a-sinus-plasma-using-pygame/
<p style="color: grey">
Python
recipe 334696
by <a href="/recipes/users/1759688/">S W</a>
(<a href="/recipes/tags/graphics/">graphics</a>).
</p>
<p>An old-school demo effect, using sine wave interference patterns. Entertaining for at least a few minutes :)</p>
<p>Modify the freq variable for different patterns.</p>