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
Xion / compact.py
Created Nov 13, 2011
PHP compact() function in Python
View compact.py
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.
Example:
>>> 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
Xion / pytz_patch.py
Created May 6, 2012
Patching pytz with import hook to have usable generic timezones
View pytz_patch.py
"""
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
Xion / sqla_regex.py
Last active May 31, 2019
Regular expression filters in SQLAlchemy
View sqla_regex.py
"""
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
View jinjatestcase.py
from collections import Mapping
import unittest
import warnings
from flask import get_template_attribute
from myapplication import app
class JinjaTestCase(unittest.TestCase):
@Xion
Xion / requestcontexttask.py
Created Nov 4, 2015
Base class for Celery tasks running inside Flask request context
View requestcontexttask.py
from celery import Task
from flask import has_request_context, make_response, request
from myapp import app
__all__ = ['RequestContextTask']
class RequestContextTask(Task):
@Xion
Xion / deprecated.py
Created May 26, 2013
@deprecated decorator for Python classes
View deprecated.py
import functools
import inspect
import os
import warnings
class _DeprecatedDecorator(object):
MESSAGE = "%s is @deprecated"
def __call__(self, symbol):
@Xion
Xion / error.py
Created Aug 23, 2015
ErrorExtension for Jinja
View error.py
"""
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
Xion / setup_gae_virtualenv.sh
Created Oct 18, 2013
Setup virtualenv for a Google App Engine project
View setup_gae_virtualenv.sh
#!/bin/sh
# Script for setting up virtualenv to work correctly with Google App Engine projects
# @author Karol Kuczmarski "Xion"
DEFAULT_APPENGINE_SDK_PATH="/opt/google_appengine"
DEFAULT_PROJECT_LIB_PATH="./lib"
@Xion
Xion / auth.py
Last active Jun 5, 2018
Query string authenticators for Requests
View auth.py
"""
Requests' authenticator that attaches given parameters
to the URL query string.
License: Public Domain.
"""
from requests.auth import AuthBase
class QueryStringAuth(AuthBase):
View count_lens_operators.sh
#!/bin/sh
curl https://hackage.haskell.org/package/Chart-1.1/docs/Control-Lens-Operators.html | python -c '
import re, sys
for line in sys.stdin.readlines():
m = re.search(r"""class="def">([^<]+)</a> ::""", line)
if m:
print(m.group(1)[1:-1].replace("&lt;", "<").replace("&amp;", "&").replace("&gt;", ">"))
' | sort | uniq | wc -l
You can’t perform that action at this time.