Skip to content

Instantly share code, notes, and snippets.

View jessex's full-sized avatar

Joshua Essex jessex

View GitHub Profile
@jessex
jessex / convert.py
Created July 10, 2012 04:23
Blog snippets: shrtn
def convert_to_code(id, alphabet=ALPHABET):
"""Converts a decimal id number into a shortened URL code. Use the id of the
row in the database with the entered long URL."""
if id <= 0: #invalid codes (autoincrement is always 1 or higher)
return alphabet[0]
base = len(alphabet) #base to convert to (56 for our standard alphabet)
chars = []
while id:
chars.append(alphabet[id % base])
@jessex
jessex / hn_email.rb
Created July 10, 2012 04:06
Hacker News to Email
#!/usr/local/bin/ruby -rubygems
require 'open-uri'
require 'json'
require 'pony'
class Headline
def initialize(title, title_url, points,
comments, comments_url, time, time_units)
@title = title
@jessex
jessex / bash1
Created April 2, 2012 05:20
HaltPy HaltPy
$ ./halt.py principia.py
False
$ oh gosh
i know
@jessex
jessex / Jmad.txt
Created September 5, 2011 19:08
Cool Madison: Past and Present
____
/(( )) /
( )6 -( ) /
(_) l (_) /
\ <> )
) (
.----\""/----.
| \/ |
| | . | |
| | . | |____/__
@jessex
jessex / counter.sh
Created June 14, 2011 17:55
Count all lines of code for java source files in current directory
find . -name '*.java' | xargs wc -l
@jessex
jessex / EulerProblem029.scala
Created March 4, 2011 18:46
Euler Problem 029
//Maps all a^b terms for lower <= b <= upper to all a for lower <= a <= upper
def getDistinctCount(lower:Int, upper:Int) = {
(lower to upper).flatMap(a => (lower to upper).map(b => BigInt(a).pow(b)))
.distinct.size //Return number of distinct elements
}
println(getDistinctCount(2, 100))