Skip to content

Instantly share code, notes, and snippets.

View huseyinyilmaz's full-sized avatar

Huseyin Yilmaz huseyinyilmaz

  • Balikesir, Turkey
View GitHub Profile
@huseyinyilmaz
huseyinyilmaz / xmlutils.py
Last active November 26, 2020 12:19
Convert python dictionary to xml
# -*- coding: utf-8 -*-
import unittest
import xmlutils
from xml.dom import minidom
from collections import Mapping
def dict2element(root, structure, doc):
"""
@huseyinyilmaz
huseyinyilmaz / abc_interface_models.py
Created January 4, 2012 11:40
Sample Interface implementation in python
"""
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():
@huseyinyilmaz
huseyinyilmaz / normalize_email.py
Created January 10, 2012 08:06
Normalize email
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.
@huseyinyilmaz
huseyinyilmaz / roman_puzzle.py
Created January 17, 2012 12:52
Roman number puzzle solution
"""
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'),
#!/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
@huseyinyilmaz
huseyinyilmaz / test.erl
Last active December 22, 2015 16:08
Tested if erlang can handle to open 10 million concurent erlang processes and close them. (It does not work in 32bit compilations because of 4GB limit.)
%%%-------------------------------------------------------------------
%%% @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).
@huseyinyilmaz
huseyinyilmaz / fib.py
Created September 18, 2013 11:08
corecursive fibonacci (source: http://en.wikipedia.org/wiki/Corecursion)
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)
@huseyinyilmaz
huseyinyilmaz / dict_optimization_test.py
Created September 19, 2013 14:49
Test if python do any optimizations for inline dicionaries.
# 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',
"""
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 "
@huseyinyilmaz
huseyinyilmaz / common.py
Created July 13, 2014 10:09
most_common subsequence search
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