Skip to content

Instantly share code, notes, and snippets.

View hrbrmstr's full-sized avatar
💤
#tired

boB Rudis hrbrmstr

💤
#tired
View GitHub Profile
@hrbrmstr
hrbrmstr / commits.R
Last active December 27, 2015 10:29
github "timecard" heatmap in R
library(ggplot2)
library(plyr)
# need to run this in your project directory:
# git log --pretty=format:"%cd" | sed -e 's/\:/\ /' | \
# cut -f 1,4 -d\ | sort | uniq -c | \
# sed -e 's/^\ \ *//' > /tmp/timecard.out
base.df <- expand.grid(dow=c("Sun","Mon","Tue","Wed","Thu", "Fri","Sat"), hour=0:23)
base.df$dow <- factor(base.df$dow, levels=c("Sun","Mon","Tue","Wed","Thu", "Fri","Sat"))
@hrbrmstr
hrbrmstr / scadacs-us.R
Last active December 29, 2015 04:29
SCADA map in R inspired by http://www.scadacs.org/iram.htmlI
library(xml2)
library(stringr)
library(tidyr)
library(dplyr)
library(ggplot2)
library(ggthemes)
library(maptools)
library(sp)
# inspired by this SCADACS post: http://www.scadacs.org/iram.html
// booktracker.js
// by @hrbrmstr (2013)
// MIT license
//
// run this mongo query on the command line and redirect to a CSV file:
// $MONGO_BIN/mongo --quiet $DBNAME booktracker.js > $OUTPUT_LOCATION/book.csv
//
// stick it in the same cron job you have booktracker.py running
db.amzn.find({ }, { 'ItemLookupResponse.Items.Item.SalesRank' : 1,
@hrbrmstr
hrbrmstr / server.R
Last active December 29, 2015 14:09
Graphing Maine Power Outages With R/Shiny : Preview: http://162.243.111.4:3838/outages/
library(shiny)
library(maps)
library(maptools)
library(ggplot2)
library(plyr)
library(XML)
# Define server logic required to plot various variables against mpg
shinyServer(function(input, output, session) {
@hrbrmstr
hrbrmstr / index.html
Last active April 8, 2024 12:19
Graphing Maine power outages with D3. The "meta refresh" is the sub-optimal way of updating every 5 minutes, but the fam was getting a bit irked that I was coding on Thanksgiving. See previous gists and http://rud.is/b entries for why I made this. UPDATE : 2013-12-23 : mouseover now shows historical graphs of outages; data table cleaned up and t…
<!DOCTYPE html>
<!--
-- by @hrbrmstr (2013)
-- MIT License
-->
<html>
<head>
<title>Central Maine Power Live Outage Map</title>
<meta charset="utf-8"/>
<meta http-equiv="refresh" content="300"/>
@hrbrmstr
hrbrmstr / accidents.R
Last active December 29, 2015 17:49
Responding to the following LinkedIn question : https://www.linkedin.com/groups/Read-data-in-R-Hello-4066593.S.5812033094177271812 : about how to read a semi-ugly and semi-large file into R
# install.packages("data.table") # if you don't have it installed
library(data.table)
# download the file first since it's *huge* and we don't want to have to
# re-download it every time we work with it. comment this out after you
# read it in once or put an "if exists" wrapper around it to avoid
# re-downloading it from an errant script run. This assumes you have
# a "data"directory under your home directory; change destination
# as appropriate
@hrbrmstr
hrbrmstr / d3intro.html
Last active December 31, 2015 15:09
D3 introduction
<!DOCTYPE html>
<html>
<head>
<title>D3 Dots</title>
<script src="d3.v3.min.js" type="text/javascript" charset="utf8"></script>
<script src="jquery-1.10.2.min.js" type="text/javascript" charset="utf8"></script>
<script src="jquery-migrate-1.2.1.min.js" type="text/javascript" charset="utf8"></script>
@hrbrmstr
hrbrmstr / bheoutages.R
Created December 27, 2013 15:18
BHE county-level outage aggregation in R using point-in-polygon testing with county shapefiles. See this blog post for details: http://rud.is/b/2013/12/27/points-polygons-and-power-outages/
library(XML)
library(maptools)
library(sp)
library(plyr)
# Small script to get county-level outage info from Bangor Hydro
# Electric's town(-ish) level info
#
# BHE's outage google push-pin map is at
# http://apps.bhe.com/about/outages/outage_map.cfm
@hrbrmstr
hrbrmstr / tlds.py
Created January 5, 2014 23:47
script to process a file of hosts/domains into just TLDs using tldextract
#!/usr/bin/python
import tldextract
f = open("/tmp/indomains.txt")
hosts = f.readlines()
f.close()
tlds = ['.'.join(tldextract.extract(host.rstrip())[-2 : ]) for host in hosts]
@hrbrmstr
hrbrmstr / amsmeteors.py
Last active January 3, 2016 02:09
Get the amsmeteors.org observations <table> into CSV format (Python version)
import urllib2
from bs4 import BeautifulSoup
soup = BeautifulSoup(urllib2.urlopen("http://www.amsmeteors.org/observations/").read())
rows = soup.findChildren('table')[0].findChildren
for row in t[0].findAll('tr')[1:]:
col = row.findAll('td')