Skip to content

Instantly share code, notes, and snippets.

@joyeecheung
joyeecheung / reverse.js
Created September 5, 2014 04:12
Reverse a list recursively.
function reverse(a) {
return a.length ? reverse(a.slice(1)).concat([a[0]]) : [];
}
@joyeecheung
joyeecheung / resolve.js
Created August 28, 2014 07:30
A simplified version of the require.resovle() from node.js
var path = require('path');
// require(X) from module at path Y
function resolve(x, y) {
// 1. If X is a core module,
// a. return the core module
// b. STOP
if (isCoreModule(x)) {
console.log(x + " is a core module");
}
@joyeecheung
joyeecheung / plot.plt
Last active August 29, 2015 14:04
plotting result of Jigsaw
set terminal png size 1378,768
set output 'result.png'
set xrange [-2000:30000]
set boxwidth 200 absolute
set style fill solid 1.0 noborder
bin_width = 1000;
bin_number(x) = floor(x/bin_width)
rounded(x) = bin_width * ( bin_number(x) + 0.5 )
plot 'result.txt' using (rounded($1)):(1.0/20) smooth frequency with boxes
@joyeecheung
joyeecheung / count.sh
Created August 5, 2014 11:10
count.sh
#! /usr/bin/env bash
for i in {1..20}; do
ant run
result=`grep "No solution" ASearchDialog.txt`
if [ ! -z "$result" ]; then
echo "-1" >> result.txt
else
result=`grep -o "Total number of searched nodes:[0-9]\+" ASearchDialog.txt | grep -o '[0-9]\+$'`
echo $result >> result.txt
@joyeecheung
joyeecheung / setup.sh
Last active August 29, 2015 14:04
Set up environment for SYSU Cloud Desktop
# Download JDK
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u65-b17/jdk-7u65-linux-x64.tar.gz
# Untar JDK
tar xvzf jdk-7u65-linux-x64.tar.gz
# Remove the tar.gz
rm jdk-7u65-linux-x64.tar.gz
# set env var
@joyeecheung
joyeecheung / gpa-calculator-insysu.js
Last active August 29, 2015 14:04
GPA calculator for insysu.com
var courses = $("#score-result table tbody tr");
var totalCredit = 0.0, totalProduct = 0.0;
courses.each(function(idx, course) {
var cells = $(course).children("td");
if (cells[3].textContent !== "公选") {
var credit = parseFloat(cells[2].textContent);
var score = parseFloat(cells[5].textContent);
totalCredit += credit;
@joyeecheung
joyeecheung / gpa.js
Created July 17, 2014 06:56
GPA calculator for SYSU third party academic administration system
var tr = $("#score-result table tbody tr");
var credit_total = 0.0, total = 0.0;
tr.each(function(idx, row) {
var credit = parseFloat($(row).children('td')[0].textContent);
var score = parseFloat($(row).children('td')[2].textContent);
credit_total += credit;
total += score * credit;
});
@joyeecheung
joyeecheung / test.sh
Created July 2, 2014 13:29
Run the tests!
for z in *.zip; do
d=`basename $z .zip`
mkdir $d && unzip $z -d $d
if [ -d "$d/src" ]; then
cp ../_s1/* $d/src/
if [ -f "$d/src/makefile" ]; then
rm $d/src/makefile
fi
cd $d/src/
make
@joyeecheung
joyeecheung / load.sh
Created March 18, 2014 13:14
Litter helper to generate loading command when building TPC-H.
#!/bin/bash
write_to_file()
{
file="loaddata.sql"
if [ ! -f "$file" ] ; then
touch "$file"
fi
@joyeecheung
joyeecheung / loaddata.sql
Created March 18, 2014 12:44
Example for loading data generated by TPC-H.
USE tpch;
LOAD DATA LOCAL INFILE '/home/joyeecheung/tpch_2_16_1/dbgen/region.tbl' INTO TABLE REGION
FIELDS TERMINATED BY '|' LINES TERMINATED BY '|\n';
LOAD DATA LOCAL INFILE '/home/joyeecheung/tpch_2_16_1/dbgen/nation.tbl' INTO TABLE NATION
FIELDS TERMINATED BY '|' LINES TERMINATED BY '|\n';
LOAD DATA LOCAL INFILE '/home/joyeecheung/tpch_2_16_1/dbgen/supplier.tbl' INTO TABLE SUPPLIER
FIELDS TERMINATED BY '|' LINES TERMINATED BY '|\n';