Skip to content

Instantly share code, notes, and snippets.

View ashchristopher's full-sized avatar

Ash Christopher ashchristopher

  • Shopify
  • Toronto, Ontario
View GitHub Profile
In settings.py:
STATIC_URL = 'http://app.wave-test.com/sitestatic/'
In template:
{% compress js %}
<script type="text/javascript" src="{{ STATIC_URL }}js/vendor/require/require.js"></script>
{% endcompress %}
@ashchristopher
ashchristopher / extend_less
Created November 26, 2012 21:23
extend less
{% block external_app_less_imports %}
{{ block.super }}
@import "{{ STATIC_URL }}css/personal/personal.less";
{% endblock external_app_less_imports %}
@ashchristopher
ashchristopher / func_time_decorator
Created September 30, 2012 18:38
Timing a function decorator
import time
def print_timing(func):
def wrapper(*arg):
t1 = time.time()
res = func(*arg)
t2 = time.time()
print '%s took %0.3f ms' % (func.func_name, (t2-t1)*1000.0)
return res
return wrapper
@ashchristopher
ashchristopher / db_table_size_mysql
Created September 18, 2012 23:19
Get size of db tables in MySQL
SELECT TABLE_NAME, table_rows, data_length, index_length, round(((data_length + index_length) / 1024 / 1024),2) "Size in MB" FROM information_schema.TABLES WHERE table_schema = "waveaccounting"
SELECT TABLE_SCHEMA, TABLE_NAME, table_rows, data_length, index_length, round(((data_length + index_length) / 1024 / 1024),2) "Size in MB" FROM information_schema.TABLES;
@ashchristopher
ashchristopher / db_sizes_mysql
Created September 18, 2012 23:09
Get db sizes in MySQL
SELECT table_schema "Data Base Name",
sum( data_length + index_length ) / 1024 /
1024 "Data Base Size in MB",
sum( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES
GROUP BY table_schema ;
@ashchristopher
ashchristopher / coverage_django
Created September 15, 2012 16:44
coverage usage
coverage run manage.py test
coverage report -m
coverage html
@ashchristopher
ashchristopher / django_model_defn
Created August 7, 2012 14:31
Django Model definition?
class ModelTestCase(TestCase):
def test_1(self):
class Foo(object):
arg1 = "str"
arg2 = 1
class Bar(models.Model):
active = models.BooleanField()
@ashchristopher
ashchristopher / track_data.py
Created July 26, 2012 17:46 — forked from dcramer/track_data.py
Tracking changes on properties in Django
from django.db.models.signals import post_init
def track_data(*fields):
"""
Tracks property changes on a model instance.
The changed list of properties is refreshed on model initialization
and save.
>>> @track_data('name')
@ashchristopher
ashchristopher / diagnose_import_errors_without_stacktraces
Created July 6, 2012 01:57
Useful for diagnosing import errors that don't give stack traces
from django.core.management import setup_environ
import settings
setup_environ(settings)
from django.db import models
models.get_models()
@ashchristopher
ashchristopher / graphite-centos6-install.txt
Created May 24, 2012 15:18 — forked from dillera/graphite-centos6-install.txt
Install Graphite 0.9.9 and Statsd on Centos 6
# FOR CENTOS 6
# Andrew Diller Jan 2012
# Get EPEL Repo installed
rpm --httpproxy proxy --httpport 3128 --import https://fedoraproject.org/static/0608B895.txt
rpm -Uvh http://download.fedora.redhat.com/pub/epel/6/i386/epel-release-6-5.noarch.rpm
vi /etc/yum.repos.d/epel.repo