Skip to content

Instantly share code, notes, and snippets.

@richardhsu
richardhsu / 0_reuse_code.js
Last active August 29, 2015 14:18
Here are some things you can do with Gists in GistBox.
// 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 November 11, 2014 22:43
Ping 99% Latencies
#!/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 September 24, 2023 05:25
IPerf to send specific number of packets per second.
#!/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 August 29, 2015 14:08
Ping with timestamp and threshold.
#!/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 21:50
Quick backup script to backup my minecraft server folder and potentially other folders to Dropbox.
#!/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 April 9, 2014 09:30
Bash script to pull git repositories, clone them, view log and grab the first email address seen.
#!/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 January 26, 2014 19:15
Request Page from SSA for Names By State with Python 3 and urllib.
#!/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 December 18, 2015 22:29
Submitting a JSON post request in Python with an `application/json` type.
#!/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 06:36
Google Charts LineChart example with updating.
// 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 December 13, 2012 07:05
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.
#!/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: