Skip to content

Instantly share code, notes, and snippets.

View msharp's full-sized avatar

max sharples msharp

  • Melbourne, Australia
View GitHub Profile
@msharp
msharp / aws-lambda-unzipper.py
Created February 6, 2017 22:52
unzip archive from S3 on AWS Lambda
import os
import sys
import re
import boto3
import zipfile
def parse_s3_uri(url):
match = re.search('^s3://([^/]+)/(.+)', url)
if match:
return match.group(1), match.group(2)
#############################
#
# Appends the camera model,
# extracted from the EXIF data
# to the file name.
#
# RAW file support comes via
# a Perl command-line tool
# called `exiftool`
#
@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))
/*
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 / 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)

tmux cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@msharp
msharp / FileSplitter.py
Last active August 25, 2023 04:33
python script to split a (large) file into multiple (smaller) files with specified number of lines
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
class FileSplitter:
def __init__(self):
self.parse_args(sys.argv)
@msharp
msharp / normal-probability.py
Created April 23, 2013 08:33
command-line app to calculate probabilities from a normal distribution. uses scipy.stats for calculations
#!/usr/bin/python
import sys
import os
import math
import scipy.stats
normal_distribution_calculations =[
(1, "Probability that score is less than x (area below)", ["Enter score: "], lambda dist,score: dist.cdf(score)),
(2, "Maximum score to satisfy Pr(x) (area below)", ["Enter probability: "], lambda dist,prob: dist.ppf(prob)),
(3, "Probability that score is more than x (area above)", ["Enter score: "], lambda dist,score: dist.sf(score)),
@msharp
msharp / aliases
Created February 7, 2013 03:04
Add an alias to your aliases to list your aliases. Works for bash & zsh, probably other shells too.
alias aliases="egrep '^[^#$ ]' $0 | sed -E 's/^alias ([^=]+)=/\1 => /g' | sort"
@msharp
msharp / android_lockscreen_permutations.rb
Created October 9, 2012 03:16
Calculate how many permutations there are for the Android pattern lock-screen
NODES = {
1 => [2,4,5],
2 => [1,3,4,5,6],
3 => [2,5,6],
4 => [1,2,5,7,8],
5 => [1,2,3,4,6,7,8,9],
6 => [2,3,5,8,9],
7 => [4,5,8],
8 => [4,5,6,7,9],
9 => [5,6,8]