Skip to content

Instantly share code, notes, and snippets.

View cypreess's full-sized avatar

Kris Dorosz cypreess

View GitHub Profile
from collections import OrderedDict
def deep_search(needles, haystack):
found = {}
if type(needles) != type([]):
needles = [needles]
if type(haystack) == type(OrderedDict()) or type(haystack) == type(dict()):
for needle in needles:
@cypreess
cypreess / import.py
Last active June 29, 2018 09:07
Import specific class in Python
def import_name(name):
components = name.split('.')
mod = __import__(
'.'.join(components[0:-1])
)
for m in components[1:]:
mod = getattr(mod, m)
return mod
@cypreess
cypreess / natural_timedelta.py
Last active June 29, 2018 10:38
Formatting negative timedelta in more natural way
import datetime
def timedelta_to_string(timedelta):
total_seconds = timedelta.total_seconds()
if total_seconds < 0:
timedelta_str = '-' + str(datetime.timedelta() - timedelta)
else:
timedelta_str = '+' + str(timedelta)
return timedelta_str
from rest_framework.authentication import SessionAuthentication
class CsrfExemptSessionAuthentication(SessionAuthentication):
def enforce_csrf(self, request):
return # To not perform the csrf check previously happening
Znamy przyczynę śmierci Roberta Brylewskiego. Są wyniki sekcji zwłok
PIOTR HALICKI dzisiaj 13:33
FACEBOOK | 20
TWITTER | 2
He he
E-MAIL
KOPIUJ LINK 0SKOMENTUJ
Niewydolność krążeniowo-oddechowa była przyczyną śmierci Roberta Brylewskiego – dowiedział się Onet. Tak wynika ze wstępnych wyników przeprowadzonej dziś sekcji znaeenego muzyka. Na razie jednak nie ustalono, czy miało to związek z wcześniejszym brutalnym pobiciem Brylewskiego. Będzie to jeszcze przedmiotem dalszych badań.
@cypreess
cypreess / example.py
Created June 7, 2018 09:26
Snipty example snippet
print("Snipty is awesome!")
import shortuuid
from django.db import models
def shorten_name(name):
if len(name) <= 3:
return name.lower()
else:
return name[0].lower() + ''.join([ch for ch in name[1:].lower() if ch not in 'aeiouy'][:2])
from logging import getLogger
from django.db import connection
logger = getLogger(__name__)
class QueryCountDebugMiddleware(object):
"""
This middleware will log the number of queries run
and the total time taken for each request (with a
status code of 200). It does not currently support
@cypreess
cypreess / left_pad.py
Created June 7, 2018 08:22
Snipty multi file support demonstration
def left_pad(s, n, c):
return s.rjust(len(s) + n, c)