Skip to content

Instantly share code, notes, and snippets.

create extension if not exists "unaccent";
create or replace function slugify(name text)
returns text as $$
begin
return trim(
regexp_replace(
unaccent(lower(name)),
'[^0-9a-z]+',
@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 / fabfile.py
Created February 23, 2013 16:50
django deployment from git remotes.
# -*- coding: utf-8 -*-
from fabric.state import env
from fabric.api import cd, local, run, abort, task
from fabric.context_managers import prefix
def worktree(cmd):
with prefix('source /usr/bin/virtualenvwrapper.sh'):
with cd(env.repo_path):
with prefix('cd `git config --get core.worktree`'):
@jeanphix
jeanphix / gist:3939448
Created October 23, 2012 15:28
SQLAlchemy - INSERT INTO ... (SELECT ...)
from sqlalchemy.sql.expression import Executable, ClauseElement
class InsertFromSelect(Executable, ClauseElement):
_execution_options = \
Executable._execution_options.union({'autocommit': True})
def __init__(self, table, columns, select):
self.table = table
self.columns = columns
@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__:
@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 / 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 / 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 / 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 / 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