Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeremy Ashkenas jashkenas

View GitHub Profile
View gist:89405
View Constructor:
this.configure(options);
this._reset();
this.render();
Base View
.el - conventional root element reference for every view
.toElement - returns this.el
.childViews - Array of child views
View tix
#! /usr/bin/env ruby
require 'rubygems'
require 'hpricot'
username = "<username>"
password = "<password>"
tix = Hpricot(IO.popen("curl https://trac.zenbe.com/report/7 --basic -u #{username}:#{password} -k -s"))
(tix/"table.listing.tickets"/"tbody"/"tr").each do |row|
View portfwd.coffee
tcp: require 'tcp'
server: tcp.createServer (socket) ->
client: null
socket.addListener 'connect', ->
client: tcp.createConnection 22
client.addListener 'receive', (data) -> socket.send(data)
client.addListener 'eof', -> client.close()
View gist:305158
Function.prototype.curry: (scope, rest...) ->
scope ||= this
=> @apply(scope, rest)
View inheritance.coffee
class B extends A
constructor: ->
@where_am_i: 'at work'
sayWhereYouAre: ->
alert 'I am ' + @where_am_i
View nodeFactory2.js
function nodeFactory() {
function toStringFactory(data) { return function toString() {
// TODO: Implement
}}
function compileFactory(data) { return function compile() {
// TODO: Implement
}}
return {
BaseNode: function (data) {
return {
View sinatra.coffee
routes: {}
get: (route, handler) ->
routes[route]: handler
#############################################
get 'greet/:name', (request) ->
"Hello " + request.params['name']
View equality and operators.coffee
func: (should_i) ->
do_it() if should_i = true
somevar: 0
while should_i = true
do_it()
somevar: somevar + 1
should_i: false
# Compared to
View __slice.js
var __slice = function(array, from, to) {
return array.slice(
from < 0 ? from + array.length : from || 0,
to < 0 ? to + array.length : to == 0 ? to : array.length
);
};
View denied.coffee
# This Python:
@cache('public')
@get('/')
def hello():
return 'Hello World!'
# Can be done like this with CoffeeScript: