Skip to content

Instantly share code, notes, and snippets.

-- Raymond Ho
-- 99 Haskell problems from: https://wiki.haskell.org/99_questions/1_to_10
-- 9/17/2015
module NinetyNineProblems where
--1
myLast :: [a] -> a
myLast [] = error "No end for empty lists"
@raymonstah
raymonstah / qs.js
Created September 16, 2015 22:04
Quicksort in JS using FP & Recursion
// Raymond Ho
// This small script is just to demonstrate some functional programming feautures of Javascript.
// Quicksort!
// Anon function helper, will return a random number.
var randomNumber = function() {
return Math.floor(Math.random()*101);
}
// Create an array of 100 random numbers.
@raymonstah
raymonstah / sleepsort.js
Created May 6, 2015 06:56
Sleep Sort in JavaScript (No Threads!)
// Raymond Ho
// JavaScript makes Sleep Sort so easy to implement..
// Exponentially slower if sorting larger numbers.
function sleepNumber(number) {
// The timeout is (n^2) so that close numbers are no longer close.
// Example: 1 is really close to 2, but 1^2 isn't close to 2^2.
setTimeout(function(){
console.log(number);
}, number*number);
@raymonstah
raymonstah / rent_split.py
Last active August 29, 2015 14:20
Got a total of who payed what and need to break it down to see who owes who? Use me!
# Raymond Ho
# May 5, 2015
# Note: Run me through the terminal.
# Sublime Text 2 won't successfully build b/c of Unicode errors.
import csv
import sys
@raymonstah
raymonstah / birthday.py
Created April 7, 2015 19:12
Birthday paradox / problem. In a room of 70 people, there's a 99.9% chance that there will be a pair with the exact same day of birth.
# In probability theory, the birthday paradox concerns the probability that,
# in a set of n randomly chosen people,
# some pair of them will have the same birthday.
# By the pigeonhole principle, the probability reaches 100% when
# the number of people reaches 367.
import random
# 365 distinct birthdays including February 29th.
print(''.join([chr(x) for x in [int(x,16) for x in \
[str(hex(2 * 2 * 5 * 7 * 37 * 149 * 5417 * 148781 \
* 51939996061871)[i:(i+2)])\
for i in range(25)][2::2]]]))
@raymonstah
raymonstah / redditrip.py
Created November 30, 2014 23:20
A reddit imgur ripper. Prevents downloading same files repeatedly if ran multiple times.
#!/usr/local/bin/python3
# Raymond Ho
# November 29, 2014
# Downloads imgur uploads from reddit and saves them in a new directory.
# Rerun every so often to download new pictures without downloading the
# same pictures multiple times. A text file keeps track of what has
# already been downloaded.
# Raymond Ho
# Oct 7, 2014
"""
Checks if the movie / TV show you've been waiting for is finally up on Netflix,
or if they have new seasons / episodes, whatever. Only works if Netflix updated
in the past two weeks.
"""
from urllib import request, parse # Used to generate URLs and open links
@raymonstah
raymonstah / montyhall.py
Created September 6, 2014 22:42
A Monty Hall Simulation. Try to win a car!
# Monty Hall Simulator
# Raymond Ho
# September 5th, 2014
# Run -> python montyhall.py
import random
def greet():
# Using the 'statement continuation character '\'
print "\nWelcome to the Monty Hall Simulator, created by Raymond Ho.\n" \