Skip to content

Instantly share code, notes, and snippets.

View sdtsui's full-sized avatar

Daniel Tsui sdtsui

View GitHub Profile
var reduceRight = function(array, iterator, accumulator){
var i = (accumulator === undefined) ? array.length-2 : array.length-1;
var accumulator = (accumulator === undefined) ? array[array.length-1] : accumulator;
for (; i>=0; i--){
accumulator = iterator(accumulator, array[i]);
}
return accumulator;
};
@sdtsui
sdtsui / inheritance
Created January 19, 2015 07:06
S18 - Inheritance
//Functional:
var SmartPhone = function(num, email){
var instance = {}
instance.number = num;
instance.email = email;
instance.method1 = function(){};
instance.method2 = function(){};
instance.method3 = function(){};
return instance;
}
@sdtsui
sdtsui / hasDupTC
Created January 19, 2015 07:27
S18 - hasDuplicates Time Complexity
var hasDuplicates = function(array){
for(var i = 0; i < array.length; i++){
var item = array[i];
if(array.slice(i+1).indexOf(item) !== -1){
return true;
}
}
return false;
};
/*
@sdtsui
sdtsui / coffee-fundamentals
Created January 19, 2015 07:46
CoffeeScript-patterns
#Function:
square = (x) -> x*x
#Array:
list = [1,2,3,4,5]
#Splicing:
list[2..4] =['injected', 'some', 'stuff']
#While loops
doSomething() while someCondition
#Concatenating Strings without + Operator
#Block strings, expression evals to string
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.7.2/immutable.min.js"></script>
<script type="text/javascript">
console.log('IM :', Immutable);
var IM = Immutable;
var array = IM.List(["totally", "immutable", {hammer: "Can’t Touch This"}]);
console.log(array.get(1)); //immutable
array.get(2).hammer = "hm, surely I can mutate this nested object..."
console.log(array.get(2).hammer); //"hm, ...'
@sdtsui
sdtsui / RBNode.es6
Created May 25, 2015 14:00
Static Get for RBTree
//RBNode.es6
const IM = require('immutable');
let BSTNode = require('./BSTNode');
export class RBNode extends BSTNode {
constructor(key, value, left, right, id, color = 0) {
super(key, value, left, right, id, true);
this.color = (!!color) ? RBNode.B : RBNode.R;
@sdtsui
sdtsui / gist:1761ed61e023144719c0
Created June 26, 2015 17:11
flipTable random notes
some pseudocode, i have some questions about how the tree will work.
probs@HR late
____________________
Store all of the elements in an immutable tree.
HTML5 deviceOrientation:
window.addEventListener('deviceMoveEvent??'), function(e){
@sdtsui
sdtsui / vimeoSpeed.js
Created September 14, 2015 23:15
vimeoSpeed
var vid = document.querySelector(".video");
vid.playbackRate = 2;
@sdtsui
sdtsui / om-next-david-nolen.md
Created January 12, 2016 22:14
om-next-david-nolen.md

David Nolen Talk - Om Next.

Preface: This is a riff on "The Language of the System" by Rich Hickey Problem Statements:

  1. Client Sever communication is ad-hoc (how)
  2. C/S communication requires a lot of out-of-band information ( what - read AWS docs)
  3. React render model makes moving up/across the UI tree tricky

Assumptions:

  1. Single-atom app state is good