Skip to content

Instantly share code, notes, and snippets.

~/bin/src/node $ coffee -pe "x: [0..10]"
(function() {
var _a, _b;
{
x: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
};
})();
~/bin/src/node $ coffee -pe "i in [0..10]"
(function() {
var _a, _b, _c, _d, _e;
!!(function(){ for (var _d=0, _e=(_a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).length; _d<_e; _d++) if (_a[_d] === i) return true; }).call(this);
})();
~ $ coffee -pe "a: 3"
(function() {
{
a: 3
};
})();
~ $ cat > test.coffee
a: 3
b: 4
c: a + b
~ $ coffee -p test.coffee
(function() {
{
a: 3,
~/bin/src/coffee-script $ coffee -pe "thing[stuff()] ?= 5"
(function() {
var _a, _b;
thing[(_a = stuff())] = (typeof (_b = thing[(_a = stuff())]) !== "undefined" && _b !== null) ? thing[_a] : 5;
})();
should be
~/bin/src/coffee-script $ coffee -pe "thing[stuff()] ?= 5"
(function() {
$.each carousels, ->
carousel = $(this)
carousels.each ->
carousel = $(this)
# or abstract it out
$.fn.each_j = (callback) ->
this.each (i) ->
callback.call this, i, $(this)
@rf-
rf- / gist:954788
Created May 4, 2011 05:13 — forked from anonymous/gist:954770
coffeescript global offset
# note that this is gross
findPos = (obj) ->
values = while (obj = obj.offsetParent)
[obj.offsetLeft, obj.offsetTop]
_.reduce(values, (sums, pair) ->
left: sums.left + pair[0]
right: sums.right + pair[1]
left: 0, top: 0)
#!/usr/bin/env ruby
out_path = ARGV[0]
in_path = ARGV[1]
glob = "#{in_path}/**/*.coffee"
cmd = "coffee -o #{out_path} -c #{in_path}"
current_mtime = Time.now
arr = [[{:name=>"one", :enabled=>true},
{:name=>"two", :enabled=>false}],
[{:name=>"one", :enabled=>true},
{:name=>"two", :enabled=>true}]
]
a = arr.flatten.inject(Hash.new(true)) do |result, element|
result[element[:name]] &&= element[:enabled]
result
module Instantizable
def instantize(name)
klass = self
define_method(name) do |*args, &block|
klass.send(name, self, *args, &block)
end
end
end
# Test the module with a normal method, a method with a hash arg, and a method with a block.