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

    Just do it

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

    1% of decisions aren't permanent

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

@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 +++++++------
# |
#!/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',
# 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.
#
@drmingdrmer
drmingdrmer / git-subrepo
Last active March 25, 2019 05:39
add/update git sub repository with git-subtree by reading a config file
#!/bin/sh
clr()
{
# clr light read blabla
local black=0
local white=7
@drmingdrmer
drmingdrmer / git-history-msg
Last active July 12, 2019 06:04
Batch replace word in commit messages with: git history-msg typo type origin/master..mydev_branch
#!/bin/sh
usage(){
cat <<-END
git history-msg <from> <to> <spec>
Replace word <from> to <to> in commit message.
Install:
copy it into /usr/local/bin/ or somewhere PATH env can find.
@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.