Skip to content

Instantly share code, notes, and snippets.

View bwreilly's full-sized avatar

Ben Reilly bwreilly

  • Montreal Quebec
View GitHub Profile
@bwreilly
bwreilly / all-your-reps.py
Created February 11, 2017 03:36
Get all your state/fed reps by address
import requests
openstates_t = 'http://openstates.org/api/v1/legislators/geo/?lat={lat}&long={long}'
sunlight_t = 'https://congress.api.sunlightfoundation.com/legislators/locate?latitude={lat}&longitude={long}'
geocoding_t = 'https://geocoding.geo.census.gov/geocoder/locations/onelineaddress?address={address}&benchmark=9&format=json'
def get_coordinates(address):
url = geocoding_t.format(address=address)
x, y = requests.get(url).json().get('result').get('addressMatches')[0].get('coordinates').values()
return x, y
@bwreilly
bwreilly / user.keymap.clj
Last active August 29, 2015 14:04
Sublime to LightTable keymap
{:+ {:app {}
:editor {"alt-w" [:editor.watch.watch-selection]
"alt-shift-w" [:editor.watch.unwatch]
"pmeta-/" [:toggle-comment-selection]
"pmeta-d" [:editor.sublime.selectNextOccurrence]
"pmeta-ctrl-up" [:editor.sublime.swapLineUp]
"pmeta-ctrl-down" [:editor.sublime.swapLineDown]
"ctrl-shift-up" [:editor.sublime.selectLinesUpward]
"ctrl-shift-down" [:editor.sublime.selectLinesDownward]}}}
@bwreilly
bwreilly / django_haystack_testing
Last active December 20, 2015 01:39
testing search in django (haystack)
TEST_INDEX = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'TIMEOUT': 60 * 10,
'INDEX_NAME': 'test_index',
},
}
@bwreilly
bwreilly / after_layer.js
Created March 16, 2012 20:06
openlayers with some backbone
Layer = Backbone.Model.extend();
Layer.prototype.initialize = function() {
var lyr = new olCls(this.get('name'), this.get('url'), opts);
this.set({ olLayer: lyr });
};
LayerView.prototype.render = function() {
var view = this;
var trucks = new Layer({name: 'Vehicles');
view.map.addLayer(trucks);
// refresh the vehicles and turn them into markers
@bwreilly
bwreilly / txmeter_esri.py
Created February 7, 2012 23:52
nx_spatial, networkx for trivial spatial graph processing
import arcgisscripting as arc
import nx_spatial as ns
# add the fcs to networkx network
G = ns.read_fc(workingdir, gp)
tx = ns.attr_find(G, FcName="Transformer")
#break up net into connected components
components = nx.connected_components(G.to_undirected())
for c in components:
@bwreilly
bwreilly / txmeter_esri.py
Created February 7, 2012 23:27
nx_spatial, networkx for trivial spatial graph processing
import arcgisscripting as arc
import csv
import networkx as nx
import nx_spatial as ns
gp = arc.create(9.3)
features = [
"ServicePoint",
"Transformer",
"SecUGElectricLineSegment",
@bwreilly
bwreilly / arcobjects_cursor_enumerable.cs
Created July 1, 2011 15:26
simple arcobjects cursor example to IEnumerable
public static IEnumerable Features(IFeatureCursor featureEnum)
{
IFeature f = featureEnum.NextFeature();
while (f != null)
{
yield return f;
f = featureEnum.NextFeature();
}
}
@bwreilly
bwreilly / featureclass_arcobjects.cs
Created July 1, 2011 15:18
literally how you get a featureclass in arcobjects
ESRI.ArcGIS.Geodatabase.IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesFile.ArcInfoWorkspaceFactoryClass();
ESRI.ArcGIS.Geodatabase.IWorkspace workspace = workspaceFactory.OpenFromFile(databaseOrDirectory, 0);
ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace;
ESRI.ArcGIS.Geodatabase.IFeatureDataset featureDataset = featureWorkspace.OpenFeatureDataset(featureClassName);
ESRI.ArcGIS.Geodatabase.IFeatureClass fc = (IFeatureClass)featureDataset;