This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 今は設定値にして、環境別に値を変えている | |
# 'development' or 'apache' or 'nginx' | |
WEB_SERVER = 'development' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
constructor (arg1, arg2): | |
class Bar extends Foo | |
constructor (args...): | |
super args... # Call super() with all args | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Clear all data in localStorage about some model class. | |
@clearLocalStorage = (modelClass) -> | |
# Must create a model instance for to sync localStorage.records. | |
# (But is also a target that you want to delete it! | |
# Backbone.LocalStorage is not good so much...) | |
accessor = new modelClass | |
for modelAttrs in accessor.localStorage.findAll() | |
target = new modelClass(id: modelAttrs.id) | |
accessor.localStorage.destroy target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Search real event emitter from `event.target`. | |
# | |
# e.g. | |
# $('<div class="setter"><div><span>Button</span></div></div>') | |
# .click (event) -> | |
# $emitter = findEventEmitterElement(event.target, '.setter:first') | |
@findEventEmitterElement = (eventTarget, selector) -> | |
$target = $(eventTarget).parents(selector) | |
if $target.length is 1 | |
$target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Timerクラスからは以下を分離したい | |
// | |
// - setTimeout/clearTimeout の実行 | |
// - new Date の実行 | |
// | |
var timer = new Timer(); | |
// タスクを登録。'タスクID', インターバル(ms), コールバック |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = require("util"); | |
var inspect = function(obj, depth){ | |
depth = depth || 0; | |
console.log(util.inspect(obj, false, depth)); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Choice randomly according to ratios | |
# | |
# e.g. | |
# | |
# ratioMap=[[1.0, 'x'], [2.0, 'y'], [3.0, 'z']] | |
# -> x=1/6, y=2/6, z=3/6 | |
# | |
# Can also write like this: | |
# ratioMap={ x:1.0, y:2.0, z:3.0 } | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func = ({foo:x, bar:y}) -> console.log x, y | |
func({foo:1, bar:2}) # -> "1 2" | |
func = ([a, b]) -> console.log a, b | |
func([3, 4]) # -> "3 4" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# RSpec の動作確認 | |
# | |
shared_context '_dummy' do | |
# letは遅延評価で値をキャッシュする | |
let(:some_value) { 'Some value' } | |
end | |
shared_context '_create_rspec_test_user' do | |
User.create!(name: 'RSpec test user') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def proc_return | |
Proc.new { return "In Proc.new" }.call | |
return "proc_return method finished" | |
end | |
def lambda_return | |
lambda { return "In lambda" }.call | |
return "lambda_return method finished" | |
end |
OlderNewer