Skip to content

Instantly share code, notes, and snippets.

@ericallam
ericallam / generated.js
Created February 8, 2012 14:09
Comparing js and coffeescript
(function() {
var TodosView,
__hasProp = Object.prototype.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
TodosView = (function(_super) {
__extends(TodosView, _super);
function TodosView() {
@ericallam
ericallam / package.mdown
Created January 12, 2012 15:18
Use versioned github tarballs to update dependencies on heroku cedar stack

Heroku cedar stack lets you deploy node.js apps and uses the npm package manager to install dependencies When pushing to heroku, it will install dependencies using npm install, and heroku helpfully caches your dependencies between deploys. This can be a problem when you update a dependency that uses a github tarball, like this:

// package.json
{
  "name": "node app name",
  "description": "",
  "version": "0.0.1",
 "dependencies": {
@ericallam
ericallam / foo.rb
Created November 21, 2011 19:34 — forked from ngauthier/foo.rb
currying an instance method
class Foo
def foo(x, y)
"foo! #{x} and #{y}"
end
def bar
# my imaginary syntax for "create functional reference from method foo with argument bar.
&(:foo, 5)
end
end
@ericallam
ericallam / routes.rb
Created November 9, 2011 15:23
Add routes outside of routes.draw
# Unfortunately, you still have to create the routes somewhere in routes.rb
Your::Application.routes.draw do
root :to => 'controller#action'
end
mapper = ActionDispatch::Routing::Mapper.new(Rails.application.routes)
mapper.instance_exec do
match '/some/action' => "some#action"
end
@ericallam
ericallam / app.coffee
Created November 8, 2011 20:02
Set certain regions of an Ace editor to readOnly
event = require('pilot/event')
Anchor = require('ace/anchor').Anchor
doc = ace_editor.session.getDocument()
editablePositions = [[1, 0, 2, 0]] # allow editong only the second row
jQuery.each editable, (index, row) ->
editablePositions.push [new Anchor(doc, row[0], row[1]), new Anchor(doc, row[2], row[3])]
Range = require('ace/range').Range
def products_page
@page.our_products?
end
helper_method :products_page
class Page
OUR_PRODUCTS_TITLE = 'Our Products'
def our_products?
@ericallam
ericallam / heredocs.rb
Created September 14, 2011 14:05
Ruby Heredocs
# by default, heredoc strings are treated like double-quoted ruby strings, which means you can do string interpolation:
<<-EOF
The time is #{Time.now}
EOF
# => The time is Wed Sep 14 10:04:29 -0400 2011
# But you can create heredoc strings that are treated like single-quoted string, like this:
<<-'EOF'
@ericallam
ericallam / module_function.rb
Created September 12, 2011 23:13
Using module_function instead of extend self
# a lot of people in ruby do this
module Foo
extend self
def bar
'bar'
end
end
Foo.bar
@ericallam
ericallam / Gemfile
Created August 28, 2011 14:55
Using the Asset Pipeline outside of Rails - Serving CoffeeScript and SASS
source "http://rubygems.org"
gem 'sprockets', :git => 'git://github.com/sstephenson/sprockets.git'
gem 'coffee-script'
gem 'sass'
gem 'rack-test'
gem 'sinatra'
@ericallam
ericallam / show.html.erb
Created August 26, 2011 16:37
Rails for Zombies 2 – Challenge 5-9
<p id="notice"><%= notice %></p>
<ul>
<li>
<em>Name:</em>
<%= @weapon.name %>
</li>
<li>
<em>Condition:</em>
<span id="condition"><%= @weapon.condition %></span>
<%= link_to "Toggle", toggle_condition_user_weapon_path(@user, @weapon), remote: true %>