Skip to content

Instantly share code, notes, and snippets.

Richard Hsu richardhsu

Block or report user

Report or block richardhsu

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@richardhsu
richardhsu / 0_reuse_code.js
Last active Aug 29, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@richardhsu
richardhsu / plot99.py
Created Nov 11, 2014
Ping 99% Latencies
View plot99.py
#!/usr/bin/env python
import argparse
import datetime
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import numpy
import os
import re
@richardhsu
richardhsu / iperf.sh
Last active Dec 5, 2018
IPerf to send specific number of packets per second.
View iperf.sh
#!/bin/bash
PORT=50000
TIME=60
print_usage () {
echo "Usage: ./iperf.sh [-s|-c destination] [-h] [-p port] [-t time] -k total_packets_per_sec"
echo " -h|--help : Print usage."
echo " -s : Server mode which receives the data."
echo " -c : Client mode which sends the data. Requires destination."
@richardhsu
richardhsu / ping.sh
Last active Aug 29, 2015
Ping with timestamp and threshold.
View ping.sh
#!/bin/bash
COUNT=450
INTERVAL=2
THRESHOLD=5
print_usage () {
echo "Usage: ./ping.sh [-h] [-c count] [-i interval] [-t threshold] -d destination"
echo " -h|--help : Print usage."
echo " -c|--count : Number of pings to send. Default 450."
@richardhsu
richardhsu / backup.sh
Created May 31, 2014
Quick backup script to backup my minecraft server folder and potentially other folders to Dropbox.
View backup.sh
#!/bin/bash
# Backup folders to DropBox
# Add folder names relative to home directory.
# This file exists at the home directory level.
DATE=`date +%Y-%m-%d-%H-%M`
FOLDERS=("minecraft")
DROPBOX="/home/richardhsu/.dropbox/dropbox.py"
for dir in "${FOLDERS[@]}"
@richardhsu
richardhsu / git_log_first_email.sh
Created Apr 9, 2014
Bash script to pull git repositories, clone them, view log and grab the first email address seen.
View git_log_first_email.sh
#!/bin/bash
# Set up a repos.txt file that contains a list of all the repos
# one repo per line. Then create an emails.txt file which is where
# all the emails will go. It'll be a CSV file so you can verify.
# This is a quick hacky way to get emails, not sure if I covered all
# valid characters in regex but didn't need precision. Feel free to
# make it better!
reponame="https://github.com/[a-zA-Z0-9._-]+/([a-zA-Z0-9._-]+)$"
email="<([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.\w+)>"
@richardhsu
richardhsu / ssa_names_by_state.py
Created Jan 26, 2014
Request Page from SSA for Names By State with Python 3 and urllib.
View ssa_names_by_state.py
#!/usr/bin/env python3
import urllib.request
import urllib.parse
url = 'http://www.ssa.gov/cgi-bin/namesbystate.cgi'
post_data = {
'state': 'IL',
'year': '2012'
}
@richardhsu
richardhsu / send_post.py
Last active Dec 18, 2015
Submitting a JSON post request in Python with an `application/json` type.
View send_post.py
#!/usr/bin/env python
import json
import urllib, urllib2
# URL and Data to Send
url = 'http://localhost/api/table_name'
values = { 'user': 'username',
'count': 5,
'status': False }
@richardhsu
richardhsu / google_linechart_update.js
Created May 30, 2013
Google Charts LineChart example with updating.
View google_linechart_update.js
// Google Chart Visualization Playground's LineChart Example
function drawVisualization() {
// Create and populate the data table.
var data = google.visualization.arrayToDataTable([
['x', 'Data 1', 'Data 2', 'Data 3'],
[1, 1, 1, 0.5],
[2, 2, 0.5, 1],
[3, 4, 1, 0.5],
[4, 8, 0.5, 1],
[5, 7, 1, 0.5],
@richardhsu
richardhsu / so_xml2sql.py
Created Dec 13, 2012
XML to SQL converter for Stack Overflow XML data dump files. For newer versions of MySQL you can use the LOAD XML and it can work out but for older versions this script can help.
View so_xml2sql.py
#!/usr/bin/env python
""" Stack Overflow XML 2 SQL
The following is a custom made XML 2 SQL converter for Stack Overflow data.
Latest Stack Overflow Data: August 2012
Call Examples:
You can’t perform that action at this time.