David Blume commited on 2016-08-03 23:44:35
Showing 4 changed files, with 158 additions and 0 deletions.
| ... | ... |
@@ -0,0 +1,28 @@ |
| 1 |
+# testpython |
|
| 2 |
+ |
|
| 3 |
+This is just a test project. You can do anything here, test python |
|
| 4 |
+and IDE projects. |
|
| 5 |
+ |
|
| 6 |
+### Getting the project |
|
| 7 |
+ |
|
| 8 |
+You can get a copy of this project by clicking on the |
|
| 9 |
+[ZIP](http://git.dlma.com/testpython.git/zipball/master) |
|
| 10 |
+or [TAR](http://git.dlma.com/testpython.git/tarball/master) buttons |
|
| 11 |
+near the top right of the GitList web page. |
|
| 12 |
+ |
|
| 13 |
+You can clone from the origin with: |
|
| 14 |
+ |
|
| 15 |
+ git clone ssh://USERNAME@dlma.com/~/git/testpython.git |
|
| 16 |
+ |
|
| 17 |
+### Current Features |
|
| 18 |
+ |
|
| 19 |
+* Multiple directories for testing build systems and IDEs |
|
| 20 |
+ |
|
| 21 |
+### Is it any good? |
|
| 22 |
+ |
|
| 23 |
+[Yes](https://news.ycombinator.com/item?id=3067434). |
|
| 24 |
+ |
|
| 25 |
+### To Do |
|
| 26 |
+ |
|
| 27 |
+* Compare Sublime Text Projects, Visual Studio Code Projects, and Atom Projects. |
|
| 28 |
+ |
| ... | ... |
@@ -0,0 +1,61 @@ |
| 1 |
+# From https://dl.dropboxusercontent.com/u/3967849/pyru/_build/html/threading.html |
|
| 2 |
+import threading, queue |
|
| 3 |
+ |
|
| 4 |
+############################################################################# |
|
| 5 |
+ |
|
| 6 |
+counter = 0 |
|
| 7 |
+ |
|
| 8 |
+counter_queue = queue.Queue() |
|
| 9 |
+ |
|
| 10 |
+def counter_manager(): |
|
| 11 |
+ 'I have EXCLUSIVE rights to update the counter variable' |
|
| 12 |
+ global counter |
|
| 13 |
+ |
|
| 14 |
+ while True: |
|
| 15 |
+ increment = counter_queue.get() |
|
| 16 |
+ counter += increment |
|
| 17 |
+ print_queue.put([ |
|
| 18 |
+ 'The count is %d' % counter, |
|
| 19 |
+ '---------------']) |
|
| 20 |
+ counter_queue.task_done() |
|
| 21 |
+ |
|
| 22 |
+t = threading.Thread(target=counter_manager) |
|
| 23 |
+t.daemon = True |
|
| 24 |
+t.start() |
|
| 25 |
+del t |
|
| 26 |
+ |
|
| 27 |
+############################################################################# |
|
| 28 |
+ |
|
| 29 |
+print_queue = queue.Queue() |
|
| 30 |
+ |
|
| 31 |
+def print_manager(): |
|
| 32 |
+ 'I have EXCLUSIVE rights to call the "print" keyword' |
|
| 33 |
+ while True: |
|
| 34 |
+ job = print_queue.get() |
|
| 35 |
+ for line in job: |
|
| 36 |
+ print(line) |
|
| 37 |
+ print_queue.task_done() |
|
| 38 |
+ |
|
| 39 |
+t = threading.Thread(target=print_manager) |
|
| 40 |
+t.daemon = True |
|
| 41 |
+t.start() |
|
| 42 |
+del t |
|
| 43 |
+ |
|
| 44 |
+############################################################################# |
|
| 45 |
+ |
|
| 46 |
+def worker(): |
|
| 47 |
+ 'My job is to increment the counter and print the current count' |
|
| 48 |
+ counter_queue.put(1) |
|
| 49 |
+ |
|
| 50 |
+print_queue.put(['Starting up']) |
|
| 51 |
+worker_threads = [] |
|
| 52 |
+for i in range(10): |
|
| 53 |
+ t = threading.Thread(target=worker) |
|
| 54 |
+ worker_threads.append(t) |
|
| 55 |
+ t.start() |
|
| 56 |
+for t in worker_threads: |
|
| 57 |
+ t.join() |
|
| 58 |
+ |
|
| 59 |
+counter_queue.join() |
|
| 60 |
+print_queue.put(['Finishing up']) |
|
| 61 |
+print_queue.join() |
| ... | ... |
@@ -0,0 +1,29 @@ |
| 1 |
+# https://dl.dropboxusercontent.com/u/3967849/pyru/_build/html/process.html |
|
| 2 |
+import urllib.request |
|
| 3 |
+ |
|
| 4 |
+sites = [ |
|
| 5 |
+ 'https://www.yahoo.com/', |
|
| 6 |
+ 'http://www.cnn.com', |
|
| 7 |
+ 'http://www.python.org', |
|
| 8 |
+ 'http://www.jython.org', |
|
| 9 |
+ 'http://www.pypy.org', |
|
| 10 |
+ 'http://www.perl.org', |
|
| 11 |
+ 'http://www.cisco.com', |
|
| 12 |
+ 'http://www.facebook.com', |
|
| 13 |
+ 'http://www.twitter.com', |
|
| 14 |
+ 'http://www.macrumors.com/', |
|
| 15 |
+ 'http://arstechnica.com/', |
|
| 16 |
+ 'http://www.reuters.com/', |
|
| 17 |
+ 'http://abcnews.go.com/', |
|
| 18 |
+ 'http://www.cnbc.com/', |
|
| 19 |
+ 'http://www.cnbc.com/', |
|
| 20 |
+] |
|
| 21 |
+ |
|
| 22 |
+def sitesize(url): |
|
| 23 |
+ ''' Determine the size of a website ''' |
|
| 24 |
+ with urllib.request.urlopen(url) as u: |
|
| 25 |
+ page = u.read() |
|
| 26 |
+ return url, len(page) |
|
| 27 |
+ |
|
| 28 |
+for result in map(sitesize, sites): |
|
| 29 |
+ print(result) |
| ... | ... |
@@ -0,0 +1,40 @@ |
| 1 |
+#!/usr/bin/env python |
|
| 2 |
+# -*- coding: utf-8 -*- |
|
| 3 |
+# |
|
| 4 |
+# "Hello Friends" in Chinese: 朋友你好 |
|
| 5 |
+import os |
|
| 6 |
+import sys |
|
| 7 |
+import time |
|
| 8 |
+from argparse import ArgumentParser |
|
| 9 |
+ |
|
| 10 |
+ |
|
| 11 |
+def set_v_print(verbose): |
|
| 12 |
+ """ |
|
| 13 |
+ Defines the function v_print. |
|
| 14 |
+ It prints if verbose is true, otherwise, it does nothing. |
|
| 15 |
+ See: http://stackoverflow.com/questions/5980042 |
|
| 16 |
+ :param verbose: A bool to determine if v_print will print its args. |
|
| 17 |
+ """ |
|
| 18 |
+ global v_print |
|
| 19 |
+ if verbose: |
|
| 20 |
+ def v_print(*s): |
|
| 21 |
+ print ' '.join([i.encode('utf8') for i in s])
|
|
| 22 |
+ else: |
|
| 23 |
+ v_print = lambda *s: None |
|
| 24 |
+ |
|
| 25 |
+ |
|
| 26 |
+def main(debug): |
|
| 27 |
+ start_time = time.time() |
|
| 28 |
+ localdir = os.path.abspath(os.path.dirname(sys.argv[0])) |
|
| 29 |
+ v_print("(verbose mode) debug =", str(debug))
|
|
| 30 |
+ v_print("(verbose mode) debug = %s, localdir = %s" % (repr(debug), localdir))
|
|
| 31 |
+ print "Done. That took %1.2fs." % (time.time() - start_time) |
|
| 32 |
+ |
|
| 33 |
+ |
|
| 34 |
+if __name__ == '__main__': |
|
| 35 |
+ parser = ArgumentParser(description='Just a template sample.') |
|
| 36 |
+ parser.add_argument('-d', '--debug', action='store_true')
|
|
| 37 |
+ parser.add_argument('-v', '--verbose', action='store_true')
|
|
| 38 |
+ args = parser.parse_args() |
|
| 39 |
+ set_v_print(args.verbose) |
|
| 40 |
+ main(args.debug) |
|
| 0 | 41 |