Skip to content

Instantly share code, notes, and snippets.

View patrys's full-sized avatar

Patryk Zawadzki patrys

View GitHub Profile
@patrys
patrys / cbv-wat1.py
Last active December 20, 2016 18:57
from django.template.response import TemplateResponse
from django.views.generic import View
class MyClassBasedView(View):
def __init__(self, foo='bar'):
self._foo = foo
def get(self, request):
context = {'foo': self._foo}
#!/usr/bin/env python
from meinheld import server
from saleor.wsgi import application
server.listen(('0.0.0.0', 8000))
server.run(application)
#!/usr/bin/env python
from cherrypy import wsgiserver
from saleor.wsgi import application
server = wsgiserver.CherryPyWSGIServer(
('0.0.0.0', 8000), application, numthreads=10)
try:
server.start()
except KeyboardInterrupt:
#!/usr/bin/env python
from tornado import httpserver, ioloop, wsgi
from saleor.wsgi import application
container = wsgi.WSGIContainer(application)
server = httpserver.HTTPServer(container)
server.bind(8000)
server.start(0)
ioloop.IOLoop.current().start()
#!/usr/bin/env python
from tornado import httpserver, ioloop, wsgi
from saleor.wsgi import application
container = wsgi.WSGIContainer(application)
server = httpserver.HTTPServer(container)
server.listen(8000)
ioloop.IOLoop.current().start()
@patrys
patrys / .fonts.conf
Created March 8, 2016 12:27
Fedora, fonts and Chrome
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match target="font">
<edit name="autohint" mode="assign"><bool>true</bool></edit>
<edit name="antialias" mode="assign"><bool>true</bool></edit>
<edit name="hinting" mode="assign"><bool>true</bool></edit>
<edit name="hintstyle" mode="assign"><const>hintfull</const></edit>
<edit name="rgba" mode="assign"><const>rgb</const></edit>
</match>
</fontconfig>
@patrys
patrys / example.py
Last active October 9, 2015 12:15
Test file for flake8
from example import (
f401_unused)
@f821_undefined_name
def c901_too_complex(x):
if x > 1:
if x > 2:
if x > 3:
if x > 4:
if x > 5:
@patrys
patrys / hack.patch
Last active August 29, 2015 14:22
Expression filter hack
diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py
index 4306193..bf965c1 100644
--- a/django/db/models/expressions.py
+++ b/django/db/models/expressions.py
@@ -340,11 +340,27 @@ def reverse_ordering(self):
return self
+class ExpressionFilter(object):
+ def __init__(self, expression, value, lookup):
@patrys
patrys / such_db_optimization.py
Last active August 29, 2015 14:03
wroc.py / haskell
def query_db(ids):
print('Querying the database:', ids)
# fake some data
results = []
for id_ in ids:
results.extend(range(id_ + 2, id_ + 5))
# simulate DISTINCT()
return set(results)
@patrys
patrys / rebrand.py
Created December 13, 2012 14:42 — forked from jimmac/rebrand.rb
import glob
import os
from xml.etree import ElementTree
TEMP = './tmp.svg'
def rebrand(fname, brand):
svg = ElementTree.parse(fname)
for e in svg.iterfind(".//{http://www.w3.org/2000/svg}rect[@id='background']"):
e.set('style', 'fill:url(#%s);' % (brand,))