Skip to content

Instantly share code, notes, and snippets.

View guohai's full-sized avatar
🎱
Hey

Brent Kwok guohai

🎱
Hey
View GitHub Profile
@guohai
guohai / shell-proc.sh
Created August 8, 2011 12:39
If a process is running
#!/bin/sh
PROC_HOME=$(cd "$(dirname "$0")"; pwd)
PID_FILE=$PROC_HOME/hello.pid
function alive() {
if [ -f ${PID_FILE} ] && ((`ps awux | grep -v grep | grep -c chrome`)); then
echo "the process is running"
exit 1
fi
@guohai
guohai / InsertingDataWithPS.java
Created July 21, 2011 15:14
quick and stupid test for https://gist.github.com/1097396 in java(need c3p0 to run it directly)
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import com.mchange.v2.c3p0.ComboPooledDataSource;
public class InsertingDataWithPS {
@guohai
guohai / test_insert_data.sql
Created July 21, 2011 15:07
Insert data(string or null, date etc...) with ps, building dynamic sql, excuting with prepare sql
CREATE TABLE `str_test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) DEFAULT NULL,
`ats` text,
`dor` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
delimiter $$
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class RecursionMethodDemo {
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
@guohai
guohai / fcgi.py
Created April 13, 2011 15:31
FastCGI+Nginx+Trac启动测试
#!/usr/bin/python
#encoding: utf8
from flup.server.fcgi import WSGIServer
def myapp(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['Hello World!\n你好,世界!']
if __name__ == '__main__':
@guohai
guohai / DBAdapter.java
Created April 12, 2011 13:34
Android数据库创建更新帮助类
package org.xkit.android.demo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;