Skip to content

Instantly share code, notes, and snippets.

View msimpson's full-sized avatar

Matthew Simpson msimpson

View GitHub Profile
@msimpson
msimpson / tip.rb
Created August 20, 2011 03:03
Tip Calculator
#!/usr/bin/env ruby
# Tip Calculator
# Usage: ./tip <cost> <minutes_waited> [percent]
exit if ARGV.length < 2
cost = ARGV[0].to_f.round(2)
minutes = ARGV[1].to_i
percent = !ARGV[2].nil? ? ARGV[2].to_f / 100.0 : 0.2
@msimpson
msimpson / poker
Created July 24, 2011 03:28
A library to rank and compare poker hands.
#!/usr/bin/env ruby
# encoding: UTF-8
# - Poker -
# A library to rank and compare poker hands.
module Poker
ACE = 14
KING = 13
QUEEN = 12
@msimpson
msimpson / miller_rabin
Created July 23, 2011 20:03
An implementation of the Miller Rabin Primality Test
#!/usr/bin/env python
import random
def MillerRabinPT(n,k=100):
n = int(n)
if n<2: return False
if n==2 or n==3: return True
if not n%2: return False
@msimpson
msimpson / numconv
Created July 23, 2011 19:43
Convert an integer into a spoken number.
#!/usr/bin/env python
# Number to name convertion.
import sys
n = (sys.argv[1] if sys.argv[1].isdigit() else 0) if len(sys.argv)>1 else 0
if len(n)>30:
print("Error: Number too large.")
sys.exit(1)
@msimpson
msimpson / raid5
Created July 23, 2011 19:32
A simple script to demonstrate how Raid 5 uses parity to recover data.
#!/usr/bin/env ruby
$drives = {
:a => 'Example 1.',
:b => 'abcdefghijklmnopqrstuvwxyz',
:c => '0123456789',
:d => '3.14159265',
:parity => ''
}
@msimpson
msimpson / define
Created July 21, 2011 10:55
Google definition (this method is frowned upon by Google, use for educational purposes only).
#!/usr/bin/env ruby
# Define: a Google Dictionary API tool
require "rubygems"
require "net/http"
require "json"
if not ARGV[0]; exit; end
query = ARGV.join("+").gsub(" ","+")
@msimpson
msimpson / matrix
Created July 21, 2011 11:00
Send the Matrix message to someone's terminal (great for scaring ssh users).
#!/bin/bash
[ ! "$1" ] && {
echo "Usage: matrix <pts-number>"
echo "Grabs control of a terminal and sends the Matrix message."
echo
echo "Choose a pts number:"
echo -e "Number\tUser\tName"
ps aux | awk '/pts\// && /bash/ {print $7":\t("$1")\t"$11}'
exit
}
/*!
* jQuery Mousewheel 3.1.12
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*/
(function (factory) {
if ( typeof define === 'function' && define.amd ) {