Skip to content

Instantly share code, notes, and snippets.

View doobeh's full-sized avatar

Anthony Plunkett doobeh

View GitHub Profile
@doobeh
doobeh / blah
Created November 7, 2012 21:53
blah
Desired Result:
<p class="whatever">
What are the minimum keypresses to get there? Function keypresses are
indicated by {TAB} {ENTER} etc.
<p c{TAB}whatever">
15 key presses!
@doobeh
doobeh / Hmm
Created November 7, 2012 21:58
Hmm
Desired Result:
<p class="whatever"></p>
What are the minimum keypresses to get there? Function keypresses are
indicated by {TAB} {ENTER} {SPACE} etc.
@doobeh
doobeh / example.py
Created November 15, 2012 15:34
Subquery ORM
# Get set of users who anthony sent a message to
## Isolate the user we care about.
anthony = User.query.filter_by(username='anthony').first()
## What messages were sent by that user:
subq = db.session.query(ChatHistory.with_user).filter(ChatHistory.user_id==anthony.id).distinct().subquery()
## What users does that relate to?
users = User.query.filter(User.id.in_(subq)).all()
@doobeh
doobeh / _macros.html
Created January 14, 2013 16:42
Jinja2 Bootstrap Form Rendering Macro
{% macro render_field(field,help=False,icon=False,counter=False,text=False) %}
{% if field.type not in ('SubmitField') %}
<div class="control-group{% if field.errors %} warning{% endif %}">
{% if field.type in ('EmailField','PasswordField','TextField','TextAreaField','FileField',
'QuerySelectFieldCustom','DecimalField','SelectField','BooleanField','IntegerField','DecimalField'
) %}
{{ field.label(class="control-label") }}
<div class="controls">
{% if icon %}
@doobeh
doobeh / gist:4656606
Created January 28, 2013 15:47
Heroku Logging Quickie
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
handler.setFormatter(logging.Formatter(
'%(asctime)s %(levelname)s: %(message)s '
'[in %(pathname)s:%(lineno)d]'
))
app.logger.addHandler(handler)
app.logger.info('Testing Info Level')
@doobeh
doobeh / scratch
Created January 29, 2013 15:54
Multiple Checkboxes
from flask.ext.wtf import Form, TextField, Required, TextAreaField,\
IntegerField, DecimalField, SubmitField, SelectField, HiddenField, FileField,\
QuerySelectMultipleField, widgets
class ToggleWidget(object):
"""
Renders a list of fields as a `ul` or `ol` list.
This is used for fields which encapsulate many inner fields as subfields.
The widget will try to iterate the field to get access to the subfields and
@doobeh
doobeh / example.html
Last active April 19, 2022 10:25 — forked from anonymous/siecje.py
Simple example of using a RadioField in Flask-WTForms to generate a form.
<form method="post">
{{ form.hidden_tag() }}
{{ form.example }}
<input type="submit">
</form>
@doobeh
doobeh / example.html
Last active April 5, 2026 23:09
Checkbox WTForms Example (in Flask)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form method="post">
{{ form.hidden_tag() }}
{{ form.example }}
example = [(1, u'FromFlask', u'file1.ext', u"['file2.ext']", u'WCP', u'WR_HS', u'email@hotmail.com', u'nothing happens', u'2013-01-3009:15:18.628922', u'None'), (2, u'FromFlask', u'file1.ext', u"['file2.ext']", u'WCP', u'WR_HS', u'email@hotmail.com', u'nothing happens', u'2013-01-3009:15:29.963847', u'None'), (3, u'FromFlask', u'file1.ext', u"['file2.ext']", u'WCP', u'WR_HS', u'email@windriver.com', u'nothing happens', u'2013-01-3009:21:16.275987', u'None'), (4, u'Cody', u'file1.ext', u"['inp_test.ext']", u'WCA', u'WR_HS', u'email@windriver.com', u'nothing happens', u'2013-01-3009:34:03.196901', u'None')]
[(x, x) for x in example]
# is the same as:
output = list()
for x in example:
output.append((x,x))
<form method="post">
{{ form.hidden_tag() }}
{{ form.images }}
<input type="submit">
</form>