Skip to content

Instantly share code, notes, and snippets.

View infra-sync.rb
color = Dir["./hermitage\ color/*"]
infra = Dir["./hermitage\ infra/*"]
start_color = 213
start_infra = 297
color_idx = 0
infra_idx = 0
def mk_filename(idx)
View charlie-loyd.rake
task :landsat_2014 => :environment do
dirs = Dir["#{Rails.root.to_s}/db/initial/raster/*"].reject {|q| q =~ /tar\.gz/ }
dirs.each do |dir|
scene_id = dir.split("/")[-1]
[4,3,2].each do |band|
`gdalwarp -t_srs EPSG:3857 #{dir}/#{scene_id}_B#{band}.TIF #{dir}/#{scene_id}_B#{band}-projected.tif`
`convert -combine #{dir}/#{scene_id}_B{4,3,2}-projected.tif #{dir}/#{scene_id}_RGB-projected.tif && \
convert -channel B -gamma 0.925 -channel R -gamma 1.03 -channel RGB -sigmoidal-contrast 50x16% #{dir}/#{scene_id}_RGB-projected.tif #{dir}/#{scene_id}_RGB-projected-corrected.tif && \
View dms-yolo.rb
def dms_to_coord(dms, latlng)
re = latlng == 'lat' ? /^([\d]{2})([\d]{2})([\d]{2}(?:\.[\d]+)?)/ : /^([\d]{3})([\d]{2})([\d]{2}(?:\.[\d]+)?)/
q = dms.split(re)
d, m, s =
res = d + m / 60 + s / 3600
latlng == 'lng' ? "-#{res}" : res
View rdb.rb
class RDB
attr_reader :headers, :data
def initialize(f)
@file =
@data = @file.reject {|q| q =~ /^#/ }
@headers = @data.shift.chomp.split("\t")
@data.shift # remove schema line! {|q| q.chomp.split("\t")}
View sankey.js
var Sankey = function(opts) {
this.opts = opts;
this.el = $("#" + this.opts.el);
this.graphsReady = 0;
this.graphWidth = this.el.width();
Sankey.prototype.initPaper = function() {
this.paper = Raphael(document.getElementById(this.opts.el));
View gist:8338077

Tire Quality App: How Safe Are Your Tires?

Before you get to SF:

  1. Install Rails. Unless a critical mass of people are Pythonistas, we'll use Rails. (We'll use all manner of other tools, depending on the Fellows' skills and interests) but, as a baseline, make sure Rails is installed and working on your machine before you show up. (Instructions are below.)
  2. Send me a note (, or comment on this gist about what tools you like to use to build things, whether it be Ruby, Python, R, JavaScript, etc, and we'll adjust our stack to how most people like to do things.
  3. Download the UTQGS data:, and take a look at it
  4. Develop some questions about the data that you'd want to see in an app. Example questions that come to mind:
  • What are the safety ratings of the country's best-selling tires?
View parse_date.rb
def parse_date(d)
d.strip.gsub(/[^\d\/]/,"") =~ /(^[\d]{1,2}\/[\d]{1,2}\/[\d]{2}$)/
if $1
m, d, y = $1.split("/")
if y.to_i <= 13
y = "20#{y}"
y = "19#{y}"
Date.strptime("#{m}/#{d}/#{y}", "%m/%d/%Y")
View transcribable-harvest.rake
namespace :transcribable do
desc "Harvest documents to transcribe from DocumentCloud"
task :harvest_kmiz => :environment do
require 'rest-client'
klass = Kernel.const_get(Transcribable.table.classify)
result = JSON.parse(RestClient.get(""))
result['documents'].each do |doc|
obj = klass.find_or_initialize_by_url("{doc['id']}")
# don't plow over verified docs if rerunning the script
obj.verified = false if obj.new_record?
View deep_finder.rb
class DeepFinder
attr_reader :accum
def initialize(h, key)
@accum = []
@h = h
@key = key
dig @h
View twitter_bot.rb
require 'rubygems'
require 'twitter_oauth'
client =
:consumer_key => 'BUH',
:consumer_secret => 'BUH'
request_token = client.request_token