This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/bin/src/node $ coffee -pe "x: [0..10]" | |
(function() { | |
var _a, _b; | |
{ | |
x: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
}; | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/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); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~ $ coffee -pe "a: 3" | |
(function() { | |
{ | |
a: 3 | |
}; | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~ $ cat > test.coffee | |
a: 3 | |
b: 4 | |
c: a + b | |
~ $ coffee -p test.coffee | |
(function() { | |
{ | |
a: 3, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.each carousels, -> | |
carousel = $(this) | |
carousels.each -> | |
carousel = $(this) | |
# or abstract it out | |
$.fn.each_j = (callback) -> | |
this.each (i) -> | |
callback.call this, i, $(this) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
OlderNewer