Skip to content

Instantly share code, notes, and snippets.

View chenzx's full-sized avatar
🎯
Focusing

Chen Zhixiang chenzx

🎯
Focusing
  • Shanghai, China
View GitHub Profile
require 'watir'
ie = Watir::IE.new
while 1 do
ie.goto('http://www.douban.com/update/')
sleep 300
end
@chenzx
chenzx / wannianli.htm
Created February 21, 2013 12:47
Chinese 10000 Yeas' Calendar
<html><head><meta http-equiv="Content-Type" content="text/html; charset=GBK">
<script language="Javascript">
<!--
/*****************************************************************************
个人首选
*****************************************************************************/
var conWeekend = 3; // 星期六颜色显示: 1=黑色, 2=绿色, 3=红色, 4=隔周休
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
int main()
{
import QtQuick 2.0
import QtWebKit 3.0
import QtQuick.XmlListModel 2.0
Rectangle {
id: container
width: 1024
height: 768
property string initialUrl: "http://127.0.0.1/"
@chenzx
chenzx / directory_sync.py
Last active December 14, 2015 13:49
I have copy C/C++ source files using command "cp -r /a /b",and then modified files inside /b,after that, i want to sync the changes into original /a, so i wrote this script, i found out that Python's os.path.ctime/mtime is really both shit.
#!/usr/bin/env python
# encoding: utf-8
#
import os
import os.path
import sys
import time
import glob
FILE_EXT_FILTERS = ('.h', '.cpp', '.c')
@chenzx
chenzx / sort_lines_by_field.rb
Last active December 14, 2015 13:49
Sort lines by field, using index and "number"/"string" compare.
all_line_objs = Array.new()
FIELD_SPLITTER = ' ' #change to '\t', ',', ':' as you need;
FIELD_INDEX = 1 #Start from 0;
FIELD_TYPE = "number" #number or string;
File.open(ARGV[0]).each { |line|
fields = line.strip.split(FIELD_SPLITTER)
field = fields[FIELD_INDEX]
line_obj = {field:field, line:line.strip}
@chenzx
chenzx / lines_cut_fields.rb
Created March 6, 2013 04:51
Cut out specific fields of each line, and re-puts out. Similar to awk's function
FIELD_SPLITTER = ' ' #change to '\t', ',', ':' as you need;
FIELD_CUT_INDEXS = [0] #Start from 0;
File.open(ARGV[0]).each { |line|
fields = line.strip.split(FIELD_SPLITTER)
cut_fields = []
FIELD_CUT_INDEXS.each{ |index|
field = fields[index]
cut_fields.push( field )
}
@chenzx
chenzx / copy_directory_tree.py
Created March 6, 2013 05:29
Copy directory tree according to a relative-path-list filter file
#!/usr/bin/env python
# encoding: utf-8
#
import os
import os.path
import sys
import shutil
def copy_directory_tree( base_dir, rel_path_list_file, to_dir ):
rel_path_list = [line.strip() for line in open(rel_path_list_file, 'r')]
@chenzx
chenzx / convert_EAISurface_to_SDLSurface.cpp
Created March 7, 2013 06:11
Convert EA::Raster::ISurface*'s partly update (Code from EAWebKit-1.21) to SDL_Surface
static SDL_Surface * convert_EAISurface_to_SDLSurface(SDL_Surface * screen, EA::Raster::ISurface* easurface, int x, int y, int w, int h){
int stride = easurface->GetStride();
typedef uint8_t Uint8;
Uint8 *bits = (Uint8*)easurface->GetData() + y*stride + x*4;
//The following code is mainly from "D:\SDL-1.2.15\test\testbitmap.c"(18,14):SDL_Surface *LoadXBM(SDL_Surface *screen, int w, int h, Uint8 *bits)
SDL_Surface *bitmap;
Uint8 *line;
/* Allocate the bitmap */
@chenzx
chenzx / macros.cpp
Last active December 14, 2015 15:09
Useful C/C++ macros
#ifdef _DEBUG
#ifdef _WIN32
#define dprintf(format,...) fprintf(stdout, "%s:%d:%s " format , __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
#else
//gcc:
#define dprintf(format, args...) fprintf(stdout, "%s:%d:%s " format, __FILE__, __LINE__, __FUNCTION__, ## args)
#endif
#else
#define dprintf(format, args...)
#endif