Skip to content

Instantly share code, notes, and snippets.

View jashkenas's full-sized avatar

Jeremy Ashkenas jashkenas

View GitHub Profile
<li>
The CoffeeScript REPL now remembers your history between sessions.
Just like a proper REPL should.
</li>
<li>
You can now use <tt>require</tt> in Node to load <tt>.coffee.md</tt>
Literate CoffeeScript files. In the browser,
<tt>text/literate-coffeescript</tt> script tags.
</li>
<li>
# MAC manipulators
alias random_mac='sudo ifconfig en0 ether `openssl rand -hex 6 | sed "s/\(..\)/\1:/g; s/.$//"`'
alias restore_mac='sudo ifconfig en0 ether YOUR_ORIGINAL_MAC_ADDRESS_GOES_HERE'
diff --git a/test/model.js b/test/model.js
index ba5e1eb..a6c5609 100644
--- a/test/model.js
+++ b/test/model.js
@@ -223,15 +223,16 @@ $(document).ready(function() {
equal(value, 'last');
});
- test("set falsy values in the correct order", 1, function() {
+ test("set falsy values in the correct order", 2, function() {
var intersect = function(a1, a2, b1, b2) {
var ua_t = (b2.x - b1.x) * (a1.y - b1.y) - (b2.y - b1.y) * (a1.x - b1.x);
var ub_t = (a2.x - a1.x) * (a1.y - b1.y) - (a2.y - a1.y) * (a1.x - b1.x);
var u_b = (b2.y - b1.y) * (a2.x - a1.x) - (b2.x - b1.x) * (a2.y - a1.y);
if ( u_b != 0 ) {
var ua = ua_t / u_b;
var ub = ub_t / u_b;
if ( 0 <= ua && ua <= 1 && 0 <= ub && ub <= 1 ) {
return {
x: a1.x + ua * (a2.x - a1.x),
@jashkenas
jashkenas / app.js
Created October 17, 2012 13:40
Quick Benchmark vs. Haml vs. ERB. vs. Slim (http://news.ycombinator.com/item?id=4663724)
var http = require('http');
var fs = require('fs');
var _ = require('underscore');
var items = {
"Headline 1": "Link1 Link2 Link3 Link4 Link5 Link6 Link7".split(' '),
"Headline 2": "Link1 Link2 Link3 Link4 Link5 Link6 Link7".split(' '),
"Headline 3": "Link1 Link2 Link3 Link4 Link5 Link6 Link7".split(' '),
"Headline 4": "Link1 Link2 Link3 Link4 Link5 Link6 Link7".split(' ')
};
new nytg.state_map("nytg-map-wrapper", {
width: 365,
height: 400,
county_data: {"state_id": "57957680",
"president": [{"candidates":[{"party":"AIP","cand_shortname":"Hoefling","votes_field":"25724358_20121106_votes","cand_longname":"Thomas Hoefling"},{"party":"PFP","cand_shortname":"Barr","votes_field":"25723334_20121106_votes","cand_longname":"Roseanne Barr"},{"party":"GRN","cand_shortname":"Stein","votes_field":"24959430_20121106_votes","cand_longname":"Jill Stein"},{"party":"REP","cand_shortname":"Romney","votes_field":"24951238_20121106_votes","cand_longname":"Mitt Romney"},{"party":"LIB","cand_shortname":"Johnson","votes_field":"24962502_20121106_votes","cand_longname":"Gary Johnson"},{"party":"DEM","cand_shortname":"Obama","votes_field":"24956358_20121106_votes","cand_longname":"Barack Obama"}],"county_votes":{"24951238_20121106_votes":[0,0,0,0,0,0,2568,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5379,0,0,0,15093,0,0,0,8574,0,0,0,0,23676,0,0,0
for (key in this.attrs) {
this[key] = function() {
return this.attrs[key];
};
}
#!/usr/bin/env ruby
cmds = []
cmds << "git co gh-pages"
cmds << "git merge master"
cmds << "git push github gh-pages"
cmds << "git co master"
system cmds.join("&&")

The Scope class regulates lexical scoping within CoffeeScript. As you generate code, you create a tree of scopes in the same shape as the nested function bodies. Each scope knows about the variables declared within it, and has a reference to its parent enclosing scope. In this way, we know which variables are new and need to be declared with var, and which are shared with the outside.

Import the helpers we plan to use.

{extend, last} = require './helpers'

#!/usr/bin/env ruby
cmds = []
cmds << "git add ."
cmds << "git add -u"
cmds << "git commit -m \"#{ARGV[0]}\""
cmds << "git pull"
cmds << "git push"
system cmds.join("&&")