Skip to content

Instantly share code, notes, and snippets.

View khanghoang's full-sized avatar
😬

Khang Hoang khanghoang

😬
  • Dropbox
  • San Jose, CA
  • 00:32 (UTC -06:00)
  • X @khanght
View GitHub Profile
@khanghoang
khanghoang / README.md
Created August 5, 2016 15:07 — forked from ryansch/README.md
neovim + yadr
@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 / 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) => {
@khanghoang
khanghoang / Enum.es6.js
Created December 18, 2015 09:39 — forked from xmlking/Enum.es6.js
JavaScript Enums with ES6, Type Checking and Immutability
export class EnumSymbol {
sym = Symbol.for(name);
value: number;
description: string;
constructor(name: string, {value, description}) {
if(!Object.is(value, undefined)) this.value = value;
if(description) this.description = description;
@khanghoang
khanghoang / gist:33f002128da7f1a2fcf2
Created November 26, 2015 11:58 — forked from saetia/gist:1623487
Clean Install – OS X 10.11 El Capitan

OS X Preferences


most of these require logout/restart to take effect

# Enable character repeat on keydown
defaults write -g ApplePressAndHoldEnabled -bool false

# Set a shorter Delay until key repeat
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby

@kangax's ES6 quiz, explained

@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).

Here we go with the explanations:

Question 1:
(function(x, f = () => x) {
@khanghoang
khanghoang / protips.js
Created November 1, 2015 11:25 — forked from nolanlawson/protips.js
Promise protips - stuff I wish I had known when I started with Promises
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");
@khanghoang
khanghoang / multer-to-s3.js
Created October 22, 2015 10:58 — forked from adon-at-work/multer-to-s3.js
Sample File Upload From Multer to S3
var AWS = require('aws-sdk'),
fs = require('fs');
// http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html#Credentials_from_Disk
AWS.config.loadFromPath('./aws-config.json');
// assume you already have the S3 Bucket created, and it is called ierg4210-shopxx-photos
var photoBucket = new AWS.S3({params: {Bucket: 'ierg4210-shopxx-photos'}});
function uploadToS3(file, destFileName, callback) {