Skip to content

Instantly share code, notes, and snippets.

PRAGMA page_size=1024;
BEGIN;
CREATE TABLE t1(x INTEGER PRIMARY KEY, y TEXT);
WITH RECURSIVE c(x) AS (VALUES(1) UNION SELECT x+1 FROM c WHERE x<250)
INSERT INTO t1(x,y) SELECT x*10, printf('%04d%.800c',x,'*') FROM c;
SAVEPOINT one;
SELECT count(*) FROM t1;
WITH RECURSIVE c(x) AS (VALUES(1) UNION SELECT x+1 FROM c WHERE x<250)
INSERT INTO t1(x,y) SELECT x*10+1, printf('%04d%.800c',x,'*') FROM c;
ROLLBACK TO one;
@lsemel
lsemel / gist:2b52ba807975900ce80a
Last active August 29, 2015 14:04
Example of chainable django queryset methods (for Django 1.6 and lower)
from django.db import models
from django.db.models import query
class PersonQuerySet(query.QuerySet):
def some_query(self):
return self.filter(...)
def some_other_filter(self):
return self.filter(...)
@lsemel
lsemel / hacky.txt
Last active November 5, 2018 18:37
"Hacky" (parody of "Tacky" by Weird Al, parody of Pharrell's "Happy")
It might seem crazy, writing CSS
When I could code in Bootstrap, SASS or Less
My entire database is CSV
I use Mac OS 7 from 1993
[Chorus:]
(my code is hacky)
Spend my day in Sublime Text 3, and wear Tattly tattoos
(my code is hacky)
If you don’t star my repo, I’ll down vote you on Hacker News
@lsemel
lsemel / flakes.py
Last active December 15, 2015 03:49 — forked from aniav/flakes.py
Run pyflakes against a Django project, with option to exclude directories/files
from __future__ import absolute_import
import ast
import os
from pyflakes import checker, messages
import sys
import fnmatch
from optparse import make_option
from django.conf import settings
from django.core.management.base import BaseCommand
@lsemel
lsemel / gist:4116020
Created November 20, 2012 04:33
Break content into columns
from math import floor
indexes_of_column_breaks = {}
def column(current_count, total_count, num_cols):
cols = indexes_of_column_breaks.get((total_count, num_cols), [])
if not cols:
# Compute the indexes where a new column will start
cols.append(0)
@lsemel
lsemel / .bash_profile
Created October 18, 2012 16:11
Add to .bash_profile to automatically activate a virtualenv matching the directory you cd into
function cd {
builtin cd "$@"
dirname=${PWD##*/}
if [ $dirname ] ; then
venv="/var/www/virtualenvs/"${dirname}
if [ -d $venv ] ; then
source ${venv}/bin/activate
fi
fi
}
machine:
timezone:
Americas/New_York
dependencies:
pre:
- pip install -r requirements.txt
test:
override:
@lsemel
lsemel / pre-commit
Created March 5, 2012 22:41 — forked from jjmalina/pre-commit
Git pre-commit hook
#!/usr/bin/env python
import os
import re
import subprocess
import sys
modified = re.compile('^(?:M|A)(\s+)(?P<name>.*)')
CHECKS = [
@lsemel
lsemel / capture_extension.py
Created May 22, 2011 20:26
Jinja2 capture extension, inspired by Rails content_for blocks
from jinja2 import nodes
from jinja2.ext import Extension
class CaptureExtension(Extension):
"""
Generic HTML capture, inspired by Rails' capture helper
In any template, you can capture an area of content and store it in a global
variable:
@lsemel
lsemel / defaults.php
Created November 21, 2010 20:59
Flexible named and positional parameters for PHP
<?php
/**
* Flexible named and positional parameters for PHP
*
* To use in your function, call it like this:
*
* function your_function() {
* $opts = defaults(func_get_args(),array(
* 'some_param'=> 'default',