Skip to content

Instantly share code, notes, and snippets.

View richard-to's full-sized avatar

Richard To richard-to

View GitHub Profile
@richard-to
richard-to / sb16.py
Created April 26, 2014 07:45
Random code for a class project
import logging
import socket
import SocketServer
import sys
import time
import threading
from ftplib import FTP
from os import listdir, remove, rename, stat
from os.path import isfile, join, splitext, isfile
@richard-to
richard-to / knn1.py
Created November 4, 2014 06:44
kNN implementations with Pandas based on examples from ML in Action by Peter Harrington
import math
import numpy as np
def createDataSet():
"""
Creates a basic data set labels.
The labels are the classification given to the points. The data
is hardcoded in this toy example.
@richard-to
richard-to / gist:70049650cf58f1858b8cd38528c07a3c
Last active September 1, 2016 00:32
ES6 Features - based on examples from http://es6-features.org/
// Constants
const test_const = 1;
// Scoped variables - use `let` for local scope
let callbacks = [];
for (let i = 0; i < 3; ++i) {
callbacks[i] = function() { return i; };
}
// Arrow functions
@richard-to
richard-to / image_lossy_optimize.sh
Created January 22, 2014 07:01
Simple bash script to apply lossy optimization to jpgs in folder
#!/bin/bash
rm -rf out
mkdir out
for d in $(ls)
do
if [[ $d == *.jpg ]]
then
convert $d "out/$d.png"
@richard-to
richard-to / fisher-yates-shuffle.js
Created January 21, 2014 06:51
Fisher Yates Shuffle implementation in javascript that returns shallow clone of new list
// Fisher-Yates Shuffle
var shuffle = function(list_in) {
var pick, temp;
var list = list_in.slice(0);
var i = list.length;
while (--i > 0) {
pick = Math.floor(Math.random() * i);
temp = list[i];
list[i] = list[pick];
list[pick] = temp;
@richard-to
richard-to / gist:8122471
Last active January 1, 2016 09:08
Running list basic numpy functions usage so I don't forget.
# Create a numpy array from a list
data = np.array(listData)
# Get a vector of elements in 2nd column -> [1, 2, 3]
# Remeber that the arrays are 0 indexed so technically it would be the 3rd column
colVec = data[:,2]
# Get a vector of elements 1st row -> [1, 2, 3]
# Don't forget the comma!
rowVec = data[1,:]
@richard-to
richard-to / owari.py
Created December 24, 2013 06:43
Owari with Alpha Beta Pruning and MySQL transposition table. Can't remember if this code actually works anymore, but was using it to try to find all possible moves in Owari. Unfortunately there are probably over a hundred million moves and my old desktop ran out of RAM at about 22 million. Only 4GB installed.
import time
import MySQLdb as mdb
from warnings import filterwarnings
import config
filterwarnings('ignore', category = mdb.Warning)
conn = mdb.connect(*config.db)
@richard-to
richard-to / gist:5843066
Created June 22, 2013 23:21
Random java command line compile and jar instructions
javac -classpath /full/path/to/file.jar -d class/output/dir src/*.java
jar -cvf outdir/program.jar -C class/output/dir/ .
@richard-to
richard-to / gist:5843052
Created June 22, 2013 23:16
Hadoop 1.1 installation instructions for Ubuntu 12 using Debian package
# Need this installed to use `add-apt-repository`
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
sudo update-java-alternatives -s java-7-oracle
# Download and install Hadoop 1.1 from one of the mirrors.
wget http://apache.mirrors.tds.net/hadoop/common/hadoop-1.1.2/hadoop_1.1.2-1_x86_64.deb
sudo mount -t nfs -o resvport,soft,intr,rsize=8192,wsize=8192,timeo=900,retrans=3,proto=tcp hostname:/shared_dir /local_dir