Skip to content

Instantly share code, notes, and snippets.

@hell0again
hell0again / gist:eca54a29a633c01b10c0
Last active August 29, 2015 14:05
promiseと読みやすさ
// 1. thenまで一気に書くとthen節の中身が入れ子状に並ぶ。関数呼び出しが先頭に並ぶので読みやすいというか見慣れた形
var filePath = "**/*.tpl";
fetchTemplateFileList(filePath).then(function(fileList) {
return Promise.all(_.map(fileList, function(filePath) {
return createHtmlTextFromTemplateFile(filePath).then(function(htmlText) {
return createTemplateTableFromHtmlText(htmlText).then(function(templateTable) {
return createModuleTextFromTemplateTable(templateTable).then(function(moduleText) {
return writeModuleFromText(moduleText, getOutFilePath(filePath)).then(function(result) {
console.log("wrote "+ getOutFilePath(filePath));
});
@hell0again
hell0again / gist:f9be720ef3cbf13c5520
Created August 21, 2014 04:45
はじめにdefineがあった。
`if (typeof define !== 'function') { var define = require('amdefine')(module) } // for node`
define [
], (
) ->
'use strict'
#
@hell0again
hell0again / 01.coffee
Last active August 29, 2015 14:05
Promise.deferを書いてたときにcoffeeの変数宣言で泣いた
# Promise.deferが欲しかったので適当に書いてみる
# @deferの先頭でresolve, rejectの変数宣言をしたかった
# we want Promise.defer!!
`if (typeof define !== 'function') { var define = require('amdefine')(module) } // for node`
define [
'es6-promise'
], (es6Promise) ->
'use strict'
class Promise extends es6Promise.Promise
@hell0again
hell0again / gist:a71c3152ba77c2b7e403
Created August 22, 2014 09:33
promise.catchでコールスタック
var promise = new Promise(function(resolve, reject) {
// ..
});
promise.then(function() {
// ..
}).catch(function(err, data) { // then内でErrorを吐く場合、catch必須。つまりcatch必須。
if (err) { // スタックトレース表示
console.log(err);
if (err.stack) {
console.log(err.stack.split('¥n').slice(2).join('¥n'));
@hell0again
hell0again / gist:e6c8606328f5925aa980
Created September 17, 2014 02:48
backboneでcomputedな属性を実現するためのpluginども

setterがあったりなかったりgetterへのdependsの渡し方ら辺で差が出てる。 人気なのはepoxyっぽいけどobjectではなくjsonで設定を渡すのがキモい。

使うかもしれない

おなまえ リポジトリ 小並感
backbone-computedfields https://github.com/alexanderbeletsky/backbone-computedfields Inspired by backbone.compute。get, set, dependsとかで定義。いま使ってる
@hell0again
hell0again / gist:ff20f437f28e4862db4a
Created December 5, 2014 11:53
自作yeomanテンプレートの使い方(cli-appの例)
$ cd git
$ mkdir mycommand; cd mycommand
$ npm init
$ npm install hell0again/generator-cli-app # <github username>/<github project>
$ yo # or yo cli-app
## yeamonに言われるがままにコマンド名を指定
## package.jsonは上書き。
## cli-appなら↓でコマンドを実行可能に。
$ npm install -g コマンド名
@hell0again
hell0again / gist:72a1ae6918f3261c9bf1
Created January 26, 2015 11:43
minify差分のdiffをみる
git diff > df
grep '^-' df | sed -e 's/\s/\n/g' > g.diff.a
grep '^+' df | sed -e 's/\s/\n/g' > g.diff.b
git diff --color --no-index -- g.diff.{a,b}
@hell0again
hell0again / gist:bdbef768361411b1d6c0
Created February 5, 2015 06:00
デバッガあれこれ

perl

perl -d file.pl
  • ブレークポイント文は $DB::single = 1

実行関連

@hell0again
hell0again / main.out
Created February 19, 2015 02:25
シェルスクリプトでテンプレートエンジン的な
I am template.
lang: ja_JP.UTF-8
key1: val1
key2: val2
key3:
key4: UNDEF
@hell0again
hell0again / gist:121b36388e9ef849f756
Created February 20, 2015 01:59
source実行時の環境変数をカレントシェルにexport奴
## 指定した名前の変数の値を得る
value_of() {
name=$1
eval echo "\${${name}}"
}
## 変数が定義済みかチェックする
## source内でexitするとシェルごとexitするよ
is_defined() {
name=$1