Skip to content

Instantly share code, notes, and snippets.

Alexander Jung-Loddenkemper alexanderjulo

Block or report user

Report or block alexanderjulo

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
View keybase.md

Please publicly post the following Gist, and name it keybase.md

Keybase proof

I hereby claim:

  • I am alexanderjulo on github.
  • I am alexanderjulo (https://keybase.io/alexanderjulo) on keybase.
  • I have a public key ASApykm6Lzuffp-X-V2GUOg_Nmq-mhb5zkQI0fpCxE-WGAo
@alexanderjulo
alexanderjulo / __init__.py
Created Nov 25, 2015
flask application factory with celery
View __init__.py
from flask import Flask
from celery import Celery
def create_app():
app = Flask(__name__)
TaskBase = celery.Task
class Task(TaskBase):
@alexanderjulo
alexanderjulo / chosenselect.py
Last active Aug 29, 2015
Customized WTForms widget for Selects with Chosen
View chosenselect.py
import json
from wtforms.widgets import Select, HTMLString
class ChosenSelect(Select):
def __init__(self, multiple=False, renderer=None, options={}):
"""
Initiate the widget. This offers you two general options.
First off it allows you to configure the ChosenSelect to
@alexanderjulo
alexanderjulo / groupedqueryselectmultiplefield.py
Created Jan 24, 2014
A GroupedQuerySelectMultipleField for wtforms. Will create a select with optgroups of selects using a sqlalchemy backed query. Basically a QuerySelectMultipleField with grouping support.
View groupedqueryselectmultiplefield.py
from werkzeug.datastructures import OrderedMultiDict
from wtforms import widgets, ValidationError
from wtforms.compat import text_type
from wtforms.ext.sqlalchemy.fields import QuerySelectMultipleField
class GroupedSelectMultipleWidget(widgets.Select):
"""
Renders a select field with groups. Expects a list of tuples when
calling `field.iter_choices()`.
View chosen-bootstrap.css
select.form-control + .chosen-container.chosen-container-single .chosen-single {
display: block;
width: 100%;
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.428571429;
color: #555;
vertical-align: middle;
background-color: #fff;
@alexanderjulo
alexanderjulo / many-to-many-common-finder.py
Created Dec 4, 2012
find common elements in in a many-to-many helper table
View many-to-many-common-finder.py
def find_common(*user_ids):
queries = []
for user_id in user_ids:
query = db.session.query(participants.c.thread_id) \
.filter(participants.c.user_id==user_id)
queries.append(query)
thread_ids = [r[0] for r in db.session.query(participants.c.thread_id) \
.intersect(*queries).all()]
threads = Thread.query.filter(Thread.id.in_(thread_ids)).all()
return threads
@alexanderjulo
alexanderjulo / gist:4073388
Created Nov 14, 2012
Python Tuple Lists with language codes (as of ISO 639-1) and country codes (as of ISO 3166)
View gist:4073388
languages = [
('aa', 'Afar'),
('ab', 'Abkhazian'),
('af', 'Afrikaans'),
('ak', 'Akan'),
('sq', 'Albanian'),
('am', 'Amharic'),
('ar', 'Arabic'),
('an', 'Aragonese'),
('hy', 'Armenian'),
View function.py
@celery.task(name='questionnaire.suitability')
@with_request_context
def questionnaire_suitability(uid, suitable, treatment, explanation):
View output
% python test.py
teardown request.
teardown app context.
%
@alexanderjulo
alexanderjulo / celery.py
Created Sep 1, 2012
with request context decorator
View celery.py
class with_request_context(object):
def __init__(self, f, app=None, request=None):
self.f = f
if app:
self.app = app
else:
self.app = www
if request:
self.request = request
You can’t perform that action at this time.