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
# -*- coding: utf-8 -*- | |
import unittest | |
import xmlutils | |
from xml.dom import minidom | |
from collections import Mapping | |
def dict2element(root, structure, doc): | |
""" |
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
""" | |
This is my interface functionality implementation using abc | |
""" | |
import abc | |
from django.db import models | |
from django.contrib.contenttypes.models import ContentType | |
from django.contrib.contenttypes.generic import GenericForeignKey | |
class AbstractBase(): |
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 normalize_email(self, email): | |
""" | |
Normalazing email addres. An email address | |
has following properties: | |
1) It is case-insensitive | |
2) "." characters on username part of email address is ommited. | |
For instance foobar@gmail.com and foo.bar@gmail.com are the | |
same address. | |
3) Anything after "+" sign is ommited. foo@gmail.com and | |
foo+bar@gmail.com are same email address. |
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
""" | |
http://www.johndcook.com/blog/2012/01/14/roman-numeral-puzzle/ | |
Question - How many different roman characters consists of unique letters. | |
Range - 0 < number < 4000 | |
For roman numerals I followed the rules that explaind here | |
http://mathsyear7.wikispaces.com/Roman+Numerals | |
""" | |
from collections import OrderedDict | |
digit_representations = ['I', 'V', 'X', 'L', 'C', 'D', 'M'] | |
digit_mapping = OrderedDict([(9, 'oneten'), |
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
#!/usr/bin/env python2 | |
""" | |
My take on an adder function problem I found here | |
http://blog.jazzychad.net/2012/08/01/array-iteration-problem.html | |
""" | |
def add1(arr, val, n): | |
"""add1 - increments items in an array matching specified value | |
param: arr - array of integers to manipulate |
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
%%%------------------------------------------------------------------- | |
%%% @author Huseyin Yilmaz <huseyin@saturn.local> | |
%%% @copyright (C) 2013, Huseyin Yilmaz | |
%%% @doc | |
%%% | |
%%% @end | |
%%% Created : 9 Sep 2013 by Huseyin Yilmaz <huseyin@saturn.local> | |
%%%------------------------------------------------------------------- | |
-module(test). | |
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
from itertools import tee, chain, islice, imap | |
def add(x, y): | |
return x + y | |
def fibonacci(): | |
def deferred_output(): | |
for i in output: | |
yield i | |
result, c1, c2 = tee(deferred_output(), 3) |
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
# Test if python do any optimizations for inline dictionaries. (python 2.7) | |
# output of program : | |
# square1 = 0:00:07.711102 | |
# square2 = 0:00:00.527043 | |
from datetime import datetime | |
d = {'0': '0', | |
'1': '1', | |
'2': '4', |
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
""" | |
Generating all valid clauses of a CFG specified as BNF | |
Copied from here http://www.reddit.com/r/Python/comments/20x61y/share_the_code_youre_most_proud_of/ | |
""" | |
from itertools import chain, product | |
from re import match, findall | |
GRAMMAR = ''' | |
<sentence> ::= <noun phrase=""> <verb phrase=""> | |
<noun> ::= "boy " | "troll " | "moon " | "telescope " |
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
from collections import defaultdict | |
from collections import Counter | |
from itertools import izip | |
from itertools import islice | |
from operator import itemgetter | |
import datetime | |
import random | |
event_length = 1000000 | |
WIN_SIZE = 3 |