Skip to content

Instantly share code, notes, and snippets.

View huseyinyilmaz's full-sized avatar

Huseyin Yilmaz huseyinyilmaz

  • Balikesir, Turkey
View GitHub Profile
"""
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
@huseyinyilmaz
huseyinyilmaz / fabfile.py
Created September 11, 2014 11:12
Run part of the fabric script sequentially (failed)
from fabric.api import env
# from fabric.api import serial
from fabric.api import task
from fabric.api import run
from fabric.task_utils import state
env.hosts = ['addv3.redbeacon-inc.com', 'addv4.redbeacon-inc.com']
env.parallel = True
@huseyinyilmaz
huseyinyilmaz / question1.py
Created September 11, 2014 16:56
Algorithms 1 week 1 exercise 2
"""
The theoretical order-of-growth is N ^ (29/12) = 2.42
The empirical order-of-growth is N ^ (log_2 ratio)
log_2
N seconds ratio ratio
---------------------------------------
256 0.000 - -
512 0.001 - -
-module("folding_funs").
-export([transform_something/1]).
transformations() ->
[fun trans1/1, fun trans2/1, fun trans3/1].
transform_something(A) ->
lists:foldl(fun(Fun, Acc) -> Fun(Acc) end, A, transformations()).
@huseyinyilmaz
huseyinyilmaz / debug.py
Created December 24, 2014 13:36
Code that prints all http requests
import httplib
def patch_send():
if hasattr(httplib, 'is_patched'):
print 'httplib is already patched'
return
httplib.is_patched = True
"""
Inner function performance test
Result:
direct call = 0.335001945496
with wrapper = 0.700292110443
"""
@huseyinyilmaz
huseyinyilmaz / compile_publicator.sh
Last active August 29, 2015 14:16
compile_publicator.sh
#!/bin/bash
# -*- tab-width:4;indent-tabs-mode:nil -*-
# ex: ts=4 sw=4 et
#
# This script downloads and compiles publicator
#
# USAGE:
# To build master branch:
# $ ./compile_publicator.sh
# To build specific tag provide tag number as argument
@huseyinyilmaz
huseyinyilmaz / file_index.erl
Last active August 29, 2015 14:21
Functional_programming_with_erlang week 1 and week 2
-module(file_index).
-export([clean/1]).
-export([getWord/1]).
-export([tokenize/1]).
-export([get_line/1]).
-export([enumerate/1]).
-export([parse_string/1]).
-export([invert/1]).
-export([get_sequence/2]).
@huseyinyilmaz
huseyinyilmaz / funs.erl
Last active August 29, 2015 14:21
Functional_programming_with_erlang week 3
-module(funs).
-export([compose/1]).
-export([twice/1]).
-export([iteration/1]).
-export([make_list/2]).
-include_lib("eunit/include/eunit.hrl").
compose(Funs)->
fun(Arg) ->