This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Function to generate a percentage calculator. | |
| // Percentages will be rounded to nearest whole number. | |
| // The calculator ensures the entire set of percentages adds up to 100. | |
| var percentageCalculatorGenerator = function(numDataPoints, total) { | |
| // Ensure cumulative total adds up to 100 | |
| var cumulativeTotal = 0; | |
| // Return the generated function | |
| return function(value, idx) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """ | |
| Example of using grequests with OAuth. | |
| See: https://github.com/kennethreitz/grequests | |
| """ | |
| import json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| From: http://sdiehl.github.com/gevent-tutorial/#queues | |
| In this example we have the boss running simultaneously to the workers and have a restriction on the Queue that it can contain no more than three elements. This restriction means that the put operation will block until there is space on the queue. Conversely the get operation will block if there are no elements on the queue to fetch, it also takes a timeout argument to allow for the queue to exit with the exception gevent.queue.Empty if no work can found within the time frame of the Timeout. | |
| """ | |
| import gevent | |
| from gevent.queue import Queue, Empty | |
| tasks = Queue(maxsize=3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """ | |
| Gevent examples. | |
| """ | |
| import json | |
| import gevent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Define callback (can define 1 per request) | |
| def callback(response): | |
| print "Got", response |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """ | |
| Example of fetching followers of multiple Twitter accounts recursively, using twitterspawn. | |
| """ | |
| import atexit | |
| import json | |
| import twitterspawn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import socket | |
| if __name__ == "__main__": | |
| sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| sock.connect(("localhost", 9000)) | |
| data = "some data" | |
| sock.sendall(data) | |
| result = sock.recv(1024) | |
| print result | |
| sock.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # OAuth stuff... | |
| ACCESS_TOKEN = "YOUR_ACCESS_TOKEN" | |
| ACCESS_TOKEN_SECRET = "YOUR_ACCESS_TOKEN_SECRET" | |
| CONSUMER_KEY = "YOUR_CONSUMER_KEY" | |
| CONSUMER_SECRET = "YOUR_CONSUMER_SECRET" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """Connect to Twitter, track a hashtag, read out the tweets!""" | |
| import getpass | |
| import json | |
| import random | |
| import sys | |
| import subprocess | |
| import multiprocessing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """Connect to Twitter, track a hashtag, read out the tweets!""" | |
| import sys | |
| import subprocess | |
| import multiprocessing | |
| import track |