Skip to content

Instantly share code, notes, and snippets.

@cronin101
cronin101 / cheat.md
Last active December 25, 2015 10:59
Cheating with friends

#Cheating at 'scramble with friends'

Just to prove a point, horrible python but hacked together so excusable. Scored 800 points in a test round.

(ENV)λ  Python git:(master) ✗ time python scramble.py
Please enter line 1 delimited by spaces:
o e s e
Please enter line 2 delimited by spaces:
y s r u
@cronin101
cronin101 / profile.sh
Last active December 25, 2015 01:09
How2profile
#!/usr/bin/env sh
python -m cProfile -o $1.prof $1.py
gprof2dot -f pstats -o $1.dot $1.prof
dot -o $1.png -Tpng $1.dot
echo "Open $1.png to view."
@cronin101
cronin101 / bees.py
Created October 5, 2013 13:18
More tests
from tokenize import StringTokenizer
from tfidf import TFIDFScorer
import unittest
class TestTFIDFScorer(unittest.TestCase):
def test_C_constant(self):
'''C should be set equal to the number of documents in the collection'''
def tokenize(line): return StringTokenizer(line)
document_lines = [
@cronin101
cronin101 / errday_im_testing.py
Created October 5, 2013 12:05
wow, such reliability, much coverage
from tokenize import StringTokenizer
from overlap import OverlapScorer
import unittest
class TestOverlapScorer(unittest.TestCase):
def test_no_overlaps(self):
'''Queries share no words with documents so the scores should be 0'''
query_lines = [
'1 How to roll up pants?',
'2 How r babby formed?',
@cronin101
cronin101 / pubkey
Created October 1, 2013 14:17
pub key
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCwCOLe9uVcvLLP6d7RElk7wHSoDxqoDcbiMcfQqtufGhzO8+UgpC2AcZXyS3TYLgw3Ebf6/O8po+wUWJJp3l4FzFqqg/PuODFQ/aUOWBe5m050jSp7SRgDK8dXNm3XOITeJQ7tIBUJMMgQ2kFlZ5A+DOzHa2gYyY44u3gB5AZ4CL5XeCSb0+2DsAwM26XtsGIz7YJv19GaUlA2ocFYLwEOhyvdzftngCiT35oDlIiiBlx0snuwVrcH6aLizDnLgYfrpRNpSa35ApL9MKiv+S61ZLVoPy7RISp1aj5hLpmUMCHh/PlOwtikRXH527ry0nCppWsULm94ayjDBYq65vn cronin@espeon
@cronin101
cronin101 / labweekchess.hs
Created September 23, 2013 13:17
Functional programming beginners lab, exercises from 'Haskell: The Craft of Functional Programming'
-- Informatics 1 - Functional Programming
-- Lab week tutorial part II
--
--
import PicturesSVG
import Test.QuickCheck
import Control.Monad
data PieceColour = Black | White
@cronin101
cronin101 / labweekexercise.hs
Last active December 23, 2015 17:29
Any example of how not to complete a first-year Haskell lab.
-- Informatics 1 - Functional Programming
-- Lab Week Exercise
--
-- Week 2 - due: Friday, Oct. 1, 5pm
--
-- Insert your name and matriculation number here:
-- Name: Willip Fodler
-- Nr. : 01
@cronin101
cronin101 / largest_slice.hs
Last active December 23, 2015 06:19
Finding the slice of an input array that has the largest total
import Data.List
data SummedIntList = SummedIntList {
listElements :: [Int],
elementTotal :: Int
} deriving (Show)
emptySummedList = SummedIntList [] 0
addIntToList (SummedIntList xs t) x = SummedIntList (xs ++ [x]) (t + x)
@cronin101
cronin101 / YOQO.rb
Created September 2, 2013 23:24
You only qux once
main ⭔ define_method :qux_it!, ->{ ->{ define_method :qux_it!, ->{ raise "Already quxxed it bro" } }.() && "Quxxing the foo-bar" }
#=> #<Proc:0x007fb75035b1f0@(pry):24 (lambda)>
main ⭔ qux_it!
#=> "Quxxing the foo-bar"
main ⭔ qux_it!
#RuntimeError: Already quxxed it bro
#from (pry):24:in `block (3 levels) in __pry__'
main ⭔ qux_it!
#RuntimeError: Already quxxed it bro
#from (pry):24:in `block (3 levels) in __pry__'
@cronin101
cronin101 / one_way.rb
Created September 2, 2013 23:22
Trapdoor method
main ⭔ define_method :secret_message, ->{ ->{ define_method :secret_message, ->{ "Too late" } }.() && "I hope you remember this" }
#=> #<Proc:0x007fb74ad90f68@(pry):21 (lambda)>
main ⭔ secret_message
#=> "I hope you remember this"
main ⭔ secret_message
#=> "Too late"