Skip to content

Instantly share code, notes, and snippets.

@robkuz
robkuz / curried.coffee
Created April 9, 2012 06:20
curried functions
foo = (param1)->
(param2)->
param1 + param2
foo(1)(2)
@robkuz
robkuz / overengineering.coffee
Created March 5, 2012 16:22
Over engineering
# very simple, very clear. If need to be changed, changes in two places
func: (data)=>
if data.x % @TILE_SIZE == 0
@x = Math.floor(data.x / @TILE_SIZE)
if data.y % @TILE_SIZE == 0
@y = Math.floor(data.y / @TILE_SIZE)
# easier to change BUT intention not so clear anymore
# and also longer and took longer to write
func: (data)=>
class Grid
@new: (x, y = 1, dval = 0)->
item = new Grid x, y, dval
(x, y) ->
(value) ->
v = value()
if v is undefined
return item.grid[x][y]
else
item.grid[x][y] = v
get = "get"
set = (value) -> value
class Grid
@new: (x, y, val = 0)->
item = new Grid x, y, val
(x, y) ->
(value) ->
if value == get
return item.grid[x][y]
{
...
"version": "0.4.0",
...
"bin" :
{
"cap" : "./bin/cap.js",
"ccap": "./bin/ccap.js",
"dcap": "./bin/dcap.js",
"coffee": "./bin/dcap.js"
{
...
"version": "0.3.0",
...
"bin" :
{
"cap" : "./bin/cap.js",
"ccap": "./bin/ccap.js",
"dcap": "./bin/dcap.js"
}
{
"author": "robert kuzelj <robert@capitalize.org>",
"name": "capitalize",
"description": "capitalizes and decapitalizes a string",
"version": "0.3.0",
"homepage": "www.capitalize.org",
"repository":
{
"url": ""
},
#!/usr/bin/env node
var capitalize = require("../main.js");
var value = process.argv[2];
console.log(capitalize.decapitalize(value));
#!/usr/bin/env node
var capitalize = require("../main.js");
var value = process.argv[2];
console.log(capitalize.capitalize(value));
@robkuz
robkuz / cap.js
Created December 14, 2011 13:39
command line tool
#!/usr/bin/env node
var capitalize = require("../main.js");
var action = process.argv[2];
var value = process.argv[3];
if (action == "-c")
{
console.log(capitalize.capitalize(value));
}