Skip to content

Instantly share code, notes, and snippets.

View khanghoang's full-sized avatar
😬

Khang Hoang khanghoang

😬
  • Dropbox
  • San Jose, CA
  • 14:59 (UTC -06:00)
  • X @khanght
View GitHub Profile
@khanghoang
khanghoang / eslint-flow-config
Created July 24, 2016 07:09
eslint-flow-config
{
"parser": "babel-eslint",
"plugins": [
"flowtype"
],
"rules": {
"flowtype/require-parameter-type": 1,
"flowtype/require-return-type": [
1,
"always",
@khanghoang
khanghoang / tmux-cheatsheet.markdown
Created June 22, 2016 06:39 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@khanghoang
khanghoang / mongodb-auth.txt
Created May 19, 2016 08:12 — forked from toan2406/mongodb-auth.txt
MongoDB authentication setting
docker run -v /datadir:/data/db --name mongo -d mongo --auth
docker exec -it mongo mongo
> use admin
> db.system.users.find()
> db.createUser({ user: 'admin', pwd: 'admin', roles: [ { role: "root", db: "admin" } ] });
> use some-db
> db.createUser({ user: 'user', pwd: 'user', roles: [ "readWrite" ] });
@khanghoang
khanghoang / 02-05-2016-some-thoughts-about-generators.md
Last active May 2, 2016 10:05
Some thoughts about Generators

Generators

The playground:

  • I've created a jsbin for you to play with Generators. In the practical project, you need to have either facebook-regenerator or babel-polyfill to run it.
    The playground

What is generator:

  • Generator's interface
interface Generator extends Iterator {
@khanghoang
khanghoang / optimization-webpack.md
Last active May 29, 2016 14:47
30-04-2016-Optimization Webpack

Webpack

At first glance

Know what you have in your pocket.

User webpack -json > tree.json to get all the information about your modules.
For visualization, put the tree.json to this https://webpack.github.io/analyse/#home
To parse those information to human-readable code, use this package https://github.com/robertknight/webpack-bundle-size-analyzer with its command webpack --json | webpack-bundle-size-analyzer

Minimize

To minimize your scripts (and your css, if you use the css-loader) webpack supports a simple option:

const initialLoadRequest = (dispatch) => {
const fetchForm = fetchLoginForm;
const sessionStatus = getSessionStatus;
return Promise.props({
form: (() => {
const loginFormAction = fetchForm();
dispatch(loginFormAction);
return loginFormAction.promise;
})(),
@khanghoang
khanghoang / parrallelPromises.js
Created April 19, 2016 15:30
parrallelPromises
export default function parrallelPromises (store) {
return next => action => {
const { parrallelPromises } = action;
if (!parrallelPromises) {
return next(action);
}
return Promise.props(parrallelPromises)
.then((results) => {
return store.dispatch(results);
@khanghoang
khanghoang / promise.js
Last active March 15, 2016 04:28
promise stuff
var Q = require('q');
var request = require('request');
var Promise = require('bluebird')
var numberOfArticle = 0;
function getArticleUrlPerPage(pageNumber, articleUrls) {
var options = {
method: 'GET',
url: 'https://www.getnewsmart.com/?last_time_title=This+week&page=' + pageNumber + '&section=&xhr=true',
};
@khanghoang
khanghoang / generateDOM-test.js
Last active February 27, 2016 10:48
GenerateDOM
var expect = require('chai').expect;
var jsdom = require('mocha-jsdom');
var generateDOM = require('../src/index');
describe('Generate', function() {
jsdom();
it('should render children nodes', function(){
var source = {
@khanghoang
khanghoang / slim-redux.js
Last active March 7, 2021 13:58 — forked from gaearon/slim-redux.js
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
// call fn() and re-assign it to results.
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {