Skip to content

Instantly share code, notes, and snippets.

@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(...)
# This class gives you all the Rails 3 URL helpers, which are so
# unhelpfully unavailable in models, libraries, and unit tests
# Stick this in the library folder and get a URL with
# UrlHelpers.new.nameofmodel_url
class UrlHelpers
include Rails.application.routes.url_helpers
def initialize
default_url_options[:host] = case Rails.env
when "development" then "localhost"
# in compass.rb
puts '>> Environment is ' + environment.to_s
if (environment.to_s == 'production')
puts '>> Disabling compass in production'
never_update = true
cache_location = '/tmp'
else
puts '>> Compass is enabled'
end
@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',
@lsemel
lsemel / MY_config.php
Created November 21, 2010 20:32
Vary configuration in CodeIgniter based on the the subdomain, e.g. (dev|staging|www).yourdomain.com
<?php
class MY_Config extends CI_Config {
/**
* Loads in custom server-specific configurations
*
* Additional config variables set
* server_name - the part of the hostname to the left of '.topleveldomain.com'
*
@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 = [
machine:
timezone:
Americas/New_York
dependencies:
pre:
- pip install -r requirements.txt
test:
override:
@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
}
@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 / 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