Skip to content

Instantly share code, notes, and snippets.

View suxue's full-sized avatar

FEI Hao suxue

  • CSIT of ANU
  • ACT, Australia
View GitHub Profile
@suxue
suxue / .gitignore
Last active August 29, 2015 14:05
hello world LKM
.built-in.o.cmd
.hello.ko.cmd
.hello.mod.o.cmd
.hello.o.cmd
.tmp_versions/
Module.symvers
hello.ko
hello.mod.c
modules.order
@suxue
suxue / Makefile.am.coverage
Created August 4, 2014 07:11
autoconf common files
# Coverage targets
if HAVE_GCOV
.PHONY: clean-gcda
clean-gcda:
@echo Removing old coverage results
-find -name '*.gcda' -print | xargs -r rm
.PHONY: coverage-html generate-coverage-html clean-coverage-html
@suxue
suxue / bf.cpp
Created August 3, 2014 11:17
brain fuck c++
// a simple brain-fuck interpretor
// see http:://en.wikipedia.org/wiki/Brainfuck
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <vector>
#define BUFSIZE 30000
class State {
@suxue
suxue / wrap.cpp
Created July 17, 2014 02:18
wrap a function pointer in c++
// create an equivalent functor that call the function pointer and print
// all input arguments
#include <boost/function_types/parameter_types.hpp>
#include <boost/function_types/result_type.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/pop_front.hpp>
#include <functional>
#include <utility>
#include <iostream>
#include <iostream>
#include <string>
#include <type_traits>
#include <utility>
using namespace std;
void print(const string& str) {
cout << str << endl;
}
@suxue
suxue / kmeans.coffee
Created April 20, 2014 08:06
kmean classifier
_ = require("underscore")
assert = require('assert')
zip = (list) -> _.zip.apply(null, list)
sum = (list) -> _.reduce(list, ((memo, v) -> memo + v), 0)
mean = (list) -> sum(list) / list.length
distances =
euclidean : (p,q) ->Math.sqrt(sum _.map(_.zip(p, q), (v)->(v[0]-v[1])**2))
manhattan : (p,q) ->sum(_.map(_.zip(p, q), (v) -> Math.abs(v[0] - v[1])))
cosine : (p, q) ->
@suxue
suxue / MPDProxy.js
Created April 13, 2014 04:35
MPD Proxy
var events = require("events");
var net = require("net");
var util = require("util");
function make_line_reader(line_consumer) {
var buffer = [];
function parser(char) {
if (char !== '\n') {
buffer.push(char);
@suxue
suxue / server.js
Created April 11, 2014 04:03
simple websocket server
// websocket server for evaluating javascript expression remotely
var http = require("http");
var assert = require('assert');
var srv = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('simple websocket server for calculator');
});
@suxue
suxue / Edit_Distance.py
Created March 19, 2014 09:09
Calculate Edit Distance
#!/usr/bin/env python
# vim: set fileencoding=utf-8:
import sys
import numpy
import random
class Direction:
def __str__(self):
if self._dir == 0:
@suxue
suxue / WebSocketServer.sh
Created March 16, 2014 11:52
simple WebSocket Server make use of netcat
#!/bin/ksh
typeset port=$((RANDOM % 60000))
while ((port < 30000)); do
port=$((RANDOM % 60000))
done
typeset pipe=`mktemp -u`
mkfifo $pipe
trap "rm -f $pipe" INT