Skip to content

Instantly share code, notes, and snippets.

View jackhftang's full-sized avatar

Jack Tang jackhftang

View GitHub Profile
@jackhftang
jackhftang / vnc.sh
Last active September 17, 2019 16:15
bash script for vnc over ssh tunnel
#!/bin/bash
#HOST='tahufa@cube.jackhftang.com'
HOST='me@cube.jackhftang.com'
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 / 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 / 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 / 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 / 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

// 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 / 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 = {}
@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'
from bottle import run, post, request
from threading import Thread
from queue import Queue
import datetime
import requests
import shutil
import tempfile
from os.path import join
import time
@jackhftang
jackhftang / todo.html
Created September 29, 2017 17:21
A taste of rxjs + d3
<div>
<ul class="list"></ul>
Item: <input type="text" class="input_todo"/>
<button class="btn_push">Push</button>
<button class="btn_pop">Pop Last</button>
<br>
<span class="msg"></span>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.4.3/Rx.min.js"></script>