Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeff Larson thejefflarson

View GitHub Profile
View async_function_queue.js
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();
View deferrable.js
propublica.Deferrable = propublica.View.extend({
init : function(){
this._super();
_.bindAll(this, 'render');
var oldRender = this.render;
this.render = function(){_.defer(oldRender);};
}
});
View view.js
// 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',
View model.js
// 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.
View stat.rb
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
View clocco_parse.clj
# 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
View group_by.rb
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
View proxies.rb
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
View load_balance_graticule.rb
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
View simple-node-logger.js
// hi there npm
var doColor
try {
var stdio = require("stdio")
doColor = stdio.isStderrATTY()
} catch (ex) {
doColor = true
}
function colorize (msg, color) {
You can’t perform that action at this time.