Skip to content

Instantly share code, notes, and snippets.

View jashkenas's full-sized avatar

Jeremy Ashkenas jashkenas

View GitHub Profile
# /server.coffee
...
{TwitterNode} = require 'twitter-node'
# create our interface to the Twitter Streaming API
twitter = new TwitterNode
user: 'yourtwitterusername'
password: 'yourtwitterpassword'
track: ["why"]
sys = require('sys')
_ = require('underscore')
io = require('socket.io')
express = require('express')
TwitterNode = require('twitter-node').TwitterNode
# vs.
sys = require 'sys'
_ = require 'underscore'
class Docdata < ActiveRecord::Base
belongs_to :document
after_save :index_document
def self.to_hstore(hash)
hash.map {|k, v| "\"#{sanitize(k)}\"=>\"#{sanitize(v)}\"" }.join(',')
end
Sidebar = Backbone.Model.extend
promptColor: ->
@set color: prompt "Please enter a CSS color:"
window.sidebar = new Sidebar
sidebar.bind 'change:color' (model, color) ->
$('#sidebar').css background: color
require 'rubygems'
gem 'rails', '>= 3.0.7'
# Skip ActiveResource.
require 'active_record/railtie'
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'rails/test_unit/railtie'
(= gravity* 1.8 timebase* 120 front-threshold* 1
nourl-factor* .4 lightweight-factor* .3 )
(def frontpage-rank (s (o scorefn realscore) (o gravity gravity*))
(* (/ (let base (- (scorefn s) 1)
(if (> base 0) (expt base .8) base))
(expt (/ (+ (item-age s) timebase*) 60) gravity))
(if (no (in s!type 'story 'poll)) .5
(blank s!url) nourl-factor*
(lightweight s) (min lightweight-factor*
# If the request is asking for JSONP (eg. has a 'callback' parameter), then
# short-circuit, and return the rendered JSONP.
def jsonp_request?
return false unless params[:callback]
@callback = params[:callback]
render :partial => 'common/jsonp.js', :type => :js
true
end
~/Desktop/nyt/work(v2) > sudo npm uninstall coffee-script
npm info it worked if it ends with ok
npm info using npm@0.3.16
npm info using node@v0.4.2
npm info preuninstall coffee-script@1.0.1
npm info uninstall coffee-script@1.0.1
npm info predeactivate coffee-script@1.0.1
npm info deactivate coffee-script@1.0.1
npm info postdeactivate coffee-script@1.0.1
npm info postuninstall coffee-script@1.0.1
if images = settings.preloadImages
(new Image).src = image for image in images.reverse()
select document_id, ts_headline('english', text, plainto_tsquery('#{search}'),
'minWords=10,maxWords=20,maxFragments=1')
as highlight from pages
where pages.document_id in (#{documents.map(&:id).join(',')})
and pages.text @@ plainto_tsquery('#{search}')
limit 5