Skip to content

Instantly share code, notes, and snippets.

View kdepp's full-sized avatar
🏠
Working from home

CuteRat kdepp

🏠
Working from home
View GitHub Profile
@kdepp
kdepp / longStackTrace (Yaku vs Bluebird)
Last active August 29, 2015 14:22
longStackTrace (Yaku vs Bluebird)
Promise_Yaku = require 'yaku'
Promise_Bird = require 'bluebird'
Promise_Yaku.enableLongStackTrace()
Promise_Bird.longStackTraces()
test = (Promise) ->
foo = -> Promise.reject "not catched"
Promise.resolve()
Promise_Yaku = require 'yaku'
Promise_Bird = require 'bluebird'
Promise_Yaku.enableLongStackTrace()
Promise_Bird.longStackTraces()
test = (Promise) ->
bar = -> JSON.parse('edf{23}')
Promise.resolve()
@kdepp
kdepp / sec.md
Last active May 14, 2016 14:42
Intro to Semantic Editor Combinators (for js users)

学会了 Semantic Editor Combinators,你不一定真的需要Immutable.js

只是想轻一些

首先声明,绝不否认 Immutable.js 的作用,以及如果语言自身支持 immutable 的好处。

本文想说的是,大部分时间我们需要的不是对数据的封装,而是一个快速修改嵌套结构数据并返回新对象的方法。

和 Immutable.js 借鉴自 FP 一样,这里要说的方案 (SEC,Semantic Editor Combinators) 也是借鉴在之前的大牛在 FP 中的思考。

对比

@kdepp
kdepp / tty_qr.py
Created September 7, 2016 07:26
Print QRCode in Terminal
from PIL import Image
import sys, os
QR_DIR = '.'
try:
b = u'\u2588'
sys.stdout.write(b + '\r')
sys.stdout.flush()
except UnicodeEncodeError:
BLOCK = 'MM'
@kdepp
kdepp / gist:05c0f1029e67fe3b8ac13740a0771bed
Created December 6, 2016 01:25
benchmark - time cps - OS X 10.10.5 - GHC 7.8.3
2016-12-06 01:19:40.00319 UTC
2016-12-06 01:19:40.030091 UTC
2016-12-06 01:19:40.032538 UTC
2016-12-06 01:19:40.032581 UTC
2016-12-06 09:19:40.034801 CST
2016-12-06 09:19:40.035805 CST
"Tue, 6 Dec 2016 01:19:40 UTC"
"Tue, 6 Dec 2016 09:19:40 CST"
"Tue, 6 Dec 2016 09:19:40 "
"Tue, 6 Dec 2016 01:19:40 UTC"
@kdepp
kdepp / gist:1db8787aa44bf80c8780693880133f1b
Created December 6, 2016 03:33
benchmark - time cps - OS X 10.10.5 - GHC 7.8.3 - time 1.7
2016-12-06 03:29:15.940822 UTC
2016-12-06 03:29:15.963588 UTC
2016-12-06 03:29:15.969227 UTC
2016-12-06 03:29:15.969314 UTC
2016-12-06 11:29:15.971724 CST
2016-12-06 11:29:15.973697 CST
"Tue, 6 Dec 2016 03:29:15 UTC"
"Tue, 6 Dec 2016 11:29:15 CST"
"Tue, 6 Dec 2016 11:29:15 "
"Tue, 6 Dec 2016 03:29:15 UTC"
@kdepp
kdepp / solve.js
Created January 25, 2017 15:11
coin change
function recurSolve(sum, coins) {
var coins = coins.slice().sort(function (a, b) { return b - a; });
console.log(coins);
var go = function (sum, coins) {
if (sum === 0) return 1;
if (coins.length === 0 || sum < 0) return 0;
return go(sum - coins[0], coins) + go(sum, coins.slice(1));
};
return go(sum, coins);
@kdepp
kdepp / install_eslint.sh
Created June 29, 2017 03:07
npm install eslint relavent bundle
#!/bin/sh
npm install --save-dev babel-eslint eslint eslint-config-standard eslint-plugin-html eslint-plugin-import eslint-plugin-node eslint-plugin-promise eslint-plugin-standard
// Old
const result = await rp(options)
if (!result.ok) {
console.error("The request was not ok: " + JSON.stringify(result));
return response.header("Location", `https://us-central1-teamsync-working-v2.firebaseapp.com`).send(302);
}
await admin.database().ref("installations").child(result.team_id).set({
token: result.access_token,
team: result.team_id,
@kdepp
kdepp / b.js
Last active January 31, 2018 02:53
withAccessToken
const getAccessToken = () => {
const pGetToken = db ? getAccessTokenFromDB() : Promise.resolve()
return pGetToken.then(token => {
if (token) return token
return getAccessTokenFromRemote()
.then(data => {
if (!data || !data.access_token) {
throw new Error('No access token in token api response')