Skip to content

Instantly share code, notes, and snippets.

View thejefflarson's full-sized avatar
👨‍👩‍👧‍👦
being a dad

Jeff Larson thejefflarson

👨‍👩‍👧‍👦
being a dad
View GitHub Profile
propublica.models.AsyncFunctionQueue = propublica.Model.extend({
stopped : false,
init : function(attrs){
this.queue = [];
this._super(attrs);
},
add : function(fn){
this.queue.push(fn);
this._run();
propublica.Deferrable = propublica.View.extend({
init : function(){
this._super();
_.bindAll(this, 'render');
var oldRender = this.render;
this.render = function(){_.defer(oldRender);};
}
});
// The inspiration for this class is grounded in Jeremy Ashkenas's work with
// DocumentCloud. The concept of **bindings** is especially brilliant and is a
// large portion of what makes **Glass.js** tick.
propublica.View = Base.extend({
// jquery object for our target
el : null,
// list of bindings to listen in on
bindings : {},
tag : 'div',
// The primary function of a **Model** is to manipulate and query data. For example filtering
// an array-type object should happen in a subclass of Model. Another great candidate
// for a **Model** is any object that requires an external resource such as an ajax call.
//
// Basically, any long running or long blocking operation should happen in a model.
// **Models** are usually encapsulated in **Views** and rarely, if ever, stand alone.
propublica.Model = Base.extend({
// The **init** method copies the passed in attributes to the instance's built in
// **_attrs** object.
class Stat < ActiveRecord::Base
validates_presence_of :url, :hits
validate_on_create :log_hits?
validate :url_format
named_scope :aggregate, :order => "hits DESC", :select => ["sum(hits) as hits, url, title"], :group => :url
def title
t = read_attribute(:title)
if t.nil?
begin
# this.coffee
parse: (source, code) ->
lines: code.split '\n'
sections: []
language: get_language source
has_code: docs_text: code_text: ''
save: (docs, code) ->
sections.push {
docs_text: docs
class TableFu
def group_by(column)
rows = [["column", "value"]]
faceted_by(column).each {|table| rows << [table.faceted_on, table.rows.length] }
TableFu.new rows
end
end
task :proxies => :environment do
todo = []
#todo << "killall ssh"
todo << "ssh -f jeff@server1 -L 8080:maps.google.com:80 -N"
todo << "ssh -f jeff@server2 -L 8081:maps.google.com:80 -N"
todo << "ssh -f jeff@server3 -L 8082:maps.google.com:80 -N"
`#{todo.join("&&")}`
end
module Graticule #:nodoc:
module Geocoder #:nodoc:
class Google
def initialize(key)
@key = key
@proxies = ["http://127.0.0.1:8080", "http://127.0.0.1:8081", "http://127.0.0.1:8082"]
@url = URI.parse @proxies[rand(@proxies.length)] + '/maps/geo'
end
end
end
// hi there npm
var doColor
try {
var stdio = require("stdio")
doColor = stdio.isStderrATTY()
} catch (ex) {
doColor = true
}
function colorize (msg, color) {