Skip to content

Instantly share code, notes, and snippets.

@liyu1981
liyu1981 / ctRequire.js
Last active December 26, 2015 20:29
require wrapper with package names.
/*
This will intro clustertech flavour of require -- ctRequire.
Originally, require works as
require([
'm1.js',
'm2.js',
'm3.js'
],
function(m1, m2, m3) {
@liyu1981
liyu1981 / simple_regex.js
Last active December 26, 2015 20:29
Simple regex implementation use DFA (http://swtch.com/~rsc/regexp/regexp1.html).
/*
Simple regex implementation use DFA (http://swtch.com/~rsc/regexp/regexp1.html).
It support following simple rules
1. '.' match all characters
2. '*' match 0+ occurrences, e.g., a*
3. '?' match 0 or 1 occurrences, e.g., a?
*/
@liyu1981
liyu1981 / hano.cc
Created October 29, 2013 13:23
hano implementation
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
using namespace std;
void moveout(struct peg* p, int no1);
@liyu1981
liyu1981 / gptest.c
Created October 29, 2013 13:29
greenplum test
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int data;
struct node *next;
} node;
node * label(node *list);
@liyu1981
liyu1981 / server.js
Created November 4, 2013 04:04
nodejs simple http server for static files
var sys = require('sys'),
my_http = require('http'),
path = require('path'),
url = require('url'),
filesys = require('fs');
my_http.createServer(
function(request,response){
var my_path = url.parse(request.url).pathname;
var full_path = path.join(process.cwd(),my_path);
@liyu1981
liyu1981 / httppost.js
Created November 4, 2013 04:06
simple nodejs http server print post body
var http = require('http');
var querystring = require('querystring');
function processPost(request, response, callback) {
var queryData = "";
if(typeof callback !== 'function') return null;
if(request.method == 'POST') {
request.on('data', function(data) {
queryData += data;
var crypto = require('crypto');
/**
* Calculates the hash/checksum of a string. Default algorithm is MD5.
*
* @param {String} str
* @param {String} algorithm
* @return {String} checksum
* @api public
*/
@liyu1981
liyu1981 / actionQueue.js
Last active December 28, 2015 23:29
Simple action queue facility for using in nodejs
function ActionQueue() {
this.q = [];
this.actionIndex = 0;
}
ActionQueue.prototype.push = function(func) {
this.q.push(func);
};
ActionQueue.prototype.run = function(callbacks) {
@liyu1981
liyu1981 / formJsonClient.js
Created November 21, 2013 09:55
a mutation of restify JsonClient. Send form data, receive json response.
// Copyright 2012 Mark Cavage, Inc. All rights reserved.
// Adapted from Mark Cavage's json_client.js of restify
// by Li Yu (liyu@clustertech.com) 2013
var crypto = require('crypto');
var util = require('util');
var querystring = require('querystring');
var restify_path = '../node_modules/restify';
(function() {
var EventEmitter = require('events').EventEmitter;
var inspect = require('util').inspect;
var emit_ = EventEmitter.prototype.emit;
EventEmitter.prototype.emit = function(name) {
var args = Array.prototype.slice.call(arguments);
if (!(this === process.stderr && name === 'drain')) {
console.error("Event '%s', arguments: %s",
name, inspect(args.slice(1), false, 1));
}