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-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
@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-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 / 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-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
  1. 只管去做。

    Just do it

  2. 1%的决策,都可以更改。

    1% of decisions aren't permanent

  3. 招人要慎重,解雇要快速。

#!/usr/bin/env python2.6
# coding: utf-8
import types
# DOUBLE_LINE_MAP = [ u'\u2800\u2880\u28a0\u28b0\u28b8',
# u'\u2840\u28C0\u28E0\u28F0\u28F8',
# u'\u2844\u28C4\u28E4\u28F4\u28FC',
@drmingdrmer
drmingdrmer / git-box
Last active December 11, 2023 13:57
watch and auto fetch/rebase/merge/push git-repo.
#!/bin/bash
# Usage:
# 1. create config file ~/.gitbox.conf
#
# cat ~/.gitbox.conf
# ~/xpkit fetch,push
# ~/wiki
#
# # format:
@drmingdrmer
drmingdrmer / git-gotofix
Last active December 15, 2019 08:20
git-gotofix: go back to an earlier commit in which <fn> is modified.
#!/bin/sh
usage()
{
cat >&2 <<-END
usage: git gotofix <fn>
Fix <fn> at the commit where <fn> is lastly modified.
And get HEAD back to where before using git-gotofix.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#