Skip to content

Instantly share code, notes, and snippets.

View jpmckinney's full-sized avatar

James McKinney jpmckinney

View GitHub Profile
@jpmckinney
jpmckinney / popolo-example.rb
Created February 7, 2014 18:14
Public example of how to validate Popolo documents.
require 'json'
require 'open-uri'
require 'json-schema'
schema = JSON.load(open("http://popoloproject.com/schemas/person.json#"))
JSON::Validator.cache_schemas = true
JSON.load(open("https://raw.github.com/tmtmtmtm/eduskunta-popolo/master/people.json")).each do |person|
@jpmckinney
jpmckinney / node-shp-walk.js
Created February 8, 2014 18:51
Transform shapefiles to GeoJSON using the node-shp module
#!/usr/bin/env node
var fs = require('fs')
, path = require('path')
, walk = require('walk')
, shp = require('shp');
if (process.argv.indexOf('--help') !== -1 || process.argv.indexOf('-h') !== -1) {
console.log('Usage: geojson.js [input directory] [output directory]');
process.exit(0);
@jpmckinney
jpmckinney / scout-adapter.rb
Last active August 29, 2015 13:57
Documentation for Scout.
module Subscriptions
module Adapters
class Base
class << self
# One of "bill", "document", "opinion", "regulation", "speech", "state_bill", "state_legislator" or nil.
ITEM_TYPE = nil
# Whether the adapter supports searching.
SEARCH_ADAPTER = false
# Whether the adapter supports subscriptions only.
ITEM_ADAPTER = false
require 'csv'
require 'open-uri'
data_catalogs = {}
rows = CSV.parse(open('https://raw.github.com/opencivicdata/ocd-division-ids/master/identifiers/country-ca/ca_municipal_subdivisions-data_catalog.csv').read)
rows.shift
rows.each do |id,data_catalog|
data_catalogs[id[/[^:]+\z/]] = data_catalog
end
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jpmckinney
jpmckinney / qgis-transparency.py
Created March 31, 2014 17:53
Python snippet to change the current layer's transparency in QGIS
# @see http://linfiniti.com/2011/12/vector-transparency-plugin-for-qgis/
layer = iface.mapCanvas().currentLayer()
layer.setLayerTransparency(50) # int between 0 and 100
iface.mapCanvas().refresh()
HTTP methods:
5 CONNECT
10 PUT
47 PROPFIND
1962 POST
97097 null
97115 OPTIONS
102141 HEAD
2901012 GET
@jpmckinney
jpmckinney / company-status.rb
Last active August 29, 2015 14:00
Evaluate the popularity of company statuses.
require 'open-uri'
require 'nokogiri'
status = Hash.new(0)
Nokogiri::HTML(open('https://opencorporates.com/')).css('#facets a').each do |a|
Nokogiri::HTML(open("https://opencorporates.com#{a[:href]}")).css('.current_status li').each do |li|
status[li.at_css('a').text.strip] += Integer(li.at_css('span').text.strip.gsub(',', ''))
end
end
@jpmckinney
jpmckinney / Gemfile
Last active August 29, 2015 14:02
Get voting data for Kamil Gregor's analysis from OpenParliament.ca
source 'https://rubygems.org'
gem 'pupa', '~> 0.1.1'
@jpmckinney
jpmckinney / patch.diff
Created September 26, 2014 17:31
rangeslider.js is not accessible (https://github.com/andreruffert/rangeslider.js/issues/47), its math is wrong in getPositionFromValue, and it treats 0 as falsy.
diff --git a/app/assets/javascripts/rangeslider.js b/app/assets/javascripts/rangeslider.js
index 1531b77..9637194 100644
--- a/app/assets/javascripts/rangeslider.js
+++ b/app/assets/javascripts/rangeslider.js
@@ -107,7 +107,7 @@
this.identifier = 'js-' + pluginName + '-' +(pluginIdentifier++);
this.min = parseFloat(this.$element[0].getAttribute('min') || 0);
this.max = parseFloat(this.$element[0].getAttribute('max') || 100);
- this.value = parseFloat(this.$element[0].value || this.min + (this.max-this.min)/2);
+ this.value = parseFloat(this.$element[0].getAttribute('value') || this.min + (this.max - this.min) / 2);