Skip to content

Instantly share code, notes, and snippets.

@mwacc
mwacc / hug_rhadoop.R
Created June 18, 2014 11:16
rhadoop demo for Lviv HUG
library(rmr2)
rmr.options(backend = "local")
#hdfs.init()
lm.map =
function(., line) {
keyval( line[[1]], paste(line[[2]], line[[3]], sep="|"))
}
@mwacc
mwacc / gist:c04636a1b25409db9257
Created October 7, 2015 16:16
create maven project
# Spark scala project
mvn archetype:generate -B -DarchetypeGroupId=net.alchim31.maven -DarchetypeArtifactId=scala-archetype-simple -DarchetypeVersion=1.5 -DgroupId=org.apache.spark -DartifactId=<Project name> -Dversion=0.1-SNAPSHOT -Dpackage=org.apache.spark
# flink project
mvn archetype:generate \
-DarchetypeGroupId=org.apache.flink \
-DarchetypeArtifactId=flink-quickstart-scala \
-DarchetypeVersion=0.9.1 \
-DgroupId=org.apache.flink.quickstart \
-DartifactId=flink-scala-project \
@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);