Skip to content

Instantly share code, notes, and snippets.

View jschaub30's full-sized avatar

Jeremy Schaub jschaub30

View GitHub Profile
@jschaub30
jschaub30 / gist:4f347c2be2145cc84157
Created April 8, 2015 19:15
R script to split columns from csv file
#!/usr/bin/Rscript
# Input: CSV file with headers
# x,y,z
# 1,2,3
# 4,5,6
# Output: CSV file
# Usage:
# ./split-columns.R [IN_CSV] [COLUMN NAMES]
# Example: ./split-columns.R in.csv x z
@jschaub30
jschaub30 / gist:ce65fc9f62ac1ab2bc50
Created April 8, 2015 20:00
Python script to split columns from csv file
#!/usr/bin/python
# Input: CSV file with headers, column names
# x,y,z
# 1,2,3
# 4,5,6
# Output: CSV file
# Usage:
# ./split-columns.py [IN_CSV] [COLUMN NAMES]
# Example: ./split-columns.py in.csv x z
import sys
@jschaub30
jschaub30 / csv2html.sh
Last active July 1, 2023 18:46
Bash script to convert a simple CSV file into an HTML table
#!/bin/bash
# Script to convert a *simple* CSV file into an HTML table
# Will fail if field data contains comma or newlines
#
# USAGE: bash csv2html.sh CSV_FN [BORDER_WIDTH] > OUTPUT_HTML_FN
usage (){
echo "USAGE: $0 CSV_FN [BORDER_WIDTH] > OUTPUT_HTML_FN"
echo "Examples:"
echo "$0 /tmp/input.csv > /tmp/output.html"
@jschaub30
jschaub30 / gist:ab44ce1be4d93a2603d1
Created April 29, 2015 15:07
Bash script to process file line by line
#!/bin/bash
# Input = CSV file with timestamp as 3rd field
# 1,2,Wed Apr 29 09:46:58 CDT 2015
# 3,4,Wed Apr 29 09:46:58 CDT 2015
# Converts timestamp to linux time
while read line
do
A=$(echo $line | cut -d, -f1-2)
D=$(echo $line | cut -d, -f3)
@jschaub30
jschaub30 / gen-random-graph.py
Created May 4, 2015 17:53
Python script to generate random edge list of graph based on nodes and edges
#!/usr/bin/python
import sys
import random
def main(argList):
if '-edges' in argList:
a = argList.index('-edges')
edges = int(argList[a+1])
@jschaub30
jschaub30 / gist:8d13e24422cccee13b6d
Last active August 29, 2015 14:21
R recursive function to write hierarchical data frame to json file with childen
# http://stackoverflow.com/questions/12818864/how-to-write-to-json-with-children-from-r
# example input
# year month size
# 2007 1 100
# ...
# 2007 12 850
# 2008 1 432
# ...
makeList <- function(x){
@jschaub30
jschaub30 / gist:a5f687a922c8c41baa64
Created May 15, 2015 23:01
Convert JSON to CSV in R
#https://www.kaggle.com/c/yelp-recruiting/forums/t/4116/convesio-of-json-files-to-csv-or-r-data-format
library(plyr)
library(RJSONIO)
con <- file('data.json', "r")
df <- ldply(fromJSON(con), data.frame)
close(con)
@jschaub30
jschaub30 / read_interrupts.sh
Created June 15, 2015 16:05
Bash script to read network interrupts in Ubuntu linux
#!/bin/bash
[[ $# -lt 1 ]] && echo Usage: $0 INTERFACE && exit 1
IFACE=$1
cat /proc/interrupts | grep "$IFACE-" | cut -d':' -f1 > tmp.interfaces
echo Reading affinity of $IFACE
for IRQ in $(cat tmp.interfaces)
@jschaub30
jschaub30 / set_interrupts.sh
Created June 15, 2015 16:15
Bash script to set network interrupts in Ubuntu linux
#!/bin/bash
[[ $# -lt 1 ]] && echo "Usage: $0 [INTERFACE] [RESET]" && exit 1
IFACE=$1
# Tweak the CPUSTART to fit your system
CPUSTART=32
[[ $IFACE == "eth2" ]] && CPUSTART=8
[[ $IFACE == "eth3" ]] && CPUSTART=16
[[ $IFACE == "eth4" ]] && CPUSTART=24
@jschaub30
jschaub30 / measure_io.sh
Last active August 29, 2015 14:23
Bash script to test sequential IO (read and write) and read IOPS using ioping utility
#!/bin/bash
# Test sequential IO (read and write) and read IOPS
# Creates CSV and HTML output
# Usegu: ./measure_io.sh [DIRECTORY]
CWD=$1
[ $# -lt 1 ] && CWD=$(pwd)
ioping -h 2> tmpfile
[ $? -ne 0 ] && echo ioping not found--"sudo apt-get install ioping" or download here: https://code.google.com/p/ioping/ && exit 1
rm tmpfile