Skip to content

Instantly share code, notes, and snippets.

View nside's full-sized avatar

nside

View GitHub Profile
@nside
nside / distribute.py
Last active December 24, 2015 17:19
Distributes a callback using multiprocessing queues and writes the result back to a file
import multiprocessing, time
from multiprocessing import Pool, JoinableQueue, Process
SENTINEL = -1
def worker(q,rq, callback):
for item in iter(q.get, SENTINEL):
callback(rq, item)
q.task_done()
q.task_done()
@nside
nside / json2csv.py
Created December 6, 2013 23:45
converts a stream from JSON to CSV
#!/usr/bin/env python
import csv, json, sys, cStringIO, codecs
from operator import itemgetter
def fmt(s):
if s == None:
return ''
elif isinstance(s, basestring):
return s.encode('utf-8')
@nside
nside / gist:8078726
Created December 22, 2013 05:18
scrapyd logs grokking for logstash kibana elasticsearch
filter {
grok {
match => [ "message", "%{TIMESTAMP_ISO8601:ts} \[%{USERNAME:spider}\] %{LOGLEVEL:level}: Crawled %{NUMBER:pages2:int} pages \(at %{NUMBER:pages_rate2:int%} pages/min\), scraped %{NUMBER:items2:int} items \(at %{NUMBER:items_rate2:int%} items/min\)" ]
}
}
from twisted.web.iweb import IBodyProducer
from twisted.internet import defer
from twisted.web.client import Agent
from twisted.web.http_headers import Headers
from zope.interface import implements
import urllib
class StringProducer(object):
implements(IBodyProducer)
@nside
nside / pexecute.py
Created January 13, 2015 01:06
reads commands to run on stdin and runs them simultaneously
import multiprocessing, sys, os, fileinput
p = multiprocessing.Pool(4)
p.map(os.system, sys.stdin.readlines())
{u'Location': {u'TelephoneNumber': {u'FunctionalTypeDescription': u'Main', u'PhoneNumber': u'(708) 731-2702'}, u'Name': u'D145 Dist Ofc', u'LocationMilestones': {u'OpenDate': u'2004-02-01T12:00:00'}, u'TypeCode': u'RGD', u'@locale': u'en-US', u'SubTypeDescription': u'District Office', u'TimeZone': {u'TimeZoneCode': u'CST', u'TimeZoneOffset': {u'OffsetCode': u'UTC', u'OffsetHours': u'-06'}, u'TimeZoneDescription': u'Central Std Time'}, u'AlternateIdentifier': {u'TypeDescription': u'Legal Store Number', u'ID': u'T3912'}, u'Address': {u'City': u'Broadview', u'Subdivision': u'IL', u'Longitude': -87.851863, u'County': u'Cook', u'PostalCode': u'60155-4887', u'FormattedAddress': u'800 Broadview Village Sq, Broadview, IL 60155-4887', u'AddressLine1': u'800 Broadview Village Sq', u'Latitude': 41.853146, u'CountryName': u'United States', u'IntersectionDescription': u'NEQ Calumet Ave & BroadmoorAve'}, u'TypeDescription': u'Rgd (region/group/district office)', u'ID': 3912, u'IsDaylightSavingsTimeRecognized': u'true'}}
{
"type": "Feature",
"properties": {
"name": "Coors Field",
"amenity": "Baseball Stadium",
"popupContent": "This is where the Rockies play!"
},
"geometry": {"type":"Polygon","coordinates":[[[-74.3660367388635,39.40413],[-74.3661057823687,39.4035883356439],[-74.366310259581,39.4030674831777],[-74.3666423125559,39.4025874593515],[-74.3670891806838,39.4021667122319],[-74.3676336910731,39.4018214120983],[-74.3682549184949,39.4015648298447],[-74.3689289895278,39.4014068268035],[-74.36963,39.4013534756247],[-74.3703310104722,39.4014068268035],[-74.3710050815051,39.4015648298447],[-74.3716263089269,39.4018214120983],[-74.3721708193162,39.4021667122319],[-74.372617687444,39.4025874593515],[-74.372949740419,39.4030674831777],[-74.3731542176313,39.4035883356439],[-74.3732232611365,39.40413],[-74.3731542176313,39.4046716601493],[-74.372949740419,39.4051925006353],[-74.372617687444,39.405672506532],[-74.3721708193162,39.4060932325023],[-74.3716263089269,39.4064385114866],[-74.37100
@nside
nside / test.md
Last active October 31, 2018 03:47

Alt text

@nside
nside / graphhopper.rs
Created April 21, 2021 05:27
Graphhopper route client for Rust (uses reqwest)
pub type Point = [f64;3];
#[derive(Default, Debug, Clone, PartialEq, serde_derive::Serialize, serde_derive::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RouteResponse {
pub hints: Hints,
pub info: Info,
pub paths: Vec<Path>,
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.