Skip to content

Instantly share code, notes, and snippets.

Shunsuke Watanabe craftgear

Block or report user

Report or block craftgear

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@craftgear
craftgear / beyond_for_loop.js
Last active Oct 6, 2018
#SurviveJS 05 LT「forループを越えて」
View beyond_for_loop.js
const double = x => x * 2;
const over5 = x => x > 5;
const a = [1, 2, 3].map(double).filter(over5);
console.log('********* a', a);
import * as R from 'ramda';
const times2Over5 = R.compose(
R.tap(console.log),
@craftgear
craftgear / dummy_todos.json
Last active Aug 12, 2018
dummy_todos.json
View dummy_todos.json
{
"data": [
{
"id": 1,
"title": "Reactコンポーネントを作れるようになる",
"done": false,
"created_at": "2018-08-08 12:00:00",
"started_at": "",
"done_at":""
},
@craftgear
craftgear / permutate.js
Last active May 14, 2018
Permutation with recursion
View permutate.js
const insertItem = (xs, index, item) => [...xs.slice(0, index), item, ...xs.slice(index)];
const range = number => [...Array(number).keys()];
const permutate = (xs, accum = []) => {
const [head, ...tail] = xs;
if (!head) {
return accum;
}
return accum.length === 0
@craftgear
craftgear / pad.js
Last active Nov 25, 2017
leftPad, rightPad, oh whatever.
View pad.js
const pad = (leftOrRight = 'left') => maxLength => char => value => {
const strValue = typeof value === 'number' ? value.toString() : value;
if (strValue.length >= maxLength) {
return strValue;
}
if (typeof maxLength !== 'number') {
throw new Error('maxLength should be a number');
}
const padding = Array(maxLength - strValue.length)
@craftgear
craftgear / splitByRegexp.go
Last active Nov 20, 2017
split a string into a slice of strings by regexp (goで正規表現を使って文字列を分割する)
View splitByRegexp.go
func splitByRegexp(str string, separator string) []string {
normalRe := "[^%s]*[%s]"
rawRe := `[^%s]*[%s]`
var re *regexp.Regexp
if strings.Index(separator, `\\`) > -1 {
re = regexp.MustCompile(fmt.Sprintf(normalRe, separator, separator))
} else {
re = regexp.MustCompile(fmt.Sprintf(rawRe, separator, separator))
}
View go-ish_error_handling-3.js
async (callback) => {
const { err, ...result } = await asyncCode().catch(e => ({ err: e }));
if (err) {
callback(err);
return;
}
callback(null, result);
};
View go-ish_error_handling-2.js
async (callback) => {
try {
const result = await asyncCode();
callback(null, result)
}
catch (e) {
callback(e)
}
}
View go-ish_error_handling-1.js
async (callback) => {
const result = await asyncCode();
callback(null, result)
}
@craftgear
craftgear / gist:5669101
Last active Dec 17, 2015
expressでミドルウェアもしくはイベントハンドラでセッションの値を参照する
View gist:5669101
//ミドルウェアでやる場合
app.configure(function(){
//・・・(略)・・・
app.use(function (req, res, next) {
app.locals.message = req.session.message;
next();
});
//・・・(略)・・・
});
View jadewatch.coffee
# run with 'coffee jadewatch.coffee dirname'
fs = require 'fs'
if process.argv.length < 3
console.log 'Aborted: arguments are too short.'
return
else
child_process = require('child_process')
child_process.exec "ps", (err,stdout,stderr)->
if stdout.indexOf("coffee jadewatch.coffee") < 0
You can’t perform that action at this time.