Skip to content

Instantly share code, notes, and snippets.

@zhangchiqing
zhangchiqing / applyMerge2.js
Last active December 29, 2015 14:52
Ramda.applyMerge2
var R = require('ramda');
R.compose(
R.apply(R.add),
R.ap([R.add(3), R.multiply(100)])
)([5]); // 508
// applyMerge2 :: (a -> b) -> (a -> b) -> (b -> c) -> ([a] -> c)
var applyMerge2 = function(f1, f2, fmerge) {
@zhangchiqing
zhangchiqing / add.js
Last active November 29, 2015 15:11
add.js
/*
* Provide the implementations for 3 `add` functions to output the same value as commented
* without using if-else or switch-case
*/
var num = 1;
var add = function(n) {
// to implement
};
var addNum = add(num);
addNum(2);
@zhangchiqing
zhangchiqing / traverse.js
Last active November 9, 2015 20:08
Iterate over all mongo documents in a collection
var mongo = require('mongodb');
var config = {
host: 'localhost',
port: '27017',
db: 'local',
};
var getDBAsync = function(config) {
return new Promise(function(resolve, reject) {
@zhangchiqing
zhangchiqing / randomInt.js
Created November 9, 2015 19:56
Random Int in Pointfree style
var R = require('ramda');
// Int -> Int
var nextRandomInt = R.pipe(R.converge(R.multiply, [R.identity, Math.random]), Math.floor);
// nextRandomInt(2)
// => 1
// nextRandomInt(2)
// => 0
@zhangchiqing
zhangchiqing / zipObject.js
Last active August 29, 2015 14:26
Write a zipObject function
function zipObject() {
// write your code
}
zipObject('f')(1);
// => { f: 1 }
zipObject('method', 'url')('GET', 'https://api.github.com/users')
// => { method: 'GET', url: 'https://api.github.com/users' }
@zhangchiqing
zhangchiqing / gist:6648efc14a0daadb8d45
Created June 14, 2015 00:37
Use Ctrl+F to maximize tmux panel

The following config let you use Ctrl+F to maximuze tmux panel. And Ctrl+F again to go back

bind -n C-f resize-pane -Z
@zhangchiqing
zhangchiqing / gist:92029564386c5b1a87c8
Last active August 29, 2015 14:22
Shortcut for `ls -l`

For zsh user, a useful shortcut for ls is alt + l. If you prefer using ls -l, you can find the configuration at ~/.oh-my-zsh/lib/key-bindings.zsh

With the following config, you can list your files and clear the screen by alt + l and alt + c without pressing Enter key!

bindkey -s '\el' 'ls -l\n'                               # [Esc-l] - run command: ls
bindkey -s '\ec' 'clear\n'                               # [Esc-c] - run command: clear
@zhangchiqing
zhangchiqing / echoHttpRequest.js
Last active August 29, 2015 14:22 — forked from Marak/echoHttpRequest.js
Echo HTTP requests
module['exports'] = function echoHttp (hook) {
hook.debug("Debug messages are sent to the debug console");
hook.debug(hook.params);
hook.debug(hook.req.path);
hook.debug(hook.req.method);
@zhangchiqing
zhangchiqing / gist:fa1f7be402f2bcb84398
Created November 5, 2014 18:19
Fork and patch npm moduels hosted on GitHub
```
"gulp-requirejs": "https://github.com/zhangchiqing/gulp-requirejs/tarball/master",
```
@zhangchiqing
zhangchiqing / easing.js
Last active August 29, 2015 14:08 — forked from gre/easing.js
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
// no easing, no acceleration
linear: function (t) { return t },
// accelerating from zero velocity
easeInQuad: function (t) { return t*t },
// decelerating to zero velocity