Skip to content

Instantly share code, notes, and snippets.

View piratus's full-sized avatar
💭
🏴‍☠️

Andrew Popovych piratus

💭
🏴‍☠️
View GitHub Profile
@piratus
piratus / pythonWith.scala
Created March 12, 2013 20:55
Just being impressed with Scala's DSL creation abilities
object With {
def apply[T <: { def enter(): T; def exit(): Unit}](obj:T)(block: (T) => Unit) {
obj.enter()
block(obj)
obj.exit()
}
}
class SomeClass {
def enter() = { println("enter"); this }
@piratus
piratus / words.py
Created February 9, 2012 15:52
Word value calculator
# coding: utf-8
"""Word value calculator.
Calculates word value as per http://9gag.com/gag/2506371
"""
from string import lowercase
LETTER_VALUES = {letter: index for index, letter in enumerate(lowercase, 1)}
def word_value(word):