Skip to content

Instantly share code, notes, and snippets.

View mashihua's full-sized avatar
🏠
Working from home

Shihua Ma mashihua

🏠
Working from home
View GitHub Profile
@mashihua
mashihua / README
Created April 17, 2012 04:09
Patch for v8
#Escape the 1.4GB V8 heap limit patch for Version 3.10.2
Usage: patch -p0 < v8.patch
@mashihua
mashihua / lbyl-test.js
Created February 14, 2012 08:01
LBYL test
//test browser "look-before-you-leap" (LBYL) request
//expect is a header of HTTP/1.1
var http = require('http');
http.createServer(function(req,res){
console.log(req.header['user-agent'],req.header.expect);
});
@mashihua
mashihua / number_hash_collision.php
Created January 9, 2012 03:21
Hash collision in PHP
<?php
$size = pow(2, 16); // 16 is just an example, could also be 15 or 17
$startTime = microtime(true);
$array = array();
for ($key = 0, $maxKey = ($size - 1) * $size; $key <= $maxKey; $key += $size) {
$array[$key] = 0;
}
@mashihua
mashihua / README.md
Created January 6, 2012 13:13
Query tickets in china

Run it your own risk.

Query tickets in china

How to

  1. Copy ticket.js and run it on your browser
  2. Install node.js
  3. Put package.json and server.js into a folder
  4. Copy a mp3 to the same forder and rename it to "alert.mp3"
@mashihua
mashihua / nextTick.js
Created January 2, 2012 18:16
GC time for V8
var time = (+new Date) + 1000 * 60;
process.nextTick(function w(){
if(+new Date < time)
process.nextTick(arguments.callee)
});
@mashihua
mashihua / mysql_to_omnigraffle.applescript
Created December 26, 2011 03:01 — forked from guilhermechapiewski/mysql_to_omnigraffle.applescript
AppleScript to dump MySQL tables to OmniGraffle Pro.
(*
Copyright (c) 2008, Christian Mittendorf <[email protected]>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list ofconditions and the following disclaimer. Redistributions in binary form
must reproduce the above copyright notice, this list of conditions and the
@mashihua
mashihua / file_input_example.css
Created December 14, 2011 03:42 — forked from nathansmith/file_input_example.css
Markup to Hide a File Input
.fake_file_input {
background: url(../images/fake_file_input.png) no-repeat;
cursor: pointer;
width: 150px;
height: 30px;
overflow: hidden;
position: relative;
display: inline-block;
*display: inline;
*zoom: 1;
@mashihua
mashihua / hackcmb.js
Created December 2, 2011 22:02
Enable mobile CMB on desktop Safari
SubmitControl.prototype.submit = function() {
var sXmlReq = "";
if (BSGetElementIgnoreError("TransID_New") != null) {
this.addFieldByElementId("TransID_New");
}
for (var i = 0; i < this.m_fields.length; i++) {
var sName = (this.m_fields[i])[0];
var sValue = (this.m_fields[i])[1];
if ((sName != null) && (sValue != null)) {
sValue = sValue.replace("%", "%25");
@mashihua
mashihua / arg.js
Created October 20, 2011 10:13
get arguments
function arg(type) {
var r,t = Object.prototype.toString;
[].forEach.call(arguments.callee.caller.arguments, function (a) {
if (!r && t.call(arguments[0]).replace(/^[^\s]+\s([^\]]+)]/ig,"$1").toLowerCase() === type.toLowerCase()) r = a;
});
return r;
}
@mashihua
mashihua / node_debian_init.sh
Created October 19, 2011 07:34 — forked from peterhost/node_debian_init.sh
Daemon init script for node.js based app/server (DEBIAN/UBUNTU)
#!/bin/sh
# ------------------------------------------------------------------------------
# SOME INFOS : fairly standard (debian) init script.
# Note that node doesn't create a PID file (hence --make-pidfile)
# has to be run in the background (hence --background)
# and NOT as root (hence --chuid)
#
# MORE INFOS : INIT SCRIPT http://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit
# INIT-INFO RULES http://wiki.debian.org/LSBInitScripts
# INSTALL/REMOVE http://www.debian-administration.org/articles/28