Skip to content

Instantly share code, notes, and snippets.

View chapter09's full-sized avatar
πŸš€
Focus

Hao Wang chapter09

πŸš€
Focus
View GitHub Profile
@chapter09
chapter09 / p-ifconfig.py
Last active August 29, 2015 14:06
Change IP and Routing Table in parallel
#!/usr/bin/python
import os, sys
import subprocess
procs = []
with open(sys.argv[1], 'r') as f:
for line in f.readlines():
if line.find("host1") > -1:
@chapter09
chapter09 / spark-submit-log-to-file
Last active August 29, 2015 14:02
Save Spark console log to file
import subprocess
with open("stdout.txt","wb") as out, open("stderr.txt","wb") as err:
subprocess.Popen("ls",stdout=out,stderr=err)
@chapter09
chapter09 / Shrink reference.bib
Last active August 29, 2015 14:02
compress reference.bib by leaving only one author on the list
import os, sys
import re
in_fd = open('reference.bib', 'r')
out_fd = open('test.bib', 'a')
p = '\{(.*)\}'
for line in in_fd.readlines():
if line.find('author') > -1 or line.find('AUTHOR') > -1:
@chapter09
chapter09 / xTickLabel Roation
Created January 18, 2014 06:13
this snippet is used for rotating x axis labels
XTickLabel = get(gca,'XTickLabel');
set(gca,'XTickLabel',' ');
hxLabel = get(gca,'XLabel');
set(hxLabel,'Units','data');
xLabelPosition = get(hxLabel,'Position');
y = xLabelPosition(2);
XTick = get(gca,'XTick');
y=repmat(y,length(XTick),1);
fs = get(gca,'fontsize');
hText = text(XTick, y, ... XTickLabel,'fontsize',fs);
function s=TimeStamp
strcat(datestr(clock,'yyyy-mm-dd-HHhMM'),'m',datestr(clock,'ss'),'s')
@chapter09
chapter09 / api_client_for_amypi.py
Last active December 27, 2015 06:08
AmyPI Client for GET
# coding=utf-8
import httplib, urllib, json
import locale, datetime
import base64, hmac
from hashlib import sha1
gid = 'sh600580'
apihub_key = 'YSBYsT2nNVBNykK1'