Skip to content

Instantly share code, notes, and snippets.

View mofas's full-sized avatar

Chung Yen Li mofas

View GitHub Profile
package patmat
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import patmat.Huffman._
@RunWith(classOf[JUnitRunner])
object InsertionSort{
def sort(xs : List[Int]): List[Int] = {
def insert(sorted : List[Int], e : Int)= {
sorted.takeWhile( x => (x < e)) ++ List(e) ++ sorted.dropWhile( x => (x < e))
}
xs.foldLeft(List[Int]()) { (sorted, e) => insert(sorted, e) }
}
}
INSERT INTO app (appID, appType, partnerID) SELECT distinct(appID), appType, partnerID FROM performance WHERE appID IN( SELECT distinct(appID) FROM performance AS ip WHERE date='2014-08-13' AND NOT EXISTS (SELECT appID FROM app AS ia WHERE ip.appID = ia.appID) AND ip.appID IS NOT NULL AND ip.appID != '') LIMIT 1000;
function queryStringMapping(){
var paramStr = window.location.href.split("?")[1].split("&");
var paramsMap = new Object() , key , value;
for(var i in paramStr){
key = paramStr[i].split("=")[0];
value = decodeURI(paramStr[i].split("=")[1]);
paramsMap[key] = value;
}
return paramsMap;
}
@mofas
mofas / reverse.js
Created May 16, 2015 14:36
String reverse
String.prototype.reverse = function(){
var m = this.length >> 1,
f = this.substring(0,m),
t = this.substring(m,this.length);
return m == 0 ? t : this.reverse.apply(t) + this.reverse.apply(f);
}
@mofas
mofas / transducer-derive.js
Last active December 11, 2015 07:59
Show how transducer work.
//We have an array, and we want to modify it to get new value.
const arr = [1, 2, 3];
//f1, f2, f3 are some variable functions will apply to our arr.
const f1 = (x) => x+1;
const f2 = (x) => x*2;
const f3 = (x) => x*x;
// We usually evaluate functions one by one by mapping to get our final answer.
const res1 = arr.map(f1).map(f2).map(f3);
@mofas
mofas / test.js
Created March 25, 2016 16:46
Codemod: Replace React.addons.PureRenderMixin to PureRenderMixin
{
mixins: [React.addons.OtherMixin, React.OtherMixin, CampaignMixin, React.addons.PureRenderMixin]
}
@mofas
mofas / test.js
Last active March 25, 2016 16:48
Codemod: Replace react/addons to react
import React from 'react/addons';
import Immutable from 'immutable';
import classnames from 'classnames';
@mofas
mofas / test.js
Created March 26, 2016 09:37
CodeMod: remove refs.getDOMNode() expression
var getDOMNode = 123;
const getDOMNode = () => {
return this.refs;
}
var test = getDOMNode();
getOffset(this.refs.root.getDOMNode());
this.refs.presetMenu.getDOMNode();
@mofas
mofas / test.js
Last active March 26, 2016 12:29
CodeMod: remove const {PureRenderMixin} = React.addons;
let React = {};
React.addons = {
PureRenderMixin: null,
};
const {PureRenderMixin} = React.addons;
const {a, b} = React.addons;