Skip to content

Instantly share code, notes, and snippets.

View msharp's full-sized avatar

max sharples msharp

  • Melbourne, Australia
View GitHub Profile

tmux cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@msharp
msharp / file_sampler.py
Last active August 29, 2015 14:01
File Sampler - sample every n rows from a file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
class FileSampler:
def __init__(self):
self.parse_args(sys.argv)
/*
Taken and cribbed from blog.datalicious.com/free-download-all-australian-postcodes-geocod
May contain errors where latitude and longitude are off. Use at own non-validated risk.
*/
SET NAMES utf8;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
DROP TABLE IF EXISTS postcodes_geo;
@msharp
msharp / boxen.py
Last active August 29, 2015 14:23
Box plots in 538 style
# Pylab BOXPLOTS in 538 style
import matplotlib.pyplot as plt
import itertools
def box_plot(boxes, figsize=(5,4), ymax=None, title=None, xlabels=[]):
def setBoxColors(bp):
colours = ["#30a2da","#6d904f","#8b8b8b","#fc4f30","#e5ae38"]
n_boxes = len(bp['boxes'])
fte = list(itertools.islice(itertools.cycle(colours), n_boxes))
@msharp
msharp / encodebase52
Created March 14, 2011 04:03
recursive base52 [a-Z] number encoding
function encode52(c) {
return (c < 52 ? '' : encode52(parseInt(c / 52))) + ((c = c % 52) > 25 ? String.fromCharCode(c + 39) : String.fromCharCode(c + 97));
};
@msharp
msharp / pingdom_downtime_calculator.rb
Created August 24, 2011 04:19 — forked from mattfitzgerald/gist:1167255
pingdom downtime calculator
def calculate_downtime_minutes
check_id = 387085
user = "alerts@admin.mysquawkbox.com"
pass = "***"
key = "***"
today = DateTime.now.to_date
last_sunday = today - today.wday
@msharp
msharp / public_key.pub
Created November 28, 2011 22:49
Public Key
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDjUroth5dd9SB+U8SuAKnmGgrDPeHGFFwqAXKeNJ+wht6mVXLipDs01eVii3a7Ibkalh2v45+KleiQoXXYhaLuvuq1KskGU7lv5bJUcQWicoBWh/OtrrzmWHlsesq1EDXjqDL0bgm2sQ+efO5G1qnBhwZ7PNXH6CHb8ayuySk8m4N0R/8Sn188LwAdFy2jgcAWuOM8wXACK41JaH38HwMsgrjIphCoxZbAYtufa+wkqztEs546wBk6vDJn46J432LhxXuN5TY9BV043qLQl3Y9RDkRk5Siq63a3vioKYWsqlxIbiN0FAae9S6Klg0pVZYDsJajyYycMIJlGvAx7AGt
@msharp
msharp / indentity_correction.rb
Created January 27, 2012 04:32
Convert 4-space indents to 2-space indents
#!/usr/bin/ruby
#########################
#
# Convert rubycode with 4-space indents
# to regulation 2-space indenting format.
#
# supply directory as argument:
# > ruby indentity_correction.rb ./my_code_dir
#
@msharp
msharp / Camelization.rb
Created February 16, 2012 23:55
Some functionas to camelize ruby hashes/objects for json output
# too much stuff to camelize the json object keys
# so that they are ready for the templates
def camelized(emp)
puts emp.inspect
if emp.is_a?(Array)
new = []
emp.each {|e| new << camelize_keys(e)}
else
new = camelize_keys(emp)
@msharp
msharp / markup.rb
Created August 6, 2012 07:24
markdown command wrapper
#!/usr/bin/ruby
require 'rubygems'
require 'github/markup'
if ARGV.length == 1
f = GitHub::Markup.render(ARGV[0])
puts f
else
raise "Usage: markup <source_file> [ > <destination_file> ]"
end