Popular recipes tagged "meta:loc=80"http://code.activestate.com/recipes/tags/meta:loc=80/2016-07-17T17:26:47-07:00ActiveState Code RecipesPrint Directly from web application to POS/EPS thermal printer (PHP)
2014-09-01T14:55:56-07:00imam feriantohttp://code.activestate.com/recipes/users/633541/http://code.activestate.com/recipes/578925-print-directly-from-web-application-to-poseps-ther/
<p style="color: grey">
PHP
recipe 578925
by <a href="/recipes/users/633541/">imam ferianto</a>
(<a href="/recipes/tags/kasir/">kasir</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/over/">over</a>, <a href="/recipes/tags/php/">php</a>, <a href="/recipes/tags/pos/">pos</a>, <a href="/recipes/tags/printer/">printer</a>, <a href="/recipes/tags/tiketing/">tiketing</a>).
Revision 2.
</p>
<p>this php script will printout barcode label directly from the web by phpscript</p>
The many uses of randomness - Part 2 (Python)
2016-07-17T17:26:47-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580690-the-many-uses-of-randomness-part-2/
<p style="color: grey">
Python
recipe 580690
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/random/">random</a>, <a href="/recipes/tags/random_number/">random_number</a>, <a href="/recipes/tags/simulation/">simulation</a>, <a href="/recipes/tags/testing/">testing</a>).
</p>
<p>This is the second recipe in the series about the uses of randomness in Python. The first recipe is here:</p>
<p><a href="https://code.activestate.com/recipes/580674-the-many-uses-of-randomness-part-1/?in=user-4173351" rel="nofollow">https://code.activestate.com/recipes/580674-the-many-uses-of-randomness-part-1/?in=user-4173351</a></p>
<p>This second recipe shows some uses of random numbers to generate random characters and random strings of various categories, and some purposes for which these generated strings can be used in testing.</p>
Infix Expression Evaluation (Python)
2015-11-08T05:08:26-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/579123-infix-expression-evaluation/
<p style="color: grey">
Python
recipe 579123
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/stack/">stack</a>).
</p>
<p>Infix expression evaluation using two stacks.</p>
The Bentley-Knuth problem and solutions (Python)
2014-03-15T23:46:59-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578851-the-bentley-knuth-problem-and-solutions/
<p style="color: grey">
Python
recipe 578851
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/text_processing/">text_processing</a>).
</p>
<p>This is a program Jon Bentley asked Donald Knuth to write, and is one that’s become familiar to people who use languages with serious text-handling capabilities: Read a file of text, determine the n most frequently used words, and print out a sorted list of those words along with their frequencies. I wrote 2 solutions for it earlier, in Python and in Unix shell. Also see the comment by a user on the post, giving another solution.</p>
The game of Hangman in Python (Python)
2013-06-06T21:55:18-07:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578551-the-game-of-hangman-in-python/
<p style="color: grey">
Python
recipe 578551
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>Here is my version of the Game of Hangman in Python. I worte for my blog <a href="http://thelivingpearl.com/2013/06/06/the-game-of-hangman-in-python/">Captain DeadBones Chronicles</a></p>
Class-only Methods (Python)
2013-03-08T17:00:53-08:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/578486-class-only-methods/
<p style="color: grey">
Python
recipe 578486
by <a href="/recipes/users/4177816/">Eric Snow</a>
(<a href="/recipes/tags/metaprogramming/">metaprogramming</a>).
</p>
<p>We use the classmethod builtin to tie methods to the class rather than the instance. This is really useful for a variety of things, like alternate contructors. However, sometimes you don't want to expose the method on the instances, just on the class.</p>
<p>For instance, it usually doesn't make a lot of sense to have direct access to alternate constructors from instances; the main constructor, via the __call__ method, is only available on the class. Why? So that instances call implement their own call semantics. This is similar to why the methods (and other class attributes) on namedtuples all have names starting with an underscore.</p>
<p>To restrict a method just to the class, currently you must use a metaclass. Most people consider this black magic so they just use @classmethod. Furthermore, implementing a metaclass is simply more verbose than decorating a method with classmethod. Plus you have to deal with things like metaclass conflicts and the fact that metaclasses are inherited.</p>
<p>So...here is a sibling to classmethod that makes a method class-only without introducing metaclass complexity. You use it the same way as you would classmethod.</p>
An analogue of enumerate for nested lists. (Python)
2012-12-11T16:59:14-08:00John Crichtonhttp://code.activestate.com/recipes/users/4181975/http://code.activestate.com/recipes/578376-an-analogue-of-enumerate-for-nested-lists/
<p style="color: grey">
Python
recipe 578376
by <a href="/recipes/users/4181975/">John Crichton</a>
(<a href="/recipes/tags/enumerate/">enumerate</a>, <a href="/recipes/tags/index/">index</a>, <a href="/recipes/tags/iterator/">iterator</a>, <a href="/recipes/tags/list/">list</a>).
Revision 6.
</p>
<p>A generator function which enables traversal and modification of deeply nested lists. Together with the supplied helper functions it could be useful when working with data stored in deeply
nested lists, particularly when the level of nesting precludes a recursive approach.</p>
bubblebabble (Python)
2012-11-03T09:28:41-07:00Space Hobohttp://code.activestate.com/recipes/users/4184146/http://code.activestate.com/recipes/578319-bubblebabble/
<p style="color: grey">
Python
recipe 578319
by <a href="/recipes/users/4184146/">Space Hobo</a>
(<a href="/recipes/tags/babble/">babble</a>, <a href="/recipes/tags/bubble/">bubble</a>, <a href="/recipes/tags/digest/">digest</a>, <a href="/recipes/tags/hash/">hash</a>, <a href="/recipes/tags/human/">human</a>, <a href="/recipes/tags/readable/">readable</a>).
</p>
<p>This module provides a bubblebabble function, which computes a (somewhat more) human readable format for message digests.</p>
A Python chat program using process intercommunication (Python)
2012-09-12T10:02:21-07:00Chaobin Tang (唐超斌)http://code.activestate.com/recipes/users/4174076/http://code.activestate.com/recipes/578260-a-python-chat-program-using-process-intercommunica/
<p style="color: grey">
Python
recipe 578260
by <a href="/recipes/users/4174076/">Chaobin Tang (唐超斌)</a>
(<a href="/recipes/tags/multiprocessing/">multiprocessing</a>).
</p>
<p>This demo chat program, at some aspect, mimic the way that Erlang makes a distributable application. Because it utilizes process, the CPU cores are used as much as possible.</p>
Python script to create a header for Python scripts (Python)
2011-10-02T15:45:11-07:00userendhttp://code.activestate.com/recipes/users/4179007/http://code.activestate.com/recipes/577846-python-script-to-create-a-header-for-python-script/
<p style="color: grey">
Python
recipe 577846
by <a href="/recipes/users/4179007/">userend</a>
(<a href="/recipes/tags/2/">2</a>, <a href="/recipes/tags/auto/">auto</a>, <a href="/recipes/tags/create/">create</a>, <a href="/recipes/tags/emacs/">emacs</a>, <a href="/recipes/tags/header/">header</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/vim/">vim</a>).
Revision 5.
</p>
<p>This will create a header for a Python script. It is a nice way keep a track of what your script does and when it was created, the author of the script, etc.. </p>
<p>Update: Now, it will automatically open with one of the two most popular editors, Vim or Emacs! This script has been updated from the second version to replace spaces with underscores in the title, to convert uppercase to lowercase. It also checks to see if there is a script with the same name in the current working directory so it will not overwrite another file. Please leave comments and suggestions.</p>
Securely processing Twilio requests from Tornado (Python)
2011-10-05T15:29:44-07:00Jesse Davishttp://code.activestate.com/recipes/users/4175348/http://code.activestate.com/recipes/577893-securely-processing-twilio-requests-from-tornado/
<p style="color: grey">
Python
recipe 577893
by <a href="/recipes/users/4175348/">Jesse Davis</a>
(<a href="/recipes/tags/authentication/">authentication</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/https/">https</a>, <a href="/recipes/tags/nginx/">nginx</a>, <a href="/recipes/tags/telephony/">telephony</a>, <a href="/recipes/tags/tornado/">tornado</a>, <a href="/recipes/tags/twilio/">twilio</a>).
</p>
<p>Twilio is a telephony service that POSTs to a callback URL on your server and asks you what to do when it receives phone calls or SMSes to the numbers you rent from Twilio. But securing your communications with Twilio can be complex if you're using Tornado behind Nginx. This shows you how to protect your Twilio callback URL with HTTP Authentication, request-signing, and (optionally) SSL.</p>
<p>I'm using HTTP Authentication code from Kevin Kelley, and I wrote the rest myself.</p>
Bacwards compatibility part 2... (Python)
2011-09-19T10:01:56-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/577872-bacwards-compatibility-part-2/
<p style="color: grey">
Python
recipe 577872
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/all_versions/">all_versions</a>, <a href="/recipes/tags/amiga/">amiga</a>, <a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/backwards_compatibility/">backwards_compatibility</a>, <a href="/recipes/tags/e_uae/">e_uae</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/winuae/">winuae</a>).
</p>
<p>Some example lines to add to any test code you write that work from Python 1.4.0 to 3.2.2 on various platforms.</p>
<p>It is all Public Domain and you can do with it as you please...</p>
<p>I really don't care how you vote and/or rate this as I try to write Python code for my usage to work on the platforms and versions inside the code.</p>
<p>Some people will know this but MANY won't and there will be more to come that involve platform and version compatibility...</p>
<p>Enjoy finding simple solutions to often VERY difficult problems...</p>
<p>(Watch out for wordwrapping, etc...)</p>
<p>Bazza, G0LCU...</p>
Authenticated encryption with PyCrypto (Python)
2010-01-26T16:05:50-08:00Daniel Millerhttp://code.activestate.com/recipes/users/4016391/http://code.activestate.com/recipes/576980-authenticated-encryption-with-pycrypto/
<p style="color: grey">
Python
recipe 576980
by <a href="/recipes/users/4016391/">Daniel Miller</a>
(<a href="/recipes/tags/aes/">aes</a>, <a href="/recipes/tags/encrypt/">encrypt</a>, <a href="/recipes/tags/hmac/">hmac</a>, <a href="/recipes/tags/pycrypto/">pycrypto</a>).
Revision 3.
</p>
<p>PyCrypto-based authenticated encryption using AES-CBC and HMAC-SHA256. This class only supports shared secret encryption. Look elsewhere for public key encryption.</p>
ironpython script to Monitor Servers internal CPU temprature using WMI MSAcpi_ThermalZoneTemperature with e-mail alerting capability (Python)
2010-03-12T05:25:52-08:00mgarrana Garranahttp://code.activestate.com/recipes/users/4171135/http://code.activestate.com/recipes/577103-ironpython-script-to-monitor-servers-internal-cpu-/
<p style="color: grey">
Python
recipe 577103
by <a href="/recipes/users/4171135/">mgarrana Garrana</a>
(<a href="/recipes/tags/cputemprature/">cputemprature</a>, <a href="/recipes/tags/ironpython/">ironpython</a>, <a href="/recipes/tags/managementobjectsearcher/">managementobjectsearcher</a>, <a href="/recipes/tags/msacpi_thermalzonetemperature/">msacpi_thermalzonetemperature</a>, <a href="/recipes/tags/smtplib/">smtplib</a>, <a href="/recipes/tags/wmi/">wmi</a>).
</p>
<p>ironpython script. It reads a txt file called servers.txt where it contains server names each in a separate line . it executes the function remoteconnect on each server name , the function connects to the server and reads the internal CPU TEMP from the WMI class MSAcpi_ThermalZoneTemperature located in namespace \root\WMI
if internal CPU temp exceeds a certian Threshold , the function sends an alerting e-mail , it can also execute any other desired action using the same concept like sending an alerting sms</p>
Python Program for Windows domain based machines to collect usefull information (admins- software installed) (Python)
2009-07-16T06:49:00-07:00mgarrana Garranahttp://code.activestate.com/recipes/users/4171135/http://code.activestate.com/recipes/576844-python-program-for-windows-domain-based-machines-t/
<p style="color: grey">
Python
recipe 576844
by <a href="/recipes/users/4171135/">mgarrana Garrana</a>
(<a href="/recipes/tags/group_policy_startup_script/">group_policy_startup_script</a>, <a href="/recipes/tags/know_local_administrators_domain_machines/">know_local_administrators_domain_machines</a>, <a href="/recipes/tags/microsoft_inventory_collection/">microsoft_inventory_collection</a>, <a href="/recipes/tags/python_scripts/">python_scripts</a>, <a href="/recipes/tags/software_inventory_domain_machines/">software_inventory_domain_machines</a>).
</p>
<p>this is a python program Python Program for Windows domain based machines to collect usefull information , this can be very customizable to the type of information you'd want to collect.
you can force it to run on all machines using group policy, and each machine would create a file in a specific folder ( for simplicity here , no need to go to a database at this level) with the machine name , and containing such information
for example , this program collects local administrators on the machine( can be very usefull in security assesments or securing the corporate ) , a list of all the software installed on the machine
also other general information like machine name ,current logged on user , system time at script run time and domain that this machine belongs to</p>
<p>i've ran it in practice and i was really amazed by the result , that i couldn't find with any other tool
once you get the idea ... you can go wild with your dreams and do anything you like
i've also written a backend parser which parses the results and prints out a report with the required results
this program needs python for win32 installed
the program uses windows registery , win32 api
if you will run this software by group policy , you don't have to install python and python for windows extenstions onto each clinet machine
there is a tool called py2exe which magically , complies the code into and exe and DLL files , that you can run the exe by group policy as a startup script
please excuse the qualtiy of the code , as i am not a programmer , i am sys admin</p>
Assertion that a code fragment throws a particular exception (self-test utility, Python 3) (Python)
2010-07-20T13:15:49-07:00Dmitry Dvoinikovhttp://code.activestate.com/recipes/users/2475216/http://code.activestate.com/recipes/573452-assertion-that-a-code-fragment-throws-a-particular/
<p style="color: grey">
Python
recipe 573452
by <a href="/recipes/users/2475216/">Dmitry Dvoinikov</a>
(<a href="/recipes/tags/testing/">testing</a>, <a href="/recipes/tags/unittests/">unittests</a>).
Revision 2.
</p>
<p>The class presented in this recipe is useful when you are writing module self-tests and need to assert that a fragment of code throws a particular exception.</p>
Doomsday Algorithm (Python)
2007-12-31T09:28:48-08:00Josh Pricehttp://code.activestate.com/recipes/users/4112634/http://code.activestate.com/recipes/541094-doomsday-algorithm/
<p style="color: grey">
Python
recipe 541094
by <a href="/recipes/users/4112634/">Josh Price</a>
(<a href="/recipes/tags/programs/">programs</a>).
</p>
<p>This is a Python progam that lets you practice determining the day of week for any date. This program assumes that you know how to use the Doomsday Algorithm.</p>
Run SQLite-connections in isolated threads (Python)
2006-06-15T18:29:10-07:00Wim Schuthttp://code.activestate.com/recipes/users/2922555/http://code.activestate.com/recipes/496799-run-sqlite-connections-in-isolated-threads/
<p style="color: grey">
Python
recipe 496799
by <a href="/recipes/users/2922555/">Wim Schut</a>
(<a href="/recipes/tags/database/">database</a>).
Revision 3.
</p>
<p>This recipe lets databaseconnections live in their own thread and queues are used to communicate with them.</p>
"only on change" decorator (Python)
2005-06-24T07:17:29-07:00Alan McIntyrehttp://code.activestate.com/recipes/users/2423728/http://code.activestate.com/recipes/426620-only-on-change-decorator/
<p style="color: grey">
Python
recipe 426620
by <a href="/recipes/users/2423728/">Alan McIntyre</a>
.
</p>
<p>This decorator runs a function/method the first time called, and on any subsequent calls when some user-defined metric changes. The metric function provided to the decorator is called every time, but the function being decorated is only called on the first call and when the metric changes.</p>
Automatic delegation through descriptors (Python)
2005-04-25T10:22:23-07:00Diego Novellahttp://code.activestate.com/recipes/users/2425477/http://code.activestate.com/recipes/410693-automatic-delegation-through-descriptors/
<p style="color: grey">
Python
recipe 410693
by <a href="/recipes/users/2425477/">Diego Novella</a>
(<a href="/recipes/tags/oop/">oop</a>).
</p>
<p>When you want a class instance to act as if it was an instance of another class (at least from some aspect), but for some reason you can't use multiple inheritance, You have to deal with some kind of "delegation": You embed an object of the other instance as an attribute of your main instance, and then create as much attributes as you can that "point to" corresponding attribute of the embedded instance. To avoid all that coding stuff, here's a function, "immerse", that automatically sets as class properties all attributes that an instance of another class have, and that are not in the main class.</p>