Skip to content

Instantly share code, notes, and snippets.

@marty-wang
marty-wang / action.ts
Created March 28, 2018 21:40
strongly typed action handler and dispatcher
import { Store } from 'src/store';
type TagWithKey<TagName extends string, T> = { [K in keyof T]: { [_ in TagName]: K } & { params: T[K] } };
type Unionize<T> = T[keyof T];
type ActionHandlers<TParams, TParamsKey extends keyof TParams> = {
[Key in TParamsKey]: (params: TParams[Key]) => void
};
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.brv branch -vv
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.fix commit --amend
git config --global alias.pr pull --rebase
// always rebase for pull
git config --global branch.autosetuprebase always
@marty-wang
marty-wang / compose function
Created July 5, 2016 04:24
Very small compose function
const compose = (...fns) => (...args) => fns.reduceRight((input, fn) => fn.apply(null, [].concat(input)), args)
const combine = (...args) => args.join(" ")
const shout = (x) => x.toUpperCase()
const emphasize = (x) => `${x}!`
const yell = compose(emphasize, shout, combine)
console.log(yell("hello", "world")); // "HELLO WORLD!"
@marty-wang
marty-wang / Curry function
Created July 5, 2016 03:59
Very small curry function
function curry(fn) {
return (...args) => {
if (args.length >= fn.length) {
return fn.apply(null, args)
}
return function internal(...args1) {
args = args.concat(args1)
if (args.length >= fn.length) {
@marty-wang
marty-wang / AAD
Last active April 30, 2016 05:58
function createContext (config, onLoginError) {
var defaultConfig = {
postLogoutRedirectUri: window.location.origin,
};
var finalConfig = Object.keys(config).reduce(function(configCopy, curKey) {
configCopy[curKey] = config[curKey];
return configCopy;
}, defaultConfig);
var authContext = new AuthenticationContext(finalConfig);
@marty-wang
marty-wang / gist:5a71e9d0a6a2c6d6263c
Last active June 27, 2024 13:34
Compile and deploy React Native Android app of Release version to device.
Disclaimer: The instructions are the collective efforts from a few places online.
Nothing here is my original. But I want to put them together in one place to save people from spending the same time as I did.
First off, bundle.
==================
1. cd to the project directory
2. Start the react-native packager if not started
3. Download the bundle to the asset folder:
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
@marty-wang
marty-wang / sinon_mocha_test_async_multi_callbacks.coffee
Created November 24, 2011 22:53
Use SinonJS and Mocha to test async function of multiple callbacks
should = require 'should'
sinon = require 'sinon'
myModule = {}
myModule.asyncMethod = (callback) ->
timeout = 1000
setTimeout (->
process.nextTick ->
@marty-wang
marty-wang / sinon_fake_tick.coffee
Created November 16, 2011 22:55
Use SinonJS to test async functions using process.nextTick
vows = require 'vows'
should = require 'should'
sinon = require 'sinon'
class FakeTicker
constructor: ->
@_originalTick = process.nextTick
sinon
.stub(process, 'nextTick', (callback)->
setTimeout (->