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
@chenzx
chenzx / save_bmp.cpp
Created March 7, 2013 06:43
Save memory bitmap data into a .bmp file
//typedef's to adapter to struct BMP_FILEHDR & BMP_INFOHDR;
typedef unsigned char UINT8;
typedef signed char SINT8;
typedef unsigned short UINT16;
typedef signed short SINT16;
typedef unsigned int UINT32;
typedef signed int SINT32;
//struct BMP_FILEHDR & BMP_INFOHDR defines are copied from Win32 .h files;
struct BMP_FILEHDR // BMP file header
@chenzx
chenzx / wstring2string.cpp
Created March 7, 2013 07:13
wstring <=> string convert utils
#include<cassert>
#include<cstdio>
#include<string>
#include<map>
using namespace std;
std::wstring string2wstring(const std::string& s)
{
int len;
int slength = (int)s.length() + 1;
@chenzx
chenzx / decomposeArcToBezierCubic.cpp
Created March 7, 2013 07:15
Convert arc to bezier cubic curves, code from WebKit
// This works by converting the SVG arc to "simple" beziers.
// Partly adapted from Niko's code in kdelibs/kdecore/svgicons.
// See also SVG implementation notes: http://www.w3.org/TR/SVG/implnote.html#ArcConversionEndpointToCenter
bool decomposeArcToCubic(float angle, float rx, float ry, FloatPoint& point1, FloatPoint& point2, bool largeArcFlag, bool sweepFlag,
std::vector<FloatPoint>& v1, std::vector<FloatPoint>& v2, std::vector<FloatPoint>& v
)
{
FloatSize midPointDistance = point1 - point2;
midPointDistance.scale(0.5f);
@chenzx
chenzx / datastruct_3-3.cpp
Created March 7, 2013 07:23
Old code: 《Data Structures》3-3, Operations on single list
#include<iostream>
using namespace std;
struct Node {
int key;
Node *next;
};
Node * reverseList(Node *pHead){
/*
@chenzx
chenzx / slow_http_server.py
Last active December 15, 2015 03:29
A Python Script Overrideing SimpleHTTPServer to supply HTTP response body slow-speed sending back behavior
import SimpleHTTPServer
import BaseHTTPServer
import time
import SocketServer
import os
import threading
import socket
PORT = 8888
@chenzx
chenzx / smart_http_server.py
Created April 8, 2013 06:21
A smart http server which can send 304 response when request header has "If-Modified-Since" set, Used for browser's http disk cache functional test.
import SimpleHTTPServer
import BaseHTTPServer
import time
import SocketServer
import os
import threading
import socket
PORT = 8888
@chenzx
chenzx / files_content_replace.rb
Last active December 16, 2015 03:29
Do plain string replace (use string#gsub API) of a collection of files
#!/usr/bin/env ruby
# encoding: utf-8
#
#Usage: ruby files_content_replace.rb <filePathLists.txt>
File.open(ARGV[0]).each { |filePath|
correctedFileContentLines = []
f = File.open(filePath.strip)
f.each { |line|
line2 = line.gsub("old text", "new text")
@chenzx
chenzx / saveSkBitmapToBMPFile.cpp
Created May 23, 2013 03:38
Save Skia SkBitmap to bmp file, used for debug test.
static void saveSkBitmapToBMPFile(const SkBitmap& skBitmap, const char* path)
{
typedef unsigned char UINT8;
typedef signed char SINT8;
typedef unsigned short UINT16;
typedef signed short SINT16;
typedef unsigned int UINT32;
typedef signed int SINT32;
struct BMP_FILEHDR // BMP file header
import SimpleHTTPServer
import BaseHTTPServer
import time
import SocketServer
import os
import threading
import socket
PORT = 8888
@chenzx
chenzx / keep_thunder_running_on_windows.py
Created June 25, 2013 15:56
A Python 2.7 script to keep the win32 app running, I use it to monitor my Thunder downloader, since it is keeping crashing due to insufficient disk space
import os
import sys
import time
PROCESS_NAME = u"Thunder.exe"
PROCESS_STARTUP_CMDLINE = 'E:\ThunderPortable\ThunderPortable.exe'
def win32app_not_running():
from win32com.client import GetObject
#Need download http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/pywin32-218.win32-py2.7.exe/download