Skip to content

Instantly share code, notes, and snippets.

View haoch's full-sized avatar
🎯
Focusing

Hao Chen haoch

🎯
Focusing
View GitHub Profile
@haoch
haoch / BayesianNetworks.py
Created February 20, 2014 16:52
Bayesian Networks
class JointProbabilityTable:
def __init__(self, columns, data):
self._columns = columns
self._probability_index = len(columns)
self._data = self._normalize(data)
def _normalize(self, data):
probability_sum = 0
for row in data:
probability_sum += row[-1]
for row in data:
@haoch
haoch / pig.udf.COUNT.java
Last active January 2, 2016 18:49
Pig UDF
public class COUNT extends EvalFunc<Long> implements Algebraic{
public Long exec(Tuple input) throws IOException {return count(input);}
public String getInitial() {return Initial.class.getName();}
public String getIntermed() {return Intermed.class.getName();}
public String getFinal() {return Final.class.getName();}
static public class Initial extends EvalFunc<Tuple> {
public Tuple exec(Tuple input) throws IOException {return TupleFactory.getInstance().newTuple(count(input));}
}
static public class Intermed extends EvalFunc<Tuple> {
public Tuple exec(Tuple input) throws IOException {return TupleFactory.getInstance().newTuple(sum(input));}
@haoch
haoch / HelloApp.sh
Created January 8, 2014 08:41
Scala Script
#!/bin/bash
exec scala "$0" "$@"
!#
object HelloApp extends App{
println("HelloApp")
}
HelloApp.main(args)
@haoch
haoch / play_adapt.sh
Created January 8, 2014 06:38
Play framework adapter for Linux/Unix
#!/bin/env bash
if [ $@ == 0 ];
echo "Error - Usage: $0 [PLAY_FRAMEWORK_HOME]"
exit -1
fi
PLAY_FRAMEWORK_HOME=$1
echo -e "\n# Adopt to Linux/Unix Environment \numask 002">> $PLAY_FRAMEWORK_HOME/play
@haoch
haoch / encodeURIParameters.js
Created January 2, 2014 06:50
NodeJS common functions
var encodeURIParameter= function(obj) {
var str = [];
for(var p in obj){
if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
}
return str.join("&");
}
@haoch
haoch / Gruntfile.js
Created December 30, 2013 15:31
nodejs: npm with grunt
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
@haoch
haoch / java.lang.String.CaseInsensitiveComparator.java
Created November 8, 2013 05:05
Why need compare both UpperCase and LowerCase in comparing case insensitively?
private static class CaseInsensitiveComparator
implements Comparator<String>, java.io.Serializable {
// use serialVersionUID from JDK 1.2.2 for interoperability
private static final long serialVersionUID = 8575799808933029326L;
public int compare(String s1, String s2) {
int n1 = s1.length();
int n2 = s2.length();
int min = Math.min(n1, n2);
for (int i = 0; i < min; i++) {
@haoch
haoch / shell_require.sh
Last active December 26, 2015 09:48
shell require dependency script
#!/bin/env bash
# shell require dependency script
#
# Usage:
# require mvn git ...
#
# Author : Chen, Hao (@haoch)
# Date : Oct 24th, 2013
require(){
@haoch
haoch / closure_pom.sh
Last active December 26, 2015 09:39
traverse pom.xml value with xml in in-line command
java -cp clojure.jar clojure.main -e "(use 'clojure.xml) (->> (java.io.File. \"pom.xml\") (clojure.xml/parse) (:content) (filter #(= (:tag %) :version)) (first) (:content) (first) (println))"
@haoch
haoch / utility-mixins.less
Created September 30, 2013 12:35
LESS UTILITY MIXINS
// UTILITY MIXINS
// --------------------------------------------------
// Clearfix
// --------------------
// For clearing floats like a boss h5bp.com/q
.clearfix {
*zoom: 1;
&:before,
&:after {