Skip to content

Instantly share code, notes, and snippets.

View drmingdrmer's full-sized avatar
🙃
coding bit by bit

张炎泼 drmingdrmer

🙃
coding bit by bit
View GitHub Profile
@drmingdrmer
drmingdrmer / git-auto-squash
Last active May 27, 2022 05:58
Rewrite history to squash all commits wiht message starts with 'fixup!' to its first parent. By drdr.xp@gmail.com
#!/bin/bash
usage()
{
local name=${0##*/}
cat >&2 <<-END
Rewrite history to squash all commits wiht message starts with 'fixup!' to
its first parent. By drdr.xp@gmail.com
@drmingdrmer
drmingdrmer / hash_bucket_count_simulation.py
Last active August 29, 2015 14:16
hash behavior simulation in python
#!/usr/bin/env python
# coding: utf-8
import sys
import hashlib
import math
def count_collision(nbucket, nkey):
buckets = [0] * nbucket
@drmingdrmer
drmingdrmer / git-split
Last active November 22, 2015 17:57
split files out of commits to build a new branch
#!/bin/bash
# * 358aee4 (HEAD) fix css
# | css/site.css | 13 ++---
# |
# * f869f40 init site
# | html/index.html | 12 ++--
# | html/header.html | 34 +-----
# | css/site.css | 61 +++++++------
# |
@drmingdrmer
drmingdrmer / q.c
Created October 22, 2014 04:19
break accept() with close()/shutdown()
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <pthread.h>
/* gcc -lpthread q.c && ./a.out */
@drmingdrmer
drmingdrmer / git-file-branch.sh
Last active October 7, 2015 05:57
shell script to find out in which git-branch the last time a file was modified
# usage:
# ./git-file-branch.sh fn.cpp
prev=$(git rev-parse $(git rev-list -n1 --all -- $1)^)
for br in $(git branch -a | cut -c 3-); do
[ "x$(git rev-list -n1 --no-merges --first-parent $prev..$br -- $1)" != "x" ] && echo $br
done