Skip to content

Instantly share code, notes, and snippets.

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
@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);
@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)
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)
@binshengliu
binshengliu / utf7.py
Created September 21, 2016 17:47 — forked from gauteh/utf7.py
UTF8 to IMAP4-UTF-7 for OfflineIMAP
# -*- coding: utf-8- -*-
# from: http://piao-tech.blogspot.no/2010/03/get-offlineimap-working-with-non-ascii.html#resources
import binascii
import codecs
# encoding
def modified_base64 (s):
@binshengliu
binshengliu / gist:0f4d2e42b4d703e381092b7ae870dcc1
Created December 11, 2016 07:02
Show pid of a window by clicking on it
xprop _NET_WM_PID | cut -d' ' -f3
{click on window}
Source: http://unix.stackexchange.com/questions/19161/getting-a-windows-pid-by-clicking-on-it
@binshengliu
binshengliu / Makefile
Last active February 16, 2017 09:15
Makefile template for latex projects
# https://danielkaes.wordpress.com/2009/03/14/compiling-latex-documents-using-makefiles/
PROJECT= # tex file name here without extension
TEX=pdflatex
BIBTEX=bibtex
BUILDTEX=$(TEX) $(PROJECT).tex
all:
$(BUILDTEX)
$(BIBTEX) $(PROJECT)
$(BUILDTEX)