Skip to content

Instantly share code, notes, and snippets.

@jeanphix
jeanphix / gist:53af6d5912fd6cc1f22f
Created June 17, 2015 06:20
alembic check_revision
# -*- coding: utf-8 -*-
import os
import re
import subprocess
from copy import copy
from difflib import unified_diff
from sqlalchemy import create_engine
@jeanphix
jeanphix / WTForms CountrySelectField
Created November 3, 2011 13:03
WTForms CountrySelectField
import pycountry
class CountrySelectField(SelectField):
def __init__(self, *args, **kwargs):
super(CountrySelectField, self).__init__(*args, **kwargs)
self.choices = [(c.alpha3, c.name) for c in pycountry.countries]
@jeanphix
jeanphix / gist:1406053
Created November 29, 2011 19:20
django testing with ghost.py
import unittest
import os
import django.core.handlers.wsgi
from ghost import GhostTestCase
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
app = django.core.handlers.wsgi.WSGIHandler()
@jeanphix
jeanphix / gist:1408574
Created November 30, 2011 10:14
Django global user
# middlewares.py
import threading
_thread_locals = threading.local()
def get_current_user():
"""Returns the current user."""
return getattr(_thread_locals, 'user', None)
@jeanphix
jeanphix / gist:1419502
Created December 1, 2011 20:13
alembic / flask-sqlalchemy (alembic/env.py)
import os
import sys
from alembic import context
from sqlalchemy import engine_from_config
from logging.config import fileConfig
sys.path.append(os.getcwd())
from models import metadata
from myapp import app
@jeanphix
jeanphix / gist:1744909
Created February 5, 2012 11:38
Leaflet + OSM
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="Leaflet/dist/leaflet.css" type="text/css" />
</head>
<body>
<div id="map-canvas" style="height: 500px; width: 90%; margin: 0 auto;">
</div>
<script type="text/javascript" src="Leaflet/dist/leaflet.js"></script>
<script type="text/javascript">
@jeanphix
jeanphix / server.coffee
Created March 20, 2012 17:02
brunch github OAuth2
sysPath = require 'path'
express = require 'express'
oauth = require 'oauth'
_appSecret = "myawesomesecret"
_githubUrl = "https://github.com/login"
_githubKey = "xxxxxxxxxxxxxx"
_githubSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
_githubCallBack = "http://my.app/signin/callback"
@jeanphix
jeanphix / waveform.py
Created July 14, 2012 07:10
Creates waveform image from wave file.
import numpy
from PIL import Image, ImageDraw
import scikits.audiolab as audiolab
class Waveform(object):
"""Creates a waveform image for given wave audio file.
:param soundfile: The path to the wave file.
:param width: The output image width as an optional integer.
@jeanphix
jeanphix / gist:3827051
Created October 3, 2012 13:57
Flask-Script test command
import unittest
@manager.command
@manager.option('-p', '--path', help='Path to specific test(s).')
def test(path=None, verbosity=1):
"""Runs tests.
"""
loader = unittest.TestLoader()
if path is None:
@jeanphix
jeanphix / gist:3888701
Created October 14, 2012 14:14
distillery use case
class GroupSet(Set):
class __distillery__:
__model__ = Group
class admin:
name = 'admin'
class UserSet(Set)
class __distillery__: