Skip to content

Instantly share code, notes, and snippets.

function tree(id, arr){
var node = arr.find(a => a.id == id) || { }
node.items = arr.filter(a => a.pid == id).map(a => tree(a.id, arr))
return node
}
tree(0, [
{id:1, pid:0, name:"SYSTEM"},
{id:2, pid:1, name:"aa"},
{id:3, pid:2, name:"aaa"},
{id:4, pid:2, name:"b"},
@oxyflour
oxyflour / book.py
Created September 25, 2015 06:05
some auto booking scripts (of course no longer working)
# -*- coding: gbk -*-
import os, sys, urllib, urllib2, cookielib, random, re, datetime
# uis username, uis password, phone number
userinfo = [ \
# [studentID, password, phoneNumber],
]
# the desired date (year, month, day)
reqdate = datetime.date(2015, 5, 6)
@oxyflour
oxyflour / index.php
Created September 25, 2015 13:02
php script to cache images with memcache in Sina App Engine
<?php
//ini_set('display_errors',1);
//ini_set('display_startup_errors',1);
//error_reporting(-1);
// this is naive
function isValidUrl($url) {
return strpos($url, 'http://') === 0 || strpos($url, 'https://') === 0;
@oxyflour
oxyflour / count_particles.m
Created September 30, 2015 02:39
count particle statistics from image
% image file
FILE_NAME = 'p2.png';
% length / pixel
LENGTH_SCALE = 500 / 114;
% ignore regions if area small than
MIN_AREA = 10;
% filter to create binary image
@oxyflour
oxyflour / auto_auth.py
Created October 17, 2015 06:12
auto authentication script in Guanghua Building
import httplib, urllib, datetime
conn = httplib.HTTPConnection('baidu.com')
conn.request('GET', '/')
response = conn.getresponse()
data = response.read()
conn.close()
if data.find('//10.108.255.12') < 0:
exit()
@oxyflour
oxyflour / index.html
Created November 1, 2015 07:36
touhou clock html5 demo
<html>
<head>
<meta name="viewport" content="width=640,user-scalable=no" />
<meta charset="utf8" />
<style>
html, body {
background: #aaa;
margin: 0;
padding: 0;
position: relative;
@oxyflour
oxyflour / convert.js
Last active November 18, 2015 08:39
convert image sequence to avi with ffmpeg
var PREFIX = 'c' + Math.floor(Math.random() * 1000) + '-',
EXTENSION = 'bmp',
ROOT_DIR = '',
FFMPEG_PATH = 'ffmpeg-20151116-git-1fe82ab-win64-static\\bin\\ffmpeg.exe',
FFMPEG_ARGS = '-framerate 30',
FILE_OUTPUT = 'test.avi'
var app = WScript.CreateObject('Shell.Application'),
shell = WScript.CreateObject('WScript.Shell'),
fso = WScript.CreateObject('Scripting.FileSystemObject')
@oxyflour
oxyflour / SOAPle.py
Created January 31, 2016 08:31
simple upnp python interface
import xml.dom.minidom
def node_to_obj(node):
obj = {}
if node.nodeType == 1:
if node.attributes.length > 0:
obj["#attr"] = {}
for i in range(0, node.attributes.length):
attr = node.attributes.item(i)
obj["#attr"][attr.name] = attr.value
@oxyflour
oxyflour / autossh
Last active February 3, 2016 01:09 — forked from jeremija/autossh
raspi autossh
#! /bin/sh
# /etc/init.d/autossh
TUNNEL_MONITOR=53389
TUNNEL_USER="bae"
TUNNEL_HOST="bae.ofr.me"
TUNNEL_PORT=30383
TUNNEL_KEY="/home/oxyflour/.ssh/bae.id_rsa"
TUNNEL_ARGS="-D 0.0.0.0:3129 -L 0.0.0.0:13128:127.0.0.1:3128 -L 0.0.0.0:10022:vlr.ofr.me:22"
@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>