Popular recipes tagged "meta:loc=112"http://code.activestate.com/recipes/tags/meta:loc=112/2017-06-13T18:44:58-07:00ActiveState Code RecipesLibgen Epub Upload using Tor (Python) 2015-12-06T19:23:54-08:00fuji239http://code.activestate.com/recipes/users/4193238/http://code.activestate.com/recipes/579134-libgen-epub-upload-using-tor/ <p style="color: grey"> Python recipe 579134 by <a href="/recipes/users/4193238/">fuji239</a> (<a href="/recipes/tags/beautifulsoup/">beautifulsoup</a>, <a href="/recipes/tags/libgen/">libgen</a>, <a href="/recipes/tags/mechanize/">mechanize</a>, <a href="/recipes/tags/tor/">tor</a>, <a href="/recipes/tags/upload/">upload</a>). Revision 2. </p> <p>This script shows how to upload epub files in Library Genesys (libgen) automatically by using Tor. Please note that only copyright free epubs should be used (such as those present in <a href="https://www.gutenberg.org/" rel="nofollow">https://www.gutenberg.org/</a>). It will also check if MD5 hash is present before uploading. This is provided for python educative purposes only : it shows how to use a Tor proxy, Mechanize (for uploading and form processing), Hashlib for MD5 calculation, Filemagic for mimetype detecting and BeautifulSoup for response analyzing, all together.</p> Robust Testing of Tkinter Menu Items with Mocking. (Python) 2017-06-13T18:44:58-07:00Stephen Rigdenhttp://code.activestate.com/recipes/users/4191139/http://code.activestate.com/recipes/578964-robust-testing-of-tkinter-menu-items-with-mocking/ <p style="color: grey"> Python recipe 578964 by <a href="/recipes/users/4191139/">Stephen Rigden</a> (<a href="/recipes/tags/invoke/">invoke</a>, <a href="/recipes/tags/mainloop/">mainloop</a>, <a href="/recipes/tags/mock/">mock</a>, <a href="/recipes/tags/mocking/">mocking</a>, <a href="/recipes/tags/tk/">tk</a>, <a href="/recipes/tags/tkinter/">tkinter</a>, <a href="/recipes/tags/unittest/">unittest</a>, <a href="/recipes/tags/unittesting/">unittesting</a>, <a href="/recipes/tags/unittests/">unittests</a>). Revision 7. </p> <p>This recipe addresses the problems encountered when building robust tests for Tk menus. The software under test is a simple window with two menu items that each invoke a one button dialog box. All user visible text is imported from an external config.ini file. This scenario can lead to fragile test code because of the way TK's invoke(index) command has been implemented. (Tcl8.6.3/Tk8.6.3.)</p> Bresenham's line algorithm in n-dimensions (Python) 2012-05-16T16:15:04-07:00Vikas Dhimanhttp://code.activestate.com/recipes/users/4174758/http://code.activestate.com/recipes/578112-bresenhams-line-algorithm-in-n-dimensions/ <p style="color: grey"> Python recipe 578112 by <a href="/recipes/users/4174758/">Vikas Dhiman</a> (<a href="/recipes/tags/bresenham/">bresenham</a>, <a href="/recipes/tags/ray/">ray</a>, <a href="/recipes/tags/tracing/">tracing</a>). Revision 2. </p> <p>Given start and end point, produce a list of points through which line (or ray) will traverse.</p> STL Writer (Python) 2012-08-22T18:46:34-07:00Manfred Moitzihttp://code.activestate.com/recipes/users/4183316/http://code.activestate.com/recipes/578246-stl-writer/ <p style="color: grey"> Python recipe 578246 by <a href="/recipes/users/4183316/">Manfred Moitzi</a> (<a href="/recipes/tags/3d/">3d</a>). </p> <p>Export 3D objects, build of faces with 3 or 4 vertices, as ASCII or Binary STL (Standard Triangulation Language) file.</p> wxPython PDF Viewer using Poppler (Python) 2010-04-15T17:43:27-07:00Marcelo Fernándezhttp://code.activestate.com/recipes/users/4173551/http://code.activestate.com/recipes/577195-wxpython-pdf-viewer-using-poppler/ <p style="color: grey"> Python recipe 577195 by <a href="/recipes/users/4173551/">Marcelo Fernández</a> (<a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/poppler/">poppler</a>, <a href="/recipes/tags/python_poppler/">python_poppler</a>, <a href="/recipes/tags/viewer/">viewer</a>, <a href="/recipes/tags/wxpython/">wxpython</a>). </p> <p>This example shows a PDF Viewer class, which handles things like Zoom and Scrolling. It requires python-poppler and wxPython &gt;= 2.8.9.</p> Python Tkinter Tabs (Python) 2010-06-15T01:50:58-07:00Sunjay Varmahttp://code.activestate.com/recipes/users/4174115/http://code.activestate.com/recipes/577261-python-tkinter-tabs/ <p style="color: grey"> Python recipe 577261 by <a href="/recipes/users/4174115/">Sunjay Varma</a> (<a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/sunjay/">sunjay</a>, <a href="/recipes/tags/tabs/">tabs</a>, <a href="/recipes/tags/tkinter/">tkinter</a>, <a href="/recipes/tags/varma/">varma</a>). Revision 4. </p> <p>This tabbed interface is very useful for Tkinter users. I am sure there is a better way to do it, but I did the best I could.</p> <p>Please enjoy this tabbed interface by SunjayVarma - <a href="http://www.sunjay-varma.com" rel="nofollow">www.sunjay-varma.com</a></p> <p>UPDATES: Fixed the index issues. Made it easier to use.</p> ElementTree CDATA support (Python) 2008-10-10T12:29:33-07:00Eli Golovinskyhttp://code.activestate.com/recipes/users/2770692/http://code.activestate.com/recipes/576536-elementtree-cdata-support/ <p style="color: grey"> Python recipe 576536 by <a href="/recipes/users/2770692/">Eli Golovinsky</a> (<a href="/recipes/tags/elementtree/">elementtree</a>, <a href="/recipes/tags/xml/">xml</a>). Revision 2. </p> <p>This recipe monkey-patches the ElementTree library to allow correct parsing and generation of CDATA sections.</p> tkMath, convert between pixels, inches, cm and mm (Python) 2008-04-12T02:25:41-07:00Ronald Longohttp://code.activestate.com/recipes/users/4093058/http://code.activestate.com/recipes/552745-tkmath-convert-between-pixels-inches-cm-and-mm/ <p style="color: grey"> Python recipe 552745 by <a href="/recipes/users/4093058/">Ronald Longo</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 6. </p> <p>If you're writing some Tkinter software and you're sizing something in inches or centimeters and tkinter only gives you feedback in pixel distances then you may need a way to get back to your prefered units of measure. I recently found myself in this situation. There's nothing fancy about the set of functions here, it's more about the little known winfo_fpixels() function. Once you know about this everything else is a piece of cake. These functions are simple, but convenient.</p> Arbitrary precision binary floating point arithmetic (Python) 2005-05-23T22:10:34-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/412428-arbitrary-precision-binary-floating-point-arithmet/ <p style="color: grey"> Python recipe 412428 by <a href="/recipes/users/178123/">Raymond Hettinger</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 2. </p> <p>Achieves exactness by manipulating values stored as a long integer mantissa with an integer exponent (base two).</p> Closest elements in a target array for a given input array (Python) 2004-11-12T12:29:20-08:00Gerry Wienerhttp://code.activestate.com/recipes/users/825001/http://code.activestate.com/recipes/335390-closest-elements-in-a-target-array-for-a-given-inp/ <p style="color: grey"> Python recipe 335390 by <a href="/recipes/users/825001/">Gerry Wiener</a> (<a href="/recipes/tags/graphics/">graphics</a>). </p> <pre class="prettyprint"><code>Find the set of elements in input_array that are closest to elements in target_array. Record the indices of the elements in target_array that are within tolerance, tol, of their closest match. Also record the indices of the elements in target_array that are outside tolerance, tol, of their match. For example, given an array of observations with irregular observation times along with an array of times of interest, this routine can be used to find those observations that are closest to the times of interest that are within a given time tolerance. </code></pre> MS SQL Server log monitor (Python) 2004-09-16T19:16:14-07:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/286189-ms-sql-server-log-monitor/ <p style="color: grey"> Python recipe 286189 by <a href="/recipes/users/38288/">Matt Keranen</a> (<a href="/recipes/tags/database/">database</a>). Revision 2. </p> <p>A script to gather errors, warnings, and failures from Micrsoft SQL Servers and SQL Server Agents. Creates a single HTML file from multiple server logs. Used as a quick daily check to determine if particular servers require administrator intervention.</p> Abstract methods/classes (Python) 2004-01-23T23:16:14-08:00Ivo Timmermanshttp://code.activestate.com/recipes/users/1590094/http://code.activestate.com/recipes/266468-abstract-methodsclasses/ <p style="color: grey"> Python recipe 266468 by <a href="/recipes/users/1590094/">Ivo Timmermans</a> (<a href="/recipes/tags/oop/">oop</a>). Revision 2. </p> <p>The point is that python doesn't have a notion of “abstract methods.” Abstract methods are part of an base class that defines an interface, without any code. Abstract methods can't be called directly, because they don't contain any code in their definition.</p> <p>In the definition of the base class, you may want to include a specific method that is part of the interface, but the specific implementation is still unknown. A popular example seems to be the drawing of a point or a line in a graphical application.</p> <p>The classes Point and Line share several implementation details, but differ on other. In particular, the way they are drawn is completely different (you will want to optimize the drawing of a line). Suppose these two classes are derived from the same class, Object. It is possible to separate the implementation of the method draw of these two classes, while draw can still be called from the base class Object.</p> Low resource Win32 splashscreen (Python) 2002-04-14T15:18:03-07:00Henk Punthttp://code.activestate.com/recipes/users/235719/http://code.activestate.com/recipes/120687-low-resource-win32-splashscreen/ <p style="color: grey"> Python recipe 120687 by <a href="/recipes/users/235719/">Henk Punt</a> . </p> <p>The following code implements a splash screen as typically found in windows applications. Using only API's available from win32gui, win32api and win32con, it avoids dependancy on MFC (wrapped by win32ui). This way the 600kb or so win32ui.pyd extension DLL is not needed when freezing your app with py2exe. Another 80kb could be squeezed out by not using win32con but to define the necessary constants directly in the code itself.</p> python enum with strings (Python) 2001-10-11T11:39:07-07:00Luis P Caamanohttp://code.activestate.com/recipes/users/135446/http://code.activestate.com/recipes/81098-python-enum-with-strings/ <p style="color: grey"> Python recipe 81098 by <a href="/recipes/users/135446/">Luis P Caamano</a> . </p> <p>Will Ware posted some enum code [ <a href="http://groups.google.com/groups?hl=en&amp;newwindow=1&amp;selm=GIJJzq.Jx1%2540world.std.com" rel="nofollow">http://groups.google.com/groups?hl=en&amp;newwindow=1&amp;selm=GIJJzq.Jx1%40world.std.com</a> ] a while ago, which I started playing with. I am now using a modified version mainly for error numbers instead of an Error class. It's just very nice not to worry about values.</p>