Skip to content

Instantly share code, notes, and snippets.

View mrjjwright's full-sized avatar

John Wright mrjjwright

View GitHub Profile
git checkout -- lib
bin/cake build
TypeError: In src/helpers.coffee, Cannot call method 'compile' of undefined
at WhileNode.compile_node (/Users/johnw/js/coffee-script/lib/nodes.js:1551:29)
at WhileNode.compile (/Users/johnw/js/coffee-script/lib/nodes.js:82:21)
at Expressions.compile_expression (/Users/johnw/js/coffee-script/lib/nodes.js:367:28)
at Expressions.compile_node (/Users/johnw/js/coffee-script/lib/nodes.js:306:30)
at Expressions.compile_with_declarations (/Users/johnw/js/coffee-script/lib/nodes.js:352:19)
at CodeNode.compile_node (/Users/johnw/js/coffee-script/lib/nodes.js:1371:64)
at CodeNode.compile (/Users/johnw/js/coffee-script/lib/nodes.js:82:21)
@mrjjwright
mrjjwright / migrate_table.coffee
Created May 3, 2010 19:52
first is flow.js, 2nd is generated javascript from the third, which is proposed defer syntax in CoffeeScript
# Migrations
# -------------------------------------
# A handy utility for doing a SQLite table data or schema migration.
#
# If something goes wrong here at the wrong time,
# not that it will, I know you have a backup. :)
#
# First creates a temporary table and dumps all the rows from the old table.
# The old table is then dropped.
#
# this doesn't compile
# Error: In stdio, Parse error on line 1: Unexpected ','
foo: bar "x", 1
# this does
bar "x", 1
# so does this
foo: bar "x", "1"
@mrjjwright
mrjjwright / bindings_error.js
Created October 23, 2010 01:59
This code throws error
sqlite = require("sqlite")
db = new sqlite.Database()
db.open(":memory", function (err) {
db.execute("create table t1(x,y);", function (err) {
db.execute("insert into t1 values(?, ?)", ["hi", "hi"], function (err){
if (err) throw err;
});
});
});
foo (a) ->
if x? then y
# generates
# foo(function(a) {
# return (typeof x !== "undefined" && x !== null) ? y : undefined;
# });
# However, if you are checking for the existence of a param to the function, then no undefined check
foo (x) ->
if x? then y
@mrjjwright
mrjjwright / BackboneSyncJSON.js
Created October 28, 2010 23:29
plugin for Backbone that send the models as application/json encoded bodies
methodMap = {
'create': 'POST',
'update': 'PUT',
'delete': 'DELETE',
'read': 'GET'
};
getUrl = function(object) {
if (!(object && object.url)) {
throw new Error("A 'url' property or function must be specified");
} else {
#
# Override Backbone.sync
#
methodMap = {
'create': 'POST'
'update': 'PUT'
'delete': 'DELETE'
'read' : 'GET'
}
@mrjjwright
mrjjwright / mongo-install-err.txt
Created November 5, 2010 22:14
This happens on OSX 10.6.4
7/7] cxx_link: build/default/bson_1.o build/default/long_1.o build/default/objectid_1.o build/default/binary_1.o build/default/code_1.o build/default/dbref_1.o -> build/default/bson.node
Waf: Leaving directory `/Users/johnw/.node_modules/.npm/mongodb/0.8.1/package/external-libs/bson/build'
'build' finished successfully (0.799s)
The 'sys' module is now called 'util'. It should have a similar interface.
=== EXCEUTING TEST_BSON ===
Assertion failed: (handle->InternalFieldCount() > 0), function Unwrap, file src/node_object_wrap.h, line 30.
make[1]: *** [all] Abort trap
make: *** [build_native] Error 2
npm info mongodb@0.8.1 Failed to exec install script
npm ERR! install failed Error: mongodb@0.8.1 install: `make total`
@mrjjwright
mrjjwright / sha1_dir.coffee
Created December 14, 2010 22:15
Generate SHA-1 hashes on a directory of files in node.js quickly using openssl binary
# Uses the openssl too to generate sha1 hashes for files, returns them in a dictionary by relative path from root passed in
child_process = require "child_process"
path = require "path"
util = require "util"
PATH_TO_OPEN_SSL = "openssl"
CMD = "#{PATH_TO_OPEN_SSL} dgst -sha1"
generate = (dir, pattern, callback) ->
cmd = "#{CMD} #{pattern}"
@mrjjwright
mrjjwright / sha1_dir.coffee
Created December 14, 2010 22:15
Generate SHA-1 hashes on a directory of files in node.js quickly using openssl binary
# Uses the openssl tool to generate sha1 hashes for files, returns them in a dictionary by relative path from root passed in
child_process = require "child_process"
path = require "path"
util = require "util"
PATH_TO_OPEN_SSL = "openssl"
CMD = "#{PATH_TO_OPEN_SSL} dgst -sha1"
generate = (dir, pattern, callback) ->
cmd = "#{CMD} #{pattern}"