Skip to content

Instantly share code, notes, and snippets.

View htchaan's full-sized avatar

htc htchaan

  • Hong Kong
View GitHub Profile
@htchaan
htchaan / toType.js
Created February 5, 2014 02:21
An improved version of the typeOf operator.
var toType = function(obj) {
return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase()
}
/**
* http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/
* toType({a: 4}); //"object"
* toType([1, 2, 3]); //"array"
* (function() {console.log(toType(arguments))})(); //arguments
* toType(new ReferenceError); //"error"
@htchaan
htchaan / returnExports.coffee
Created October 17, 2014 02:49
Uses Node, AMD or browser globals to create a module.
# https://github.com/umdjs/umd/blob/master/returnExportsGlobal.js
# Uses Node, AMD or browser globals to create a module.
# If you want something that will work in other stricter CommonJS environments,
# or if you need to create a circular dependency, see commonJsStrict.js
# Defines a module "returnExports" that depends another module called "b".
# Note that the name of the module is implied by the file name. It is best
# if the file name and the exported global have matching names.
@htchaan
htchaan / fixBrewFailedToUpdateTap.sh
Created October 21, 2015 17:02
Failed to update tap: caskroom/cask
brew untap caskroom/cask && brew update && brew cleanup --force -s && rm -rf "$(brew --cache)"' && brew tap caskroom/cask
@htchaan
htchaan / de.sh
Created October 31, 2015 02:47
Shorthand to docker exec
#!/bin/bash
function de() {
ssh -t -i "$DOCKER_CERT_PATH/id_rsa" -p 22 \
-l $(jq -r '.Driver.SSHUser' "$DOCKER_CERT_PATH/config.json") \
$(jq -r '.Driver.IPAddress' "$DOCKER_CERT_PATH/config.json") \
"docker exec $@"
}
@htchaan
htchaan / gcoa.sh
Created November 4, 2015 05:30
Git checkout all remote branches
#!/bin/bash
function gcoa() {(
UPSTREAM=${1:=origin}
IFS=$'\n'
for BRANCH in $(git branch -r); do
BRANCH=${BRANCH# }
[[ "$BRANCH" != $UPSTREAM* ]] && continue
BRANCH=${BRANCH#$UPSTREAM/}
[ "${BRANCH:0:4}" = 'HEAD' ] && continue
First render Props change State change Force update Unmount
getDefaultProps
getInitialState
componentWillMount
componentWillReceiveProps
shouldComponentUpdate
componentWillUpdate
render
componentDidMount
@htchaan
htchaan / join-gopro-clips.sh
Created April 13, 2017 17:47
join-gopro-clips.sh
#!/bin/sh
# example usage:
# . join-gopro-clips.sh /f/DCIM/111GOPRO/*574*MP4
# this will generate and execute a ffmpeg command:
# /cygdrive/c/ProgramData/chocolatey/bin/ffmpeg -i 'F:\DCIM\111GOPRO\GOPR0574.MP4' -filter_complex '[0:v]scale=-1:720[v0];[v0][0:a]concat=n=1:v=1:a=1[v][a]' -r 18 -pix_fmt yuv420p -map '[v]' -map '[a]' -vcodec libx264 -preset veryslow 'C:\Temp\GOPR0574.MP4'
#function join-gopro-clips() {
i=0
c=$(which ffmpeg)
/*
* Copyright (C) 2007-2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
/*
Copyright (c) 2011, Daniel Guerrero
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the