Skip to content

Instantly share code, notes, and snippets.

@mwacc
mwacc / gist:5472666
Last active December 16, 2015 17:48
postaction example in Ngnix
location / {
root /usr/domain.com/nginx/html;
index index.jsp;
post_action /aftertouching;
}
location /aftertouching {
proxy_pass http://10.25.0.11/count.do?resource=$request&status=$request_completion&fromIp=$remote_addr&body_bytes_sent=$body_bytes_sent;
internal;
}
@mwacc
mwacc / FixHadoopOnWindows.java
Created May 17, 2013 13:46
Fix PigUnit on Windows env
package example.pig;
import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.NotFoundException;
public class FixHadoopOnWindows {
@mwacc
mwacc / gist:5955882
Created July 9, 2013 09:10
read/write file
int i = 0;
File file = new File("out2.csv")
file << "Id,Action\n"
new File('out.csv').eachLine { line ->
if(i > 0) {
file.append i
file.append ','
file.append Double.valueOf(line) > 0.6 ? 1 : 0;
file.append '\n'
@mwacc
mwacc / sym_tree.groovy
Created July 10, 2013 10:24
Check if tree is symmetric based on BFS algorithm
class Node {
def val
def left
def right
}
/*
root
A B
@mwacc
mwacc / levenstein
Created July 10, 2013 11:33
slow recursive Levenshtein distance
def levenshtain(String s1, String s2, int i, int j) {
if(i == -1 && j == -1) {
return 0
} else if( j == -1 && i > -1 ) {
return i
} else if(i == -1 && j > -1) {
return j
} else {
return min(
levenshtain(s1, s2, i, j-1)+1,
@mwacc
mwacc / gist:5984183
Created July 12, 2013 12:45
rabbitmq sample
/*
<dependencies>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>3.1.1</version>
</dependency>
</dependencies>
*/
@mwacc
mwacc / ProductListGenerator
Created July 23, 2013 12:56
Product list generator for BasketAnalys example
class Constants {
static final goods = [
'Apple', 'Orange', 'Pineaple', 'Cherry', 'Beef', 'Sugar', 'Milk',
'Pear', 'Limon', 'Blubbery', 'IceCream', 'Cake', 'Orange', 'Milk',
'Cola', 'Bread', 'Coffe', 'Cookies', 'Beer', 'Tea', 'Salmon', 'Steal Water', 'Nuts']
}
rand = new Random()
@mwacc
mwacc / Basket
Created July 23, 2013 12:59
Basket Analytic (Frequent Pattern Mining) example "in action" :)
#Install the R package arules if required
#install.packages("arules");
#load the arules package
library("arules");
# read the transaction file as a Transaction class
txn = read.transactions(file="d:\\work\\R\\items.csv", rm.duplicates= FALSE, format="basket",sep=",");
#To visualize the item frequency in txn file
itemFrequencyPlot(txn);
@mwacc
mwacc / gist:6745981
Created September 28, 2013 20:03
merge sort in groovy
def toSort = [5, 6, 7, 1, 4, 3, 2, 9, 0, 7, 8]
def partition(toSort) {
if(toSort.size == 1) return toSort
int midle = (int)(toSort.size/2)
def left = new ArrayList(), right = new ArrayList();
for(int i = 0; i < midle; i++) left << toSort[i]
for(int i = midle; i < toSort.size; i++) right << toSort[i]
@mwacc
mwacc / amazon
Created September 30, 2013 13:05
Random forest on R example
#install.packages("randomForest")
library(randomForest)
train = read.csv(file="D:\\work\\R\\train.csv",head=TRUE,sep=",")
test = read.csv(file="D:\\work\\R\\test.csv",head=TRUE,sep=",")
rf = randomForest(ACTION ~ RESOURCE+MGR_ID+ROLE_DEPTNAME+ROLE_FAMILY_DESC+ROLE_ROLLUP_2+ROLE_ROLLUP_1+ROLE_TITLE+ROLE_CODE, data=train, importance=TRUE, ntree=250, mtry=3)
prediction = predict(rf, test)
write.csv(prediction, "D:\\work\\R\\out.csv", row.names=FALSE)