Skip to content

Instantly share code, notes, and snippets.

View mrkschan's full-sized avatar
😀

KS Chan mrkschan

😀
View GitHub Profile
@mrkschan
mrkschan / pre-commit
Created June 16, 2011 06:38
a pre-commit hook for git to remove trailing whitespace
#!/bin/sh
#
# A git hook script to find and fix trailing whitespace
# in your commits. Bypass it with the --no-verify option
# to git-commit
# Ref - http://is.gd/PerowD
#
if git rev-parse --verify HEAD >/dev/null 2>&1
then
@mrkschan
mrkschan / gist:1341335
Created November 5, 2011 09:52
Make ~/.bash_completion.d/ activated
# Put this snippets to .bash_rc :)
# enable bash completion in interactive shells
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
# Include ~/.bash_completion.d/
BASH_COMPLETION_COMPAT_DIR=~/.bash_completion.d
. /etc/bash_completion
fi
@mrkschan
mrkschan / tz.sh
Created April 11, 2012 09:01
a shortcut program to convert timezone
#!/bin/bash
# Usage: tz.sh from-timezone to-timezone time
# Example: tz.sh America/Los_Angeles America/New_York '2000-01-01 00:01:02'
from=$1
to=$2
if [[ "$3" == "" ]]; then
time=`date -R`
else
time=$3
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@mrkschan
mrkschan / urldecode.py
Created August 21, 2012 07:13
a shortcut program to decode URL
#!/usr/bin/env python
# Usage: urldecode.py url
import urllib
import sys
print urllib.unquote_plus(sys.argv[1])
@mrkschan
mrkschan / gist:3522031
Last active October 9, 2015 14:27
bash completion for git, with files and directory
#!bash
#
# Enable file/directory completion for git.
#
# bashref - http://is.gd/PHQRX1
# bashlib - http://code.google.com/p/bash-completion-lib/
have git && {
_git_completion()
{
@mrkschan
mrkschan / fakesmtp
Created October 3, 2012 09:22
A fake SMTP server (smtp-sink shortcut)
#!/usr/bin/env bash
sudo smtp-sink -R /tmp -u root -d "mail.%Y-%m-%dT%H%M." 127.0.0.1:25 1024
@mrkschan
mrkschan / gist:4077171
Created November 15, 2012 07:15
vim smartindent config for Python
" Smart indenting for Python
autocmd FileType python set smartindent
autocmd FileType python set cinwords=if,elif,else,for,while,try,except,finally,def,class
autocmd FileType python set tabstop=4
autocmd FileType python set shiftwidth=4
autocmd FileType python set expandtab
@brablc
brablc / postfix_grok_pattern
Last active September 27, 2020 20:10
Logstash example configuration for parsing Postfix mail log files
# Postfix stuff based on https://gist.github.com/jbrownsc/4694374:
QUEUEID (?:[A-F0-9]+|NOQUEUE)
EMAILADDRESSPART [a-zA-Z0-9_.+-=:]+
EMAILADDRESS %{EMAILADDRESSPART:local}@%{EMAILADDRESSPART:remote}
RELAY (?:%{HOSTNAME:relayhost}(?:\[%{IP:relayip}\](?::[0-9]+(.[0-9]+)?)?)?)
POSREAL [0-9]+(.[0-9]+)?
DELAYS (%{POSREAL}[/]*)+
DSN %{NONNEGINT}.%{NONNEGINT}.%{NONNEGINT}
STATUS sent|deferred|bounced|expired
@mrkschan
mrkschan / curld
Last active April 22, 2020 03:29
curl -v -k -s -o /dev/null -w 'remote_ip=%{remote_ip}, total=%{time_total}, dns=%{time_namelookup}, connect=%{time_connect}, appconnect=%{time_appconnect}, pretransfer=%{time_pretransfer}, redirect: %{time_redirect}, starttransfer: %{time_starttransfer}'