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 / 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'
function s=TimeStamp
strcat(datestr(clock,'yyyy-mm-dd-HHhMM'),'m',datestr(clock,'ss'),'s')
@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);
@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 / 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 / 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 / parse-pcap-rtt.py
Last active December 7, 2017 10:25
A script for iterate pcap files in directories and calculate average RTT
#!/usr/bin/python
import os, sys
import subprocess
# argv[1] analysis directory
if len(sys.argv) == 1:
print """
- argv[1] analysis directory
#!/usr/bin/python
# Author: wh.sjtu@gmail.com
import os, sys
import subprocess
#
# Copy this script to the directory containing submission packages
# excute python ext_convt.py .
#
class Solution(object):
def containsNearbyAlmostDuplicate(self, nums, k, t):
"""
:type nums: List[int]
:type k: int
:type t: int
:rtype: bool
"""
if not nums:
return False
@chapter09
chapter09 / rsync.py
Created May 8, 2016 20:33
A python script for running rsync in parallel
#!/usr/bin/python
import os
import sys
import subprocess
import argparse
import re
import socket
# argv[1] host lists
# argv[2] source file/directory