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
| package main | |
| import ( | |
| "fmt" | |
| "time" | |
| "strconv" | |
| ) | |
| func makeCakeAndSend(cs chan string) { | |
| for i := 1; i<=20; i++ { |
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 json | |
| import requests | |
| API_KEY = 'YOUR_API_KEY' | |
| BASE_URL = 'http://social.repustate.com/%(api_key)s/%(call)s.json' | |
| # Create a new data source. | |
| kwargs = {'api_key':API_KEY, 'call':'add-datasource'} | |
| response = requests.post(BASE_URL % kwargs, {'name':'Testing', 'language':'en', 'niche':'general'}) | |
| datasource_id = json.loads(response.content)['datasource_id'] |
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
| def process(node): | |
| if isinstance(node, ast.Num): | |
| return str(node.n) | |
| elif isinstance(node, ast.Name): | |
| return node.id | |
| elif isinstance(node, ast.Str): | |
| return r"\b%s\b" % node.s | |
| elif isinstance(node, ast.Expr): | |
| return process(node.value) |
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
| def create_rule(rule, ignore_case=False): | |
| """ | |
| Use Python's AST parser to generate a tree which we'll traverse to create a | |
| regular expression. | |
| """ | |
| results = parser.tokens(rule.strip()) | |
| ast_string = '' | |
| unicode_strings = [] | |
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
| def memo(f): | |
| "Memoize function f." | |
| table = {} | |
| def fmemo(*args): | |
| if args not in table: | |
| table[args] = f(*args) | |
| return table[args] | |
| fmemo.memo = table | |
| return fmemo |
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 requests | |
| API_KEY = 'YOUR_API_KEY' | |
| BASE_URL = 'http://social.repustate.com/%(api_key)s/%(call)s.json' | |
| # Create a new data source. | |
| kwargs = {'api_key':API_KEY, 'call':'add-datasource'} | |
| response = requests.post(BASE_URL % kwargs, {'name':'Rob Ford', 'language':'en', 'niche':'general'}) | |
| datasource_id = response.json()['datasource_id'] |
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 requests | |
| url = "http://social.repustate.com/YOUR_API_KEY/get-data.json?datasource_id=DATASOURCE_ID&since=2013-10-28&until=2013-11-27" | |
| response = requests.get(url).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
| // Load in GeoJSON data | |
| d3.json("/media/js/toronto.json", function(json) { | |
| //Bind data and create one path per GeoJSON feature | |
| svg.select('#paths').selectAll("path") | |
| .data(json.features) | |
| .enter() | |
| .append("path") | |
| .attr("d", path) | |
| .attr("name", function(d) { |
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
| d3.json('/media/js/points.json', function(err, json) { | |
| svg.select('#points') | |
| .selectAll('circle') | |
| .data(json) | |
| .enter() | |
| .append("circle") | |
| .attr("r",4) | |
| .style('fill-opacity', 0.7) | |
| .style('display', function(d) { | |
| if (d.dd == base_date.getDate() && d.mm == base_date.getMonth()+1) { |
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
| // Values to centre and scale the map of Toronto. | |
| var x = -14100 | |
| var y = 7300 | |
| var scale = 66700 | |
| // Define map projection. | |
| projection = d3.geo.albers().translate([x, y]).scale([scale]) | |
| // Define path generator. | |
| var path = d3.geo.path().projection(projection); |
OlderNewer