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 / 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 = "[email protected]"
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
@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]
@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 / 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 / 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)