Skip to content

Instantly share code, notes, and snippets.

@zhangchiqing
zhangchiqing / bulb.css
Created April 26, 2014 05:15
visible/hidden css pattern
// bulb is invisible without power
.bulb,
.bulb-inline,
.bulb-inline-block {
display: none;
}
// bulb is visible with power
.power .bulb { display: block; }
.power .bulb-inline { display: inline; }
@zhangchiqing
zhangchiqing / 0_reuse_code.js
Created August 22, 2014 13:54
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@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
@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 / 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: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 / 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 / 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 / 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 / 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) {