Skip to content

Instantly share code, notes, and snippets.

Karol Kuczmarski Xion

Block or report user

Report or block Xion

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
Xion /
Created Nov 13, 2011
PHP compact() function in Python
def compact(*args):
''' compact() function, analoguous to the PHP version.
Converts a series of (possible nested) iterables containing variable names
into a dictionary mapping those names to variable values.
>>> x, y, z, a, b, c = 1, 2, 3, 4, 5, 6
>>> compact('x', ['y','z'], ['a', ['b'], [['c']]])
{'a': 4, 'b': 5, 'c': 6, 'x': 1, 'y': 2, 'z': 3}
def _compact_arg(res, arg):
Xion /
Created May 6, 2012
Patching pytz with import hook to have usable generic timezones
Import hook extending pytz package with usable, generic timezones:
GMT-14 up to GMT+12.
Note that pytz already has Etc/GMT+X timezones, but
(quoting Wikipedia):
"In order to conform with the POSIX style, those zones beginning with "Etc/GMT"
have their sign reversed from what most people expect. In this style,
zones west of GMT have a positive sign and those east have a negative sign."
Xion /
Last active May 31, 2019
Regular expression filters in SQLAlchemy
Module implementing an enhanced string column type for SQLAlchemy
with a support for regular expression operators in Postgres and SQLite.
import re
from sqlalchemy import String as _String, event, exc
from sqlalchemy.engine import Engine
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql.expression import BinaryExpression, func, literal
from collections import Mapping
import unittest
import warnings
from flask import get_template_attribute
from myapplication import app
class JinjaTestCase(unittest.TestCase):
Xion /
Created Nov 4, 2015
Base class for Celery tasks running inside Flask request context
from celery import Task
from flask import has_request_context, make_response, request
from myapp import app
__all__ = ['RequestContextTask']
class RequestContextTask(Task):
Xion /
Created May 26, 2013
@deprecated decorator for Python classes
import functools
import inspect
import os
import warnings
class _DeprecatedDecorator(object):
MESSAGE = "%s is @deprecated"
def __call__(self, symbol):
Xion /
Created Aug 23, 2015
ErrorExtension for Jinja
Jinja extension adding support for {% error %} tag
that allows to raise exceptions directly from templates.
from jinja2 import TemplateAssertionError
from jinja2.ext import Extension
from jinja2.nodes import CallBlock, Const
class ErrorExtension(Extension):
Xion /
Created Oct 18, 2013
Setup virtualenv for a Google App Engine project
# Script for setting up virtualenv to work correctly with Google App Engine projects
# @author Karol Kuczmarski "Xion"
Xion /
Last active Jun 5, 2018
Query string authenticators for Requests
Requests' authenticator that attaches given parameters
to the URL query string.
License: Public Domain.
from requests.auth import AuthBase
class QueryStringAuth(AuthBase):
curl | python -c '
import re, sys
for line in sys.stdin.readlines():
m ="""class="def">([^<]+)</a> ::""", line)
if m:
print([1:-1].replace("&lt;", "<").replace("&amp;", "&").replace("&gt;", ">"))
' | sort | uniq | wc -l
You can’t perform that action at this time.