Skip to content

Instantly share code, notes, and snippets.

View jackhftang's full-sized avatar

Jack Tang jackhftang

View GitHub Profile
@jackhftang
jackhftang / mat2csv.py
Created September 2, 2017 06:11
convert matlab .mat to .csv
#!/bin/env python3
import scipy.io
import numpy as np
import sys
from os.path import basename, splitext
src = sys.argv[1]
data = scipy.io.loadmat(src)
dest = f'{splitext(basename(src))[0]}.csv'
@jackhftang
jackhftang / knocking.py
Last active August 28, 2017 00:03
A simple knocking server
from bottle import route, run, template, error
import bottle
import subprocess
from random import random
from time import sleep
sequence = ['key1', 'key2', 'key3']
exclude = ['favicon.ico']
table = {}
// coroutine for callback
function coroutineC(gen, handler) {
let cb = function (err, value) {
switch (err) {
case undefined:
case null:
process.nextTick(function () {
try {
g.next(value)
} catch (ex) {
@jackhftang
jackhftang / answer1.md
Last active May 6, 2024 19:44
Oursky Developer Pre-Test

Question 1

Write a function that takes two arrays as input, each array contains a list of A-Z; Your program should return True if the 2nd array is a subset of 1st array, or False if not.

For example: isSubset([A,B,C,D,E], [A,E,D]) = true isSubset([A,B,C,D,E], [A,D,Z]) = false isSubset([A,D,E], [A,A,D,E]) = true

@jackhftang
jackhftang / xorfiles.py
Created July 23, 2017 03:24
Simple python script for one-time pad
#!/bin/env python3
import sys
if len(sys.argv) == 1:
print('usage: <file1> [<file2>]')
exit(1)
try:
a = open(sys.argv[1], 'rb')
@jackhftang
jackhftang / pytorch_play.py
Last active June 27, 2017 03:26
An demonstration of autograd. Guess the linear recursive relation of fibnonssi number. i.e. Given f(0) = a0, f(1) = a1, f(x) = w0*f(x-1) + w1*f(x-2), find a0,a1,w that best approximate fibonacci sequence fib(i) where i = 5..9
import torch as th
from torch.autograd import Variable
## helpers
def var(t):
return Variable(t, requires_grad=True)
## training data
fibs = [1, 1]
for i in range(8):
@jackhftang
jackhftang / pytorch_play.py
Created June 7, 2017 07:26
Given known recurrent structure f(x) = w0 * f(x-1) + w1 * f(x-1)
import torch as th
from torch.autograd import Variable
## helpers
def fromlist(list):
return th.FloatTensor(list)
def const(t):
return Variable(t)
@jackhftang
jackhftang / vnc.sh
Last active September 17, 2019 16:15
bash script for vnc over ssh tunnel
#!/bin/bash
#HOST='[email protected]'
HOST='[email protected]'
SOCK='/tmp/ssh_tunnel_vnc_cube.sock'
vncviewer='/Applications/TigerVNC Viewer 1.7.1.app/Contents/MacOS/TigerVNC Viewer'
PORT=${1:-5900}
## open socket
ssh -f -N -C -X -L 5900:127.0.0.1:$PORT -o ExitOnForwardFailure=yes -M -S $SOCK $HOST
@jackhftang
jackhftang / google_sheet.js
Created March 10, 2017 10:03
An easy google sheet for landing page
var SHEET_NAME = "Sheet1";
function doGet(e) {
return handleResponse(e);
}
function doPost(e) {
return handleResponse(e);
}
@jackhftang
jackhftang / SimpleHTTPServerWithUpload.py
Created December 27, 2016 01:19 — forked from UniIsland/SimpleHTTPServerWithUpload.py
Simple Python Http Server with Upload
#!/usr/bin/env python
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""