Skip to content

Instantly share code, notes, and snippets.

@liammclennan
liammclennan / gist:997399
Created May 29, 2011 02:19
settings service
# settings file
development:
gateway: test
test:
gateway: jira
production:
gateway: jira
@liammclennan
liammclennan / gist:997613
Created May 29, 2011 09:44
Fizzbuzz in CoffeeScript
# a type representing a number, that can be mapped to a fizzbuzz output
class Value
constructor: (@number) ->
# calculate the correct output for the value of @number
map: () ->
if @_is_fizzbuzz()
return 'fizzbuzz'
if @_is_fizz()
return 'fizz'
@liammclennan
liammclennan / gist:997628
Created May 29, 2011 10:18
JavaScript Arrow Lambda Syntax
// from http://wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax
// Empty arrow function is minimal-length
let empty = ->;
let square = (x) -> x * x;
@liammclennan
liammclennan / gist:997632
Created May 29, 2011 10:22
JavaScript Block Lambda Syntax
// from http://wiki.ecmascript.org/doku.php?id=strawman:block_lambda_revival
let empty = {||};
let square = {|x| x * x};
@liammclennan
liammclennan / gist:1008729
Created June 5, 2011 07:16
CoffeeScript Hello World
alert = (message) ->
console.log message
language = "CoffeeScript"
message = "Hello #{language}"
output = (comment) ->
alert comment
@liammclennan
liammclennan / gist:1014146
Created June 8, 2011 10:09
Property Inspection In CoffeeScript
Object.prototype._properties = () ->
properties = ("#{key}=#{value}" for key,value of this when typeof value isnt 'function')
@liammclennan
liammclennan / gist:1014150
Created June 8, 2011 10:12
JavaScript Property Inspection
Object.prototype._properties = function() {
var properties = [];
for (p in this) {
if (typeof this[p] !== 'function') {
properties.push(p + "=" + this[p]);
}
}
return properties;
}
@liammclennan
liammclennan / gist:1086262
Created July 16, 2011 11:04
Dependency Injection with Require.js
a.coffee
define(['dep'], (dep) ->
(d) ->
d = d || dep
{ }
)
@liammclennan
liammclennan / gist:1086983
Created July 17, 2011 00:41
Directly resolving dependencies in JavaScript Modules
// I'm calling this an anti-pattern because you cannot test this module
// without also testing the 'fs' module or monkey patching the require function.
var fs = require('fs');
exports.myObject = {
action: function() {
return fs.read('foo');
}
@liammclennan
liammclennan / gist:1086987
Created July 17, 2011 00:48
Example JavaScript Module that supports dependency injection
// Module A.js
exports = function(dep1, dep2) {
dep1 = dep1 || require('dep1');
dep2 = dep2 || require('dep2');
return {
action: function() {
return dep1.foo() + dep2.bar();