Skip to content

Instantly share code, notes, and snippets.

@marty-wang
marty-wang / action.ts
Created Mar 28, 2018
strongly typed action handler and dispatcher
View action.ts
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
};
View git config
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 Jul 5, 2016
Very small compose function
View 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 Jul 5, 2016
Very small curry function
View 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) {
View AAD
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 Jul 21, 2021
Compile and deploy React Native Android app of Release version to device.
View gist:5a71e9d0a6a2c6d6263c
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 Nov 24, 2011
Use SinonJS and Mocha to test async function of multiple callbacks
View sinon_mocha_test_async_multi_callbacks.coffee
should = require 'should'
sinon = require 'sinon'
myModule = {}
myModule.asyncMethod = (callback) ->
timeout = 1000
setTimeout (->
process.nextTick ->
@marty-wang
marty-wang / sinon_fake_tick.coffee
Created Nov 16, 2011
Use SinonJS to test async functions using process.nextTick
View sinon_fake_tick.coffee
vows = require 'vows'
should = require 'should'
sinon = require 'sinon'
class FakeTicker
constructor: ->
@_originalTick = process.nextTick
sinon
.stub(process, 'nextTick', (callback)->
setTimeout (->