Skip to content

Instantly share code, notes, and snippets.

Avatar

Shichao An shichao-an

View GitHub Profile
@shichao-an
shichao-an / prt.sh
Created Aug 22, 2014
Print routing table with netstat on FreeBSD/OS X
View prt.sh
#!/bin/bash
netstat -nr -f inet
@shichao-an
shichao-an / pln.sh
Created Aug 25, 2014
Print LAN nodes
View pln.sh
#!/bin/bash
# Works on OS X
ping -c 2 -i 2 255.255.255.255 | awk ' $4 ~ /[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/{print $4}' \
| sed 's/\(.*\):/\1/g' | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4
@shichao-an
shichao-an / comp1.sh
Created Aug 28, 2014
Compare the first column by tab as field separator of the two files
View comp1.sh
#!/bin/bash
diff <(awk -v FS='\t' '{ print $1 }' a1.txt) <(awk -v FS='\t' '{ print $1 }' a2.txt)
@shichao-an
shichao-an / purge_mysql.sh
Created Aug 28, 2014
Purge MySQL on Ubuntu
View purge_mysql.sh
#!/bin/bash
dpkg -l | grep mysql | awk '{ print $2 }' | xargs -I {} apt-get purge -y {}
@shichao-an
shichao-an / create_gitmodules.sh
Last active Aug 29, 2015
Create .gitmodules from a list of GitHub repo URLs
View create_gitmodules.sh
cat bundle.txt | xargs -I {} bash -c 'name={}; printf "[submodule \".vim/bundle/%s\"]\n\tpath = .vim/bundle/%s\n\turl = %s\n\n" ${name##*/} ${name##*/} $name' > .gitmodules
@shichao-an
shichao-an / list_at_jobs.sh
Last active Aug 29, 2015
List one-liner commands in "at" job queue
View list_at_jobs.sh
#!/bin/bash
# Result:
# job_id date command
atq | awk '{ printf("%s %s %s %s %s ", $1, $5, $3, $4, $6); \
system("at -c "$1"| tail -2 | head -1"); }'
@shichao-an
shichao-an / escape_bre.sh
Created Sep 8, 2014
Escape string for BRE
View escape_bre.sh
#!/bin/sh
escape() {
local raw="$1"
local quoted=$(printf %s "$raw" | sed 's/[][()\.^$?*+]/\\&/g')
echo "$quoted"
return 0
}
@shichao-an
shichao-an / request_exceptions.py
Created Sep 10, 2014
Custom exception example from requests
View request_exceptions.py
class RequestException(IOError):
"""There was an ambiguous exception that occurred while handling your
request."""
def __init__(self, *args, **kwargs):
"""
Initialize RequestException with `request` and `response` objects.
"""
response = kwargs.pop('response', None)
self.response = response
View pycurl_download_progress.py
import pycurl
import sys
from humanize import naturalsize
import time
START_TIME = None
@shichao-an
shichao-an / 115wangpan-dl.py
Last active Aug 29, 2015
Utility script for 115wangpan
View 115wangpan-dl.py
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 expandtab softtabstop=4 smarttab textwidth=78
from __future__ import print_function
import os
import sys
from u115 import API, File, Directory
ARGV = sys.argv
GLOB_ALL = False
You can’t perform that action at this time.