Skip to content

Instantly share code, notes, and snippets.

View jackhftang's full-sized avatar

Jack Tang jackhftang

View GitHub Profile
// 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 March 3, 2022 06:06
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='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 / 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.
"""
@jackhftang
jackhftang / shortener_b36d7.js
Last active September 6, 2016 13:30
permute integer range [0, 56800235583]
const digits = "0123456789abcdefghijklmnopqrstuvwxyz";
const digitsReverse = (function(){
var arr = digits.split('');
var table = {};
for(var i=0; i<arr.length; i++) table[arr[i]] = i;
return table;
})();
const dim = 7;
const modulo = 36;
const shift = [11, 21, 21, 23, 4, 24, 1];
@jackhftang
jackhftang / shortener_b62d6.js
Last active September 6, 2016 13:29
In general, encode integer into string, and then decode it back. The encoded sequence look completely random and suitable for shortener. This implements allow integer of range 0 to 62^6-1 = 56800235583 > 2^35
const digits = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const digitsReverse = (function(){
var arr = digits.split('');
var table = {};
for(var i=0; i<arr.length; i++) table[arr[i]] = i;
return table;
})();
const dim = 6;
const modulo = 62;
const shift = [26, 13, 47, 40, 11, 19];