Skip to content

Instantly share code, notes, and snippets.

View tim-smart's full-sized avatar

Tim tim-smart

View GitHub Profile
fs: require 'fs'
path: require 'path'
process.mixin global, require 'sys'
APP_NAME: 'USO-Updater'
COFFEE_ARGS: ['--no-wrap', '-c']
BUILD_DIR: 'build'
SOURCE_DIR: 'src'
directoryWalker: (dir, callback, maxLevels, currentLevel, fromRoot) ->
exports.someMethod = function (arg1, arg2, callback) {
// Do this for safety's sake, people might accidentally send us an extra arg
arg1 = arguments[0];
arg2 = arguments[1];
callback = arguments[arguments.length - 1];
callback(null, 'win!');
};
directoryWalker: (dir, callback, maxLevels, currentLevel, fromRoot) ->
maxLevels: if 'number' is typeof maxLevels then maxLevels else 0
currentLevel: if 'number' is typeof currentLevel then currentLevel else 1
fromRoot: if 'string' is typeof fromRoot then fromRoot else ''
fs.readdir dir, (error, files) ->
if error then puts error.message
else files.forEach (file) ->
fs.stat path.join(dir, file), (error, stats) ->
return puts error.message if error
db.get('stuff', gotThatStuff);
function gotThatStuff (value) {
db.store('stuff', 1 + value, storedThatStuff);
};
function storedThatStuff() {
puts('Great success!');
}
var Test = function Test() {};
var temp = function Test() {};
temp.prototype = Array.prototype;
Test.prototype = new temp();
Test.prototype.constructor = Test;
// Prints "Test"
new Test().constructor.name;
var Post = function Post() {
ORM.prototype.constructor.apply(this, arguments);
};
Post.prototype = Object.create(ORM.prototype);
Post.belongsTo = ['article'];
Post.hasMany = ['comments'];
// Alternate name
var CoffeeScript = require('coffeescipt-compiler');
require.registerExtension('.coffee', function(async, source, asyncCallback) {
if (true === async)
asyncCallback(CoffeeScript.compile(source));
else
return CoffeeScript.compile(source);
});
test: {
bob: 123
fail: 'caching'
}
alert 'The $test is a $test.bob ${test}'
// This returns a Javascript string
require.registerExtension('.coffee', function(async, source, callback) {
return compileCoffee(source);
});
// True
require('coffee').test === 123;
// This returns a object
require.registerExtension('.mu', function(async, source, callback) {
var Wrapper, postToPastebin, wrapper;
// This is a concept for making a script wrapper with a userscript and pastebin.ca
Wrapper = function Wrapper(scriptId) {
this.id = scriptId;
return this;
};
// Will contain / contains the meta data
Wrapper.prototype.meta = null;