Skip to content

Instantly share code, notes, and snippets.

@khankuan
khankuan / gist:db4e05a24b7becc9d512
Created July 16, 2015 04:44
Understanding Flux
1) Stores
- Stores can be specific to a domain (ProductStore, ShoppingCartStore)
- Stores can be specific to a view (esp pages, like PopularProductPageStore)
- Emit events, in 99% of the time only 'change' events, in special very rare case we need to use other event types.
- Contains a single immutable map/single object as its data
- Should only be concerned on storage kind of logic (meaning no API calls here)
2) Views (Components)
- Contains no application state
- Should only contain transient states (states that can be lost, like if you the tab's position or don't need to programatically change the tab position, then view can store the tab position instead of having it in the stores)
@khankuan
khankuan / gist:b2035f76dfa1374e9d9b
Created April 28, 2015 18:37
Random gist for FB chat with Web Speech
/*
Commands:
/muteall
/unmuteall
/muteme
/unmuteme
/mute
/* Exports */
module.exports = function(opts){
var processFunction = opts.processFunction; // Returns a promise
var delay = opts.delay || 100;
var concurrency = opts.concurrency || 10;
var deleteIfFail = opts.deleteIfFail || false;
var queue = [];
var processing = false;
@khankuan
khankuan / volume-meter.js
Last active January 2, 2018 17:00
Volume Meter from audio tag or mediastream
var VolumeMeter = function(audioOrStream, shouldStillPlayAudio){
var _this = this;
var streamData = new Uint8Array(128);
window.VolumeMeterAudioContext = window.VolumeMeterAudioContext || new (window.AudioContext || window.webkitAudioContext);
this._audioCtx = window.VolumeMeterAudioContext;
this._analyser = this._audioCtx.createAnalyser();
this._analyser.fftSize = 256;
this._analyser.smoothingTimeConstant = 0.2;
@khankuan
khankuan / gist:11374276
Last active August 29, 2015 14:00
Linux AMI install node
cd /usr/local/share/
sudo wget http://nodejs.org/dist/v0.10.26/node-v0.10.26-linux-x64.tar.gz
sudo tar xvf node-v0.10.26-linux-x64.tar.gz
sudo rm -rf node-v0.10.26-linux-x64.tar.gz
sudo ln -s /usr/local/share/node-v0.10.26-linux-x64/bin/node /usr/local/share/node
@khankuan
khankuan / Javascript get user Google contacts
Created January 9, 2014 07:12
Javascript get user Google contacts
<script src="https://apis.google.com/js/client.js?onload=gapiLoad"></script>
<script>
function gapiLoad() {
gapi.client.setApiKey('YOUR_API_KEY'); // app api-wide client api key
getGoogleContactEmails(function(result){
console.log(result);
});
}
@khankuan
khankuan / SlideSeekBar
Created July 20, 2013 11:14
Custom SeekBar that changes based on tap and scroll. For scrolling, a factor can be set so that the scrolling the slider can vary at a slower or faster speed.
import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.SeekBar;
/**
* Created by khankuan on 20/7/13.
* This custom SeekBar changes the progress based on tap gesture and scroll gesture separately.