Skip to content

Instantly share code, notes, and snippets.

@chenha0
chenha0 / gist:3720052
Created September 14, 2012 05:52
a simple C assert_equal macro
#define ASSERT_NUM_EQ(lhs, rhs) \
if ((lhs) != (rhs)) { \
printf("Assert equal %s == %s failed\n", #lhs, #rhs); \
printf("%s : %d, %s : %d\n", #lhs, lhs, #rhs, rhs); \
kill(getpid(), SIGABRT); \
}
@chenha0
chenha0 / gist:4491377
Last active December 10, 2015 20:58
c-style header file define guard snippet for sublime text 2. PS: $3 is nothing but a helper variable
<snippet>
<content><![CDATA[
#ifndef ${1:${3/.*/\U$&/}_}
#define $1
$2
#endif //${3:${TM_FILENAME/[\.\s\\\/()\[\]\{\}]+/_/g}}
]]></content>
<tabTrigger>defineguard</tabTrigger>
<scope>source.c++, source.c</scope>
</snippet>
@chenha0
chenha0 / speedtest.html
Created March 25, 2013 15:58
js download and upload speed test
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
var str = '1';
for (var dup = 0; dup < 20; dup++) {
str += str;
@chenha0
chenha0 / redmine
Created April 3, 2013 14:51
Redmine daemonize script - using webrick as service. Original from http://www.redmine.org/boards/1/topics/9334
#!/bin/bash
### BEGIN INIT INFO
# Provides: redmine
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redmine webrick
# Description: redmine webrick server autostart-script
### END INIT INFO
@chenha0
chenha0 / maxarea.cpp
Created April 22, 2013 05:44
[LeetCode]Container With Most Water http://leetcode.com/onlinejudge#question_11
class Solution {
public:
int maxArea(vector<int> &height) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int area = (height.size() - 1) * ( (height.front() < height.back()) ? height.front() : height.back() );
int i = 0, j = height.size() - 1;
while (i < j) {
@chenha0
chenha0 / inter.py
Last active December 30, 2015 07:59
find intersection among files
import sys
def parse(filename, limit):
freqs = []
with open(filename) as f:
for l in f.readlines():
l = l.strip().split()
freqs.append((float(l[1]), l[0]))
freqs.sort(reverse=True)
if limit > len(freqs): limit = len(freqs)