Skip to content

Instantly share code, notes, and snippets.

select z.zonedist,st_asgeojson(z.the_geom) from zones as z join districts as d on st_contains(d.the_geom, z.the_geom) or st_overlaps(d.the_geom,z.the_geom) where d.cd = 301;
def self.wb_gp_geojson
self.find_by_sql(
"SELECT z.zonedist,ST_AsGeoJSON(z.the_geom)
FROM zones AS z JOIN districts AS d ON
ST_Contains(d.the_geom, z.the_geom)
OR ST_Overlaps(d.the_geom,z.the_geom)
WHERE d.cd = 301;"
).map {|r|
{ :geojson => JSON.parse(r.st_asgeojson), :zonedist => r.zonedist }
}.to_json
makeWidebar : function(e, sId) {
var that = this;
this.initialColor = this.getInitialColor(sId);
console.log(sId, this.initialColor)
this.initialColor = this.initialColor.match(/[0-9]{1,3}/g)
this.initialHsl = this.curHsl = rgbToHsl(this.initialColor[0], this.initialColor[1], this.initialColor[2]);
_(this.el).each(function(barSegment) {
that.curHsl[2] = that.curHsl[2] * .80;
that.curRgb = hslToRgb(that.curHsl[0], that.curHsl[1], that.curHsl[2]);
that.curRgb = _(that.curRgb).map(function(q) { return Math.floor(q) });
var jankyLoginStatus = function(cb) {
var that = this;
var statusObj = {};
// see if we can get "me"
FB.api('/me', function(response) {
// we can't get me. Verify it's an OAuthException, and then sub in notConnected.
if (response['error'] && response['error']['type'] === "OAuthException") {
statusObj['status'] = "notConnected";
FB.logout(); // just to make sure we don't have stale cookies
return cb(statusObj);
Kernel.const_get(
self.class.to_s.titleize + "Comparisons" + self.class.to_s.titleize).where("#{self.class.to_s.downcase}_id".to_sym => self.id
).collect {|r|
Kernel.const_get(self.class.to_s.titleize + "Comparison").find(r.send("#{self.class.to_s.downcase}_comparison_id"))
}.group_by {|r|
r.send(self.class.to_s.downcase.pluralize)[1..-1].collect {|q| q.id}
}.to_a.reduce([]) { |memo, bits| memo << {:ids => bits[0], :ct => bits[1].size }; memo }
var getGenericFbImg = function() {
var genders = ['Female', 'Male'];
var gender = genders[Math.floor(Math.random() * 2)];
return "http://www.facebook.com/images/profile/blankSilhouette" + gender + ".png"
}
// thx: https://github.com/bcherry/twitter-text-js/blob/master/twitter-text.js
var stringSupplant = function(str, values) {
return str.replace(/#\{(\w+)\}/g, function(match, name) {
return values[name] || "";
});
};
@ashaw
ashaw / bm.rb
Created May 23, 2011 20:07 — forked from thejefflarson/bm.rb
poor man's benchmark
def measure
t = Time.now
yield
Rails.logger.info Time.now - t
end
#!/usr/bin/env ruby
require 'rubygems'
require 'faster_csv'
TIMEFLOW_HEADERS = ["StartDate", "EndDate", "Time", "Events", "Remarks", "Where", "Coordinates", "Source"]
TIMELINESETTER_HEADERS = ["date", "display_date", "description", "link", "series", "html"]
class TF2TS