Skip to content

Instantly share code, notes, and snippets.

View alexanderjulo's full-sized avatar

Alexander Jung-Loddenkemper alexanderjulo

View GitHub Profile
@alexanderjulo
alexanderjulo / languages-and-countries.py
Last active March 17, 2024 15:43
Python Tuple Lists with language codes (as of ISO 639-1) and country codes (as of ISO 3166)
# coding: utf8
languages = [
('aa', 'Afar'),
('ab', 'Abkhazian'),
('af', 'Afrikaans'),
('ak', 'Akan'),
('sq', 'Albanian'),
('am', 'Amharic'),
('ar', 'Arabic'),

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 / celery-crontab.py
Created June 29, 2012 15:16
celery crontab example
from celery.schedules import crontab
from flask.ext.celery import Celery
CELERYBEAT_SCHEDULE = {
# executes every night at 4:15
'every-night': {
'task': 'user.checkaccounts',
'schedule': crontab(hour=4, minute=20)
}
}
@alexanderjulo
alexanderjulo / celery.py
Created September 1, 2012 11:34
with request context decorator
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
@alexanderjulo
alexanderjulo / groupedqueryselectmultiplefield.py
Created January 24, 2014 22:07
A GroupedQuerySelectMultipleField for wtforms. Will create a select with optgroups of selects using a sqlalchemy backed query. Basically a QuerySelectMultipleField with grouping support.
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()`.
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 / __init__.py
Created November 25, 2015 06:10
flask application factory with celery
from flask import Flask
from celery import Celery
def create_app():
app = Flask(__name__)
TaskBase = celery.Task
class Task(TaskBase):
@alexanderjulo
alexanderjulo / many-to-many-common-finder.py
Created December 4, 2012 14:59
find common elements in in a many-to-many helper table
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
@celery.task(name='questionnaire.suitability')
@with_request_context
def questionnaire_suitability(uid, suitable, treatment, explanation):
% python test.py
teardown request.
teardown app context.
%