Skip to content

Instantly share code, notes, and snippets.

@ashaw
ashaw / sankey.js
Last active August 29, 2015 13:56
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));
};
class RDB
attr_reader :headers, :data
def initialize(f)
@file = File.open(f).readlines
@data = @file.reject {|q| q =~ /^#/ }
@headers = @data.shift.chomp.split("\t")
@data.shift # remove schema line
@data.map! {|q| q.chomp.split("\t")}
end
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)
q.shift
d, m, s = q.map(&:to_f)
res = d + m / 60 + s / 3600
#yolo
latlng == 'lng' ? "-#{res}" : res
end
# https://www.mapbox.com/blog/processing-landsat-8/
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`
end
`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 && \
color = Dir["./hermitage\ color/*"]
infra = Dir["./hermitage\ infra/*"]
start_color = 213
start_infra = 297
color_idx = 0
infra_idx = 0
def mk_filename(idx)
color = Dir["./west bay pass 1 color/*"]
infra = Dir["./west bay pass 1 infra/*"]
color_idx = 0
infra_idx = 0
def mk_filename(idx)
prefix = "IMG_"
no_str = idx < 1000 ? "0#{idx}" : idx
"#{prefix}#{no_str}"
class TilesController < ApplicationController
around_filter :up_s3
def tile_response(map)
respond_to do |format|
format.png {
send_data map.to_png, :content_type => Mime::Type.lookup_by_extension("png"), :disposition => "inline"
}
end
end
@ashaw
ashaw / gist:256299
Created December 14, 2009 18:44
a polltracker api in a movable type template
<?php
//pollxmlgen - a brute force poll api generator...
//@author al shaw
//sept 2009
//---global stuff--
error_reporting(0);
//---deal with query strings
$challenger1 = $_GET['challenger1'];
@ashaw
ashaw / gist:259063
Created December 17, 2009 22:00
get yr last 1000 tweets
#!/usr/bin/env ruby
(1..50).each {|i| `curl -u username:pass http://twitter.com/statuses/user_timeline.xml?page=#{i} -o twitter_page_#{i}.xml`}
/*
ajaxPaginate (will_paginate via jQuery)
@author Al Shaw for TPM PollTracker (http://polltracker.talkingpointsmemo.com) <al@talkingpointsmemo.com>
December 2009
USAGE!
Stick this in your page somewhere, with the div you want to inject the new content into as the argument.
Here, the injected_div is `.index_polls`. For it to work, you need to have a raw version of your content to inject.
The raw version should take the format <page>?format=list_only&page=[pagenumber].