👨👩👧👦
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
propublica.Deferrable = propublica.View.extend({ | |
init : function(){ | |
this._super(); | |
_.bindAll(this, 'render'); | |
var oldRender = this.render; | |
this.render = function(){_.defer(oldRender);}; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// hi there npm | |
var doColor | |
try { | |
var stdio = require("stdio") | |
doColor = stdio.isStderrATTY() | |
} catch (ex) { | |
doColor = true | |
} | |
function colorize (msg, color) { |