Skip to content

Instantly share code, notes, and snippets.

@hydra35
hydra35 / parse_bash_history.rb
Created August 15, 2012 04:07
parse raw bash histroy
file = ARGV[0]
File.readlines(file).each do |line|
if /^#(\d+)/.match(line)
ts = Regexp.last_match(1)
print Time.at(ts.to_i).to_s + " "
else
puts line
end
end
@hydra35
hydra35 / create_gw.sh
Created August 24, 2012 03:28
create NAT gateway on OSX
#!/bin/bash
# Get the interface name for the gateway
gwdev=`netstat -nr | grep default | awk '{ print $6 }' | head -1`
# If none are found, set the gateway to en1 (generally Wifi on OS X)
if [ -z "$gwdev" ]; then
gwdev=en1
fi
@hydra35
hydra35 / destroy_gw.sh
Created August 24, 2012 03:28
destroy NAT gateway on OSX
#!/bin/bash
# All these steps look excessive but address
# network instability issues created by not doing them
gwdev=`netstat -nr | grep default | awk '{ print $6 }' | head -1`
if [ -z "$gwdev" ]; then
gwdev=en1
fi
@hydra35
hydra35 / create_eimg_grub1.sh
Created September 14, 2012 13:33
create grub1 empty image
#!/bin/bash
tarball=$1
output_img=$2
size=$3
check_tarball() {
if [[ ! -s $tarball ]]; then
echo "tarball: $tarball not found" >&2
fi
@hydra35
hydra35 / show_aspath.sh
Created September 21, 2012 14:53
lookup traceroute result using bgp.he.net
#!/bin/bash
lookup_single_ip() {
local ip=$1; shift
# 从bgp.he.net获取AS信息. e.g., <td>CHINANET Shanghai province network</td>
local data=$(curl -L http://bgp.he.net/ip/$ip 2>/dev/null | grep -A 30 'Announced By' | egrep '^\s*<td>.*</td>\s*$' | egrep -v 'AS[0-9]*</a>' | uniq)
# 从<td>标签中取值. e.g., CHINANET Shanghai province network
Lookup_single_ip=$(echo $data | awk -F '<' '{print $2}' | awk -F '>' '{print $2}')
}
@hydra35
hydra35 / list_kthread.sh
Created January 15, 2013 11:28
Show me kernel threads(CentOS 6)
ps auwx | grep -E '\[.*\]' | grep -v grep | awk '{print $NF}' | awk -F/ '{print $1}' | sed 's/\[//g' | sed s'/\]//g' | sort | uniq | sort
#!/bin/bash
if [ $# -lt 3 ];then
echo "usage: $pid $key $value"
exit 1
fi
pid=$1
key=$2
value="${3}ll"
@hydra35
hydra35 / nginx.conf
Last active May 14, 2021 03:51
to gray, for Ya'An, Si Chuan earthquake
# 1. Make sure you have nginx sub module compiled in
# nginx -V 2>&1 | grep --color=always '\-\-with\-http_sub_module'
# 2. add two directives below at HTTP level
# nginx.conf
http {
# ......
sub_filter '</head>' '<style type="text/css">html{ filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); -webkit-filter: grayscale(100%); filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale"); /* Firefox 10+, Firefox on Android */
@hydra35
hydra35 / gfw.txt
Created May 1, 2013 16:03
翻墙的域名
t.co
j.mp
twitter.com
google*
w32tm /config /update /manualpeerlist:121.9.243.170
w32tm /resync