Skip to content

Instantly share code, notes, and snippets.

@binshengliu
binshengliu / gist:1319029
Created October 27, 2011 08:07
notify the working thread to quit safely
// main thread
m_KillThreadEvent.SetEvent();
while (TRUE) {
DWORD result;
MSG msg;
result = ::MsgWaitForMultipleObjects(1, &m_hPositioning, FALSE, INFINITE, QS_ALLINPUT);
if (result == (WAIT_OBJECT_0)) {
break;
} else if (result == ((DWORD)0xFFFFFFFF)) {
DWORD e = GetLastError();
@binshengliu
binshengliu / gist:1319050
Created October 27, 2011 08:23
test running time of code fragment
LARGE_INTEGER BeginTime ;
LARGE_INTEGER EndTime ;
LARGE_INTEGER Frequency ;
QueryPerformanceFrequency(&Frequency);
QueryPerformanceCounter(&BeginTime) ;
//fragment to test
QueryPerformanceCounter(&EndTime) ;
cout.precision(10);
#
# STL GDB evaluators/views/utilities - 1.03
#
# The new GDB commands:
# are entirely non instrumental
# do not depend on any "inline"(s) - e.g. size(), [], etc
# are extremely tolerant to debugger settings
#
# This file should be "included" in .gdbinit as following:
# source stl-views.gdb or just paste it into your .gdbinit file
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
//define pixelformat of windows bitmap, notice the unusual ordering of colors
typedef struct {
unsigned char B;
unsigned char G;
unsigned char R;
@binshengliu
binshengliu / align16.c
Last active October 2, 2015 05:37
align x to 16
/* from genromfs.c */
#define ALIGNUP16(x) (((x)+15)&~15)
/* from zfs */
#define P2ALIGN(x, align) ((x) & -(align))
#define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
#define P2ROUNDUP(x, align) (-(-(x) & -(align)))
#define P2PHASE(x, align) ((x) & ((align) - 1))
#define P2NPHASE(x, align) (-(x) & ((align) - 1))
#define ISP2(x) (((x) & ((x) - 1)) == 0)
@binshengliu
binshengliu / backup with apt.txt
Created April 3, 2012 05:51 — forked from bepcyc/backup with apt.txt
BAckup and restore with aptitude in Ubuntu or Debian
before backup:
dpkg --get-selections > packages.txt
while restoring:
dpkg --clear-selections
dpkg --set-selections < packages.txt
aptitude install
CC=gcc
CFLAGS=-O3 -funroll-loops -c
LDFLAGS=-O2
LDLIBS=-lm
SOURCES=MyBot.c YourCode.c ants.c
HEADERS=ants.h
OBJECTS=$(addsuffix .o, $(basename ${SOURCES}))
EXECUTABLE=MyBot
all: $(EXECUTABLE)
(defun copy-current-line-position-to-clipboard ()
"Copy current line in file to clipboard as '</path/to/file>:<line-number>'"
(interactive)
(let ((path-with-line-number
(concat (buffer-file-name) ":" (number-to-string (line-number-at-pos)))))
(x-select-text path-with-line-number)
(message (concat path-with-line-number " copied to clipboard"))))
(define-key global-map (kbd "M-l") 'copy-current-line-position-to-clipboard)
git config --global alias.lg "log --color --graph --pretty=format:'%C(auto)%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
http://fredkschott.com/post/2014/02/git-log-is-so-2005/
wget -q http://londo.ganneff.de/apt.key -O- | apt-key add -
echo "deb http://londo.ganneff.de wheezy main" > /etc/apt/sources.list.d/emacs.list
aptitude update
aptitude install emacs-snapshot