Skip to content

Instantly share code, notes, and snippets.

View marocchino's full-sized avatar
🏠
Working from home (7am~16pm JST)

marocchino

🏠
Working from home (7am~16pm JST)
View GitHub Profile
Function.prototype.intercept = function(callback) {
var underlyingObservable = this;
return ko.dependentObservable({
read: underlyingObservable,
write: function(value) { callback.call(underlyingObservable, value) }
});
};
viewModel.lastName = ko.observable("some initial value").intercept(function(value) {
// Only accepts strings of length < 20
#model
class Week < ActiveRecord::Base
def weeks=(weeks)
self.week = weeks.reject(&:blank?) * ","
end
def weeks
self.week.split(",")
end
@marocchino
marocchino / jsconf-eu-2011.md
Created October 10, 2011 05:18 — forked from mattpodwysocki/jsconf-eu-2011.md
JSConf.EU Slides
@marocchino
marocchino / gist:1274923
Created October 10, 2011 09:08
switch cast より{}[]の方が読みやすいけど…
//before
switch(action) {
case: "new"
return "create";
case: "edit"
return "update";
default:
return "unknown";
};
/**
@author: A.J <[email protected]>
@date: 2011-10-11
@version: 0.1
@param {Array} arr
@return Object
*/
var arr = ["a", "b", "c", "d", "e"];
function objectify( arr ) {
@marocchino
marocchino / gist:1305972
Created October 22, 2011 13:01
nodejs - simple calculator server
sys = require 'sys'
http = require 'http'
host = "0.0.0.0"
port = 3000
http.createServer (request,response) ->
[_, op, a, b] = request.url.split "/"
a = parseInt a
b = parseInt b
result = {
"add": (a, b) -> a + b
#ruby-1.9.2-p290
e = [*1..9].each # => #<Enumerator: [1, 2, 3, 4, 5, 6, 7, 8, 9]:each>
e.next # => 1
e.next # => 2
e.rewind # => #<Enumerator: [1, 2, 3, 4, 5, 6, 7, 8, 9]:each>
e.next # => 1
@marocchino
marocchino / gist:1363961
Created November 14, 2011 13:34
왜 통과를 못할까? 뭔가 잘못했나?;;
vows = require 'vows'
assert = require 'assert'
#Document = require('../../models/document')
## model ##
mongoose = require 'mongoose'
Schema = mongoose.Schema
ObjectId = Schema.ObjectId
db = mongoose.connect 'mongodb://localhost:27017/notepad'
DocumentSchema = new Schema
@marocchino
marocchino / gist:1370343
Created November 16, 2011 15:26 — forked from codian/gist:1369486
alias_method_chain quiz
require 'test/unit'
require 'rubygems'
gem 'activesupport'
require 'active_support/core_ext/module'
class Original
def hello
"Original"
end
end
@marocchino
marocchino / gist:1370395
Created November 16, 2011 15:41 — forked from yepp4you/gist:1369990
아아 이 어색함을 어쩔꼬 -_-);
vows = require 'vows'
assert = require 'assert'
tobi = require 'tobi'
vows.describe('Root').addBatch
'브라우저에서':
topic: -> tobi.createBrowser 3000, 'localhost'
'GET /의':
topic: (topic) ->
topic.get "/", @callback.bind(@, null)