This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compress(s): | |
""" | |
s -> string to be compressed | |
retuns -> compressed string | |
""" | |
if not s: | |
return "" | |
prev = None | |
count = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TrieNode(object): | |
""" | |
Trie Node | |
""" | |
def __init__(self,key): | |
self._key = key | |
self._value = None | |
self._children = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
class MyDataStructure(object): | |
def __init__(self): | |
self.d = {} # hash table | |
self.li = [] # dynamic resizing array | |
def insert(self, key): | |
if key in self.d: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import abc | |
class AbstractV(object): | |
__metaclass__ = abc.ABCMeta | |
def __init__(self, **kwargs): | |
for k, v in kwargs.iteritems(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
# needed for casting PyCObject to void pointer | |
from ctypes import pythonapi, c_void_p, py_object | |
from PySide.QtCore import * | |
from PySide.QtGui import * | |
import gobject | |
import pygst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import simplegui | |
import random | |
class Direction(object): | |
UP, DOWN, LEFT, RIGHT = range(4) | |
class GameState(object): | |
RUNNING, FINISHED = range(2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main = lift clock (every second) | |
number n = let angle = degrees (90 - 6 * (n * 5)) | |
in move (100 * cos angle, 100 * sin angle) (toForm (asText n)) | |
displayNumbers = group (map number [1..12]) | |
clock t = collage 400 400 [ outlined (solid blue) (circle 110) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Using folds version | |
import Data.List | |
import Data.Maybe | |
letters = "acdegilmnoprstuw" | |
getIndexOf :: Char -> String -> Int | |
getIndexOf x xs = fromMaybe (-1) (elemIndex x xs) | |
hashacc :: Int -> Char -> Int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
## Typical Usage: | |
## python parse_transalations.py 'path/to/messages.po' | |
## This prints the strings and their respective translations | |
def clean(s): | |
""" Quick and dirty scrubbing of the data """ | |
return s.replace('"', '').replace('msgid ', '').replace('msgstr ', '') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fancy_sort(countries): | |
""" countries -> list of countries """ | |
sorted_countries = [(-1 * len(x[1]) if x[0] % 2 else len(x[1]), x[1]) | |
for x in enumerate(sorted(countries, key=len))] | |
return [x for x in sorted(sorted_countries, key=lambda x: x[0])] | |
countries = ['Afghanistan', 'Albania', 'Algeria', 'Andorra', 'Angola', 'Antigua & Deps', 'Argentina', 'Armenia', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bhutan', 'Bolivia', 'Bosnia Herzegovina', 'Botswana', 'Brazil', 'Brunei', 'Bulgaria', 'Burkina', 'Burundi', 'Cambodia', 'Cameroon', 'Canada', 'Cape Verde', 'Central African Rep', 'Chad', 'Chile', 'China', 'Colombia', 'Comoros', 'Congo', 'Congo {Democratic Rep}', 'Costa Rica', 'Croatia', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'East Timor', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia', 'Fiji |
NewerOlder