Skip to content

Instantly share code, notes, and snippets.

@oxyflour
oxyflour / hindley-milner.ts
Last active May 3, 2024 01:32
a typescript implement of hindley-milner type inference
// a typescript implement of hindley-milner type inference
// reference http://smallshire.org.uk/sufficientlysmall/2010/04/11/a-hindley-milner-type-inference-implementation-in-python/
/// <reference path="./lib.es6.d.ts" />
// ...
interface AstNode {
}
class Id implements AstNode {
@oxyflour
oxyflour / index.html
Created March 20, 2016 01:59
SaiHooker mouse gesture parser
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>SAI HOOKER TEST</title>
</head>
<body>
<canvas id="c"></canvas>
<script>
@oxyflour
oxyflour / index.html
Created March 26, 2016 10:17
basic mouse gesture parser with ANN
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SAI HOOKER TEST</title>
</head>
<body>
<div id="u" style="position:absolute;">
@oxyflour
oxyflour / ssh-vpn.sh
Last active January 15, 2024 08:41
how to setup non-root ssh vpn tunnel
# remember to add
#PermitTunnel yes
# in /etc/ssh/sshd_config
# create tun device on both machines
# ref: http://www.k336.org/2013/04/non-root-ssh-vpn.html
sudo ip tuntap add dev tun0 mode tun user oxyflour group oxyflour
# delete tun
sudo ip tuntap del dev tun0 mode tun
@oxyflour
oxyflour / watch.js
Created April 25, 2016 08:28
watch folder and generate jekyll site then upload
var watch = require('node-watch'),
exec = require('child_process').exec
function debounce(func, delay) {
var timeout = 0
return function() {
var that = this,
args = arguments
if (timeout) {
clearTimeout(timeout)
@oxyflour
oxyflour / index.sh
Last active May 3, 2016 13:46
create https authorized certs
# from http://engineering.circle.com/https-authorized-certs-with-node-js/
# generate ca
wget https://raw.githubusercontent.com/anders94/https-authorized-clients/master/keys/ca.cnf
openssl req -new -x509 -days 9999 -config ca.cnf -keyout ca-key.pem -out ca-crt.pem
# generate private key for server
openssl genrsa -out server-key.pem 4096
# generate server certificate, remember to update the CN (common name)
@oxyflour
oxyflour / Promise.chain.js
Created May 21, 2016 08:44
Promise.chain
Promise.chain = function(arr, func) {
var res = [ ],
req = Promise.resolve()
return arr.reduce((req, val, i) => req.then(r => {
res.push(r)
return func(val, i)
}), req).then(r => {
res.push(r)
return res.slice(1)
})
@oxyflour
oxyflour / index.html
Created September 18, 2016 11:20
display random images in folder
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
html, body, .slide {
width: 100%;
height: 100%;
overflow: hidden;
background-color: black;
@oxyflour
oxyflour / index.html
Created March 4, 2017 05:28
Sorting Algorithm Animations
<body>
<script>
// https://github.com/vbohush/SortingAlgorithmAnimations
const methods = {
async bubble(a) {
// https://en.wikipedia.org/wiki/Bubble_sort
for (let i = 0; i < a.length; i ++) {
for (let j = a.length - 1; j > i; j --) {
if (await a.comp(a[j - 1], a[j])) {
a.swap(j - 1, j)
@oxyflour
oxyflour / index.html
Last active March 4, 2017 09:30
billiard
<html>
<body>
<canvas id="cv"></canvas>
<script>
const A = 500, // billiard size
SQ3 = A * Math.sqrt(3),
p = [A * 0.25, A], // start point [x, y]
v = [0.4, 0.5], // velocity [vx, vy], smaller is better
strokeStyle = 'red', // line style
lineWidth = 2 // line width