Skip to content

Instantly share code, notes, and snippets.

View cloudchen's full-sized avatar

Cloud Chen cloudchen

  • Shanghai, China
  • 16:33 (UTC +08:00)
View GitHub Profile
@cloudchen
cloudchen / setState.js
Created November 19, 2018 04:25
Overwrite React .setState()
setState(updatedState) {
super.setState((...rest) => {
const newState = typeof updatedState === 'function' ? updatedState(...rest) : updatedState;
//add something tricky
return newState;
});
}
@cloudchen
cloudchen / gist:b0102a20a6390a107d04
Created October 27, 2014 04:01
TroopJS - A brief review

#The good parts

  1. Declarative syntax for module instantiation works nice, especially for multiple modules that have no dependencies with each other
  2. AMD at framework level causes code more standard and stable for managing dependencies and exports
  3. Global message system (HUB) that ships with framework makes communication easier between different modules
  4. OO is supported well at framework level

#The bad parts

@cloudchen
cloudchen / check-unmerged-branch.sh
Last active May 22, 2020 09:24
check whether feature branches are fully merged into develop branch
#update remote info and prune all the remotes that are updated
git remote update -p
#check is there any unmerged commits (don't have to checkout local branch)
git branch --list -v -r --no-merged origin/develop origin/team/*/feature/*
#list unmerged commits of specific branch from preceding result
git log --oneline origin/develop..origin/team/name/feature/refactor
@cloudchen
cloudchen / no-cache-for-client-side-file.conf
Created August 31, 2013 15:09
Disable static file cache for Apache -- Useful for debug environment
<FilesMatch ".(html|htm|js|css|less)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</FilesMatch>
@cloudchen
cloudchen / .jshintrc
Created August 28, 2013 07:10
preferred jshint configuration for webpage project
{
"camelcase": true,
"curly": true,
"eqeqeq": true,
"es3": false,
"forin": false,
"immed": true,
"indent": false,
"latedef": "nofunc",
"newcap": true,
@cloudchen
cloudchen / autossh.sh
Created August 19, 2013 03:15
autossh wrapping remote ssh port forwarding
#Explanation of key parameters
#autossh -M<LocalListenPort> -f -q -N -R <RemoteIP>:<RemotePort>:<LocalIP>:<LocalPort> RemoteHost
#Example
#Forward local network port 22 of 10.128.42.134 to remote network port 7000 of 192.168.1.2 via ssh connection of example.org
autossh -M20000 -f -q -N -R 192.168.1.2:7000:10.128.42.134:22 example.org
#After connection is established by local network, you can run
#ssh -p 7000 192.168.1.2
#from remote network environment to connect 10.128.42.134:22
@cloudchen
cloudchen / oocss.css
Last active December 17, 2015 14:39
Simplified OOCSS definitions and some helpers
/*template.css*/
.main{display:table-cell;*display:block;width:auto;}
.row,.main{*zoom:1;}
.row:after,.main:after{clear:both;display:block;visibility:hidden;overflow:hidden;height:0 !important;line-height:0;font-size:xx-large;content:" x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x ";}
.page{margin:0 auto;width:950px;_text-align:left;} /* wraps other template elems to set width */ /* text-align IE5.5 */
.liquid{width:auto;margin:0;}
/* ====== Columns ====== */
.leftCol{float:left;width:250px;_margin-right:-3px;}
.rightCol{float:right;width:300px;_margin-left:-3px;}
@cloudchen
cloudchen / stringify.js
Created April 10, 2013 07:59
stringify javascript variable >> It's useful when you want write javascript variable into html template >> It's much better than JSON.stringify() since that doesn't support stringify function data type
function stringify(obj, variable) {
var objLiteral = '';
if (typeof obj == 'object') {
objLiteral += variable + "=";
if (obj.constructor == Array) {
objLiteral += "[];\n";
} else {
objLiteral += "{};\n";
}