Skip to content

Instantly share code, notes, and snippets.

View Torenable's full-sized avatar

Richard Huang Torenable

View GitHub Profile
@Torenable
Torenable / dedup_relationship.cql
Created October 14, 2016 00:50
Dedup relationships with identical properties in Cypher
MATCH (a) -[r]- (s)
// use two `WITH` clauses to build a sorted list
WITH r, a // a for group by
ORDER BY id(r)
WITH type(r) AS t, collect(r) AS coll, a
// identify duplications
WITH t, reduce(s = [], x IN coll|
CASE any(y IN coll WHERE id(x) > id(y)
AND y.KEY1 = x.KEY1
AND y.KEY2 = x.KEY2)
@Torenable
Torenable / graphviz-build-system-for-sublime.md
Last active March 22, 2017 17:21 — forked from olange/graphviz-build-system-for-sublime.md
Graphviz (DOT) Build System for Sublime Text 2 and 3

To transform the currently opened Graphviz source file (in DOT Language) into a PNG:

{
    "cmd": [ "/usr/local/bin/dot", "-Tpng", "-o", "$file_base_name.png", "$file"],
    "selector": "source.dot"
}

Usage

@Torenable
Torenable / graph_gist_template.adoc
Created November 17, 2016 17:00 — forked from jexp/graph_gist_template.adoc
CHANGEME: GraphGist Template. Fork to make your own, view source to see instruction comments

REPLACEME: TITLE OF YOUR GRAPHGIST

Introduction

@Torenable
Torenable / compile_python_pkg_from_src.txt
Last active January 5, 2017 21:29
Build `mxnet` and `python-igraph`
# Compile `mxnet`
git clone --recursive https://github.com/dmlc/mxnet
cd mxnet
cp make/osx.mk ./config.mk
echo "USE_BLAS = openblas" >> ./config.mk
echo "ADD_CFLAGS += -I/usr/local/opt/openblas/include" >> ./config.mk
echo "ADD_LDFLAGS += -L/usr/local/opt/openblas/lib" >> ./config.mk
echo "ADD_LDFLAGS += -L/usr/local/lib/graphviz/" >> ./config.mk
make -j$(sysctl -n hw.ncpu)
@Torenable
Torenable / convert_data_type_in_HIVE.hql
Created January 7, 2017 00:29
Convert CSV to Parquet in favor to Cloudera Impala
-- From CSV to Parquet in favor to Cloudera Impala
CREATE EXTERNAL TABLE IF NOT EXISTS [from_table] (
schema DATA_TYPE,
...
)
COMMENT 'A sample of vehicle infomation'
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
WITH SERDEPROPERTIES (
"separatorChar" = ",",
"quoteChar" = "\""
@Torenable
Torenable / adjacent_states.R
Created January 26, 2017 02:40
Convert the list of adjacent states to a data frame of directed state pairs
[List of Adjacent States in US](https://writeonly.wordpress.com/2009/03/20/adjacency-list-of-states-of-the-united-states-us/)
/*
glench provides a JSON file, and the URL is https://gist.github.com/3906059
Here is a R code to convert the nested list to a paired data frame in R
*/
library(dplyr)
@Torenable
Torenable / ROC.R
Last active May 21, 2017 03:45
Use pROC to evaluate classification in R
# library(pROC)
#----------------------------------
# Compute the ROC
#----------------------------------
pROC::roc($pred_p, $actual)
pROC::roc(
actual ~ pred,
data.frame(
@Torenable
Torenable / eval_dots_parameters.R
Last active May 21, 2017 19:09
Evaluate dots parameters in a R function
foo = function(...) {
list(...)
}
@Torenable
Torenable / purrr_mapping_pattern.R
Last active May 21, 2017 20:11
Programming paradigm for by row mapper and by column mapper
data(iris)
# Apply a function to rows
row_sum = function(...) {
each_row = list(...)
# call by position
each_row[[1]] + # Sepal.Length
each_row[[2]] + # Sepal.Width
each_row[[3]] + # Petal.Length
@Torenable
Torenable / thread_&_process_worker.py
Last active May 22, 2017 03:04
How to pass parameters to the workers
import threading
def thread_worker(*args, **kwargs):
pass
t1 = threading.Thread(target = thread_worker, args = (elms), kwargs = {key: value})
t1.start()
t1.join()
# arguments pass to the target function, and