Skip to content

Instantly share code, notes, and snippets.

color = Dir["./hermitage\ color/*"]
infra = Dir["./hermitage\ infra/*"]
start_color = 213
start_infra = 297
color_idx = 0
infra_idx = 0
def mk_filename(idx)
# 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 && \
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
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
@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));
};
@ashaw
ashaw / gist:8338077
Last active January 2, 2016 17:39 — forked from dansinker/gist:8337769

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 (almshaw@gmail.com), 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: http://cl.ly/0L2c152y2n2j, 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?
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}"
else
y = "19#{y}"
end
Date.strptime("#{m}/#{d}/#{y}", "%m/%d/%Y")
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("http://www.documentcloud.org/api/search?q=contributedto%3Afreethefiles+station%3AKMIZ"))
result['documents'].each do |doc|
obj = klass.find_or_initialize_by_url("https://www.documentcloud.org/documents/#{doc['id']}")
# don't plow over verified docs if rerunning the script
obj.verified = false if obj.new_record?
class DeepFinder
attr_reader :accum
def initialize(h, key)
@accum = []
@h = h
@key = key
dig @h
end
# http://rcbth.com/p/getting-an-oauth-token-for-your-twitter-bot
require 'rubygems'
require 'twitter_oauth'
client = TwitterOAuth::Client.new(
:consumer_key => 'BUH',
:consumer_secret => 'BUH'
)
request_token = client.request_token