Skip to content

Instantly share code, notes, and snippets.

View wzpan's full-sized avatar
:octocat:
Focusing

潘伟洲 wzpan

:octocat:
Focusing
View GitHub Profile
@wzpan
wzpan / hexo_compile.sh
Created December 6, 2013 12:36
A script to help me publish blog interactively.
#!/bin/zsh
# Compress stylesheets and Javascripts
cd -
cd $HEXO/themes/bootstrap/source/css
find . -name "*.css"| while read line;do
yuicompressor $line -o ${line}.min
mv *.css.min ../dist/
done
cd -
@wzpan
wzpan / ruhoh-toc-mustache.txt
Created December 4, 2013 08:37
Mustache - ToC template for ruhoh
{{# page.toc }}
{{# page.tocstartlv }}
<script type="text/javascript">
jQuery(document).ready(function() {
// Put a TOC right before the entry content.
generateTOC('.content', 'Contents', {{ page.tocstartlv }});
});
</script>
{{! {{/ page.tocstartlv }} }}
{{! {{^ page.tocstartlv }} }}
@wzpan
wzpan / qsort_cstring.c
Created October 8, 2013 02:27
C - qsort string
#include <stdlib.h>
#include <stdio.h>
int cmp_char(const void *a, const void *b)
{
return *(char *)a - *(char *)b;
}
int main(void)
{
@wzpan
wzpan / forbid_copy_construct.c
Created October 6, 2013 08:19
C++ - a macro to forbid copy constructor
// 禁止使用拷贝构造函数和 operator= 赋值操作的宏
// 应在类的 private: 中使用
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
@wzpan
wzpan / droid.cpp
Created October 3, 2013 13:33
C++ - example for class and static member
#include <iostream>
using namespace std;
class Droid{
private:
string name;
public:
static int population;
Droid(const string &s);
@wzpan
wzpan / fileio.cpp
Created October 3, 2013 09:11
C++ - file io
#include <iostream>
#include <fstream>
#include <sstream>
#include <stdexcept>
using namespace std;
int main(int argc, char *argv[])
{
if(argc != 3){
@wzpan
wzpan / const_iterator.cpp
Last active December 24, 2015 11:28
C++ - const iterator
#include <iostream>
#include <vector>
#include <dbg.h>
using namespace std;
int main(void)
{
vector<int> vt;
vector<int>::const_iterator iter;
@wzpan
wzpan / Makefile
Last active December 24, 2015 09:39
Shell - A script I use to rapidly create a new C project skeleton.
CFLAGS=-g -O2 -Wall -Wextra -Isrc -rdynamic -DNDEBUG $(OPTFLAGS)
LIBS=-ldl $(OPTLIBS)
PREFIX?=/usr/local
SOURCES=$(wildcard src/**/*.c src/*.c)
OBJECTS=$(patsubst %.c,%.o,$(SOURCES))
TEST_SRC=$(wildcard tests/*_tests.c)
TESTS=$(patsubst %.c,%,$(TEST_SRC))
@wzpan
wzpan / runtests.sh
Created October 1, 2013 13:27
C - a shell script to run c unit tests
echo "Running unit tests:"
for i in tests/*_tests
do
if test -f $i
then
if $VALGRIND ./$i 2>> tests/tests.log
then
echo $i PASS
else
@wzpan
wzpan / mutex.c
Created September 26, 2013 02:58
C - thread
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#define NLOOP 5000
int counter;
pthread_mutex_t counter_mutex = PTHREAD_MUTEX_INITIALIZER;