Skip to content

Instantly share code, notes, and snippets.

# read lines
lines = open('file-name.txt').readlines()
# change a specific line
# e.g. using regular expression
p = re.compile(...)
for i in range(len(lines)):
m = p.match(lines[i])
if m:
# m.group(0) or m.group(1)
@guanqun
guanqun / cpu-gpu-blur-comparison-script.sh
Created March 6, 2012 05:38
Compare CPU and GPU Blur Time
#!/bin/sh
rm -f cpu-output.txt
rm -f gpu-output.txt
# run benchmarks
../out/Release/bench -config 8888 -repeat 100 -match blur_size | tee cpu-output.txt
../out/Release/bench -config GPU -repeat 100 -match blur_size | tee gpu-output.txt
for i in 1 2 4 8 16 32 64 128 ; do
/////////////////////////////////////////////////////////////////////////////
/* the callbacks */
struct data {
char trace_ascii; /* 1 or 0 */
};
struct data config;
static
void dump(const char *text,
import os
import re
files = []
for (root, dirnames, filenames) in os.walk('.'):
if len(filenames) != 0:
for one in filenames:
files.append(os.path.join(root, one))
isPng = re.compile(r'.*\.png$')
import Image
import sys
import os
imagefilename = sys.argv[1]
im = Image.open(imagefilename)
tim = Image.new('RGBA', im.size)
@guanqun
guanqun / gist:6175227
Created August 7, 2013 15:40
string split
/* extracted from http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html
* use this hand-crafted function if boost can't be used in the project.
*/
void tokenize(const string& str,
vector<string>& tokens,
const string& delimiters = " ")
{
// Skip delimiters at beginning.
string::size_type lastPos = str.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
@guanqun
guanqun / .gitignore
Last active December 22, 2015 06:38
unity3d ignore files
.DS_Store
Library/
Temp/
Build/
*.csproj
*.sln
*.userprefs
*.pidb
*.unityproj
@guanqun
guanqun / gist:7035237
Created October 18, 2013 01:46
convert string to bytes
System.Text.Encoding.UTF8.GetString(bytes);
using System.Text;
Encoding.ASCII.GetBytes(words);
[Extension]
public static class ListUtils
{
[Extension]
public static void Shuffle<T>(IList<T> list)
{
int count = list.Count;
while (count > 1)
{
count--;
#include <algorithm>
#include <functional>
#include <cctype>
#include <locale>
// trim from start
static inline std::string &ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
return s;
}