Skip to content

Instantly share code, notes, and snippets.

View lukmdo's full-sized avatar
:octocat:
loading...

Lukasz Dobrzanski lukmdo

:octocat:
loading...
View GitHub Profile
@lukmdo
lukmdo / m.py
Last active February 2, 2018 22:09
meta without __metaclass__ (by inheritance)
from __future__ import print_function
from functools import wraps
class Fish(object):
def __new__(cls, *args, **kwargs):
o = super(Fish, cls).__new__(cls, *args, **kwargs)
o.foo_cache = {}
o.type = 'goldfish'
@lukmdo
lukmdo / mc_a.py
Last active August 29, 2015 14:23
"""
FIND MOST COMMON ELEMENT IN LIST
- what is "most common"
- restrictions
- list properties
- tests?
"""
def solution(items):
def test_solution():
assert solution([]) == None
assert solution([1]) == 1
assert solution([1, 2]) == None
assert solution([1, 2, 3]) == None
assert solution([1, 2, 1]) == 1
assert solution([1, 2, 1, 2]) == None
if __name__ == "__main__":
def solution(items):
if not items:
return
best = None
best_count = 0
current_count = 0
last = items[0]
for current in items:
def solution(items):
if not items:
return
count = 0
best = None
for n in items:
if count == 0:
best = n
@lukmdo
lukmdo / headers.md
Created February 4, 2016 06:52
Some of Gitub API headers

Github API response dumps

Public Request Resoponse Headers

HTTP/1.1 200 OK
Status: 200 OK
Server: GitHub.com
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
@lukmdo
lukmdo / memcached.md
Last active February 4, 2016 09:35
inspect memcached keys

ps -ef

telnet

stats
stats slabs

stats items

stats cachedump SLAB_ID NUM_HOW_MANY

@lukmdo
lukmdo / caller_func.py
Last active February 2, 2018 22:09
get caller func name
from __future__ import print_function
import inspect
def fn():
return inspect.stack()[1][3]
class Example(object):
@lukmdo
lukmdo / dict_setdefault.py
Created February 26, 2017 18:44
For non inlplace dict setdefault
"""
For non inlplace dict setdefault.
"""
base_dict = {'a': 'a-ORIG', 'b': 'b-ORIG', 'd': 'd-ORIG'}
defaults = {'a': 'A', 'b': None, 'c': 0}
overrides = defaults
# Update by override. Like:
# - base_dict.update(overrides) -> new dict BUT `dict.update` is inplace
# - base_dict + overrides -> new dict BUT unsupported operand