Skip to content

Instantly share code, notes, and snippets.

View manonthemat's full-sized avatar

Matthias Sieber manonthemat

View GitHub Profile
puts' ______________________________ '
puts'< What\'s wrong with this food? >'
puts' ------------------------------ '
puts' \ ^__^'
puts' \ (oo)\_______'
puts' (__)\ )\/\''
puts' ||----w |'
puts' || ||'
@manonthemat
manonthemat / base.hs
Created May 21, 2014 18:28
simple math fun with haskell - custom number base systems
import Data.Char (digitToInt)
numberToBaseString :: Int -> Int -> String
numberToBaseString n base
| n < base = show n
| otherwise = numberToBaseString ((n - (n `mod` base)) `div` base) base ++ show (n `mod` base)
baseStringToValue :: String -> Int -> Int
baseStringToValue n base
| n == [] = 0
@manonthemat
manonthemat / gist:9938961
Created April 2, 2014 17:32
Example of a simple algorithm with a running time that grows proportional to the input size
def find_max(data):
"""Return the maximum element from a nonempty Python list."""
biggest = data[0]
for val in data:
if val > biggest:
biggest = val
return biggest
@manonthemat
manonthemat / top_history.rb
Created November 18, 2013 03:48
function to sort a shell history file and print out the lines of commands that has been executed the most
def sortCommands(histFile, limit=10)
file = open(histFile, 'r')
lines = file.readlines
file.close
freqs = Hash.new(0)
lines.each do |line|
freqs[line] += 1
end
a = freqs.sort_by {|k, v| -v}[0..limit]
i = 0
import urllib2
import random
import difflib
import datetime
def fetch(url):
"""Fetches requested url, returns lines in list"""
response = urllib2.urlopen(url)
lines = response.readlines()
return lines