Skip to content

Instantly share code, notes, and snippets.

View jarshwah's full-sized avatar

Josh Smeaton jarshwah

View GitHub Profile
@jarshwah
jarshwah / commands
Created May 2, 2011 00:29
Being explicit with django local settings
// Being explicit with which settings file is used, allows two important properties. settings.py is ALWAYS in a production ready state, even if 'settingslocal' is accidentally checked into source control. The other nice side effect, is that every developers settings files are stored in source control - allowing each developer to share components of their settings files with their peers.
// runserver
python manage.py runserver --settings settingsjosh
// syncdb
python manage.py syncdb --settings settingsjosh
@jarshwah
jarshwah / TestHelper.cs
Created January 14, 2012 09:49 — forked from haacked/TestHelper.cs
String Comparison Unit Test Helper
public static class TestHelpers
{
public static void ShouldEqualWithDiff(this string actualValue, string expectedValue)
{
if (actualValue == expectedValue) return;
Console.WriteLine("Idx Expected Actual");
Console.WriteLine("---------------------");
var maxLength = Math.Max(actualValue.Length, expectedValue.Length);
for (int i = 0; i < maxLength; i++)
@jarshwah
jarshwah / install_cx_Oracle_rhel6.sh
Last active February 23, 2017 22:29
Installing cx_Oracle on Linux Redhat 6 using RPMs
# assuming python and pip are already installed
# installing the instantclient is usually where problems happen
# download the following files from oracle
#
# oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
# oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm
# oracle-instantclient11.2-sqlplus-11.2.0.3.0-1.x86_64.rpm
# install the rpms
@jarshwah
jarshwah / Create Postgres Django DB
Last active October 13, 2018 20:24
Creating testing databases for django on Postgres 9.3 for OSX (installed with homebrew)
# Note that the "smeatonj" below is the user that installed postgres with homebrew
# first, the "default" database:
$ createuser -U smeatonj djangotest -P
Enter password for new role:
Enter it again:
$ createdb djangotest
$ psql -U smeatonj -d djangotest
def _get_model(self):
DynamicClass = cache.get('DynamicModel_' + self.table_name)
if DynamicClass is None:
# get the custom columns required for this table..
attrs = dict((c.column_name, models.CharField(max_length=100, blank=True, null=True)) for c in self.custom_fields.all())
class Meta:
db_table = self.table_name
app_label = self._meta.app_label
managed = False
@jarshwah
jarshwah / boxstarter.ps1
Last active May 26, 2020 01:56
Box Starter - VS2015 Dev
# From a command prompt:
# START http://boxstarter.org/package/nr/url?https://gist.githubusercontent.com/jarshwah/58f5f9f78d43ae269545/raw/e5a2076fbe76106b19ecaa62355776aa0a02fc91/boxstarter.ps1
# Boxstarter options
$Boxstarter.RebootOk=$true # Allow reboots?
$Boxstarter.NoPassword=$false # Is this a machine with no login password?
$Boxstarter.AutoLogin=$true # Save my password securely and auto-login after a reboot
# Basic setup
Update-ExecutionPolicy Unrestricted
@jarshwah
jarshwah / django-test-suite-profile.txt
Created June 10, 2014 23:29
Cumulative profiling data from django test suite, with loaddata optimisations
This file has been truncated, but you can view the full file.
vagrant@djangocore:~$ PYTHONPATH=/django /home/vagrant/.virtualenvs/py2.7/bin/python -m cProfile -s cumulative /django/tests/runtests.py --settings=djangocore_test_postgresql
Testing against Django installed in '/django/django'
Creating test database for alias 'default'...
Creating test database for alias 'other'...
..........................................................................................................................................................................................................................................................................................................................................................................x........................................................................................................................................................................................s..............................................................................................................................................................
@jarshwah
jarshwah / gist:35c367a4cf567c62b579
Created June 19, 2014 14:51
Django test output for resolve_columns
field=None value=1L
field=<django.db.models.fields.AutoField: id> value=u'159059725'
field=<django.db.models.fields.CharField: isbn> value=u'The Definitive Guide to Django: Web Development Done Right'
field=<django.db.models.fields.CharField: name> value=447L
field=<django.db.models.fields.IntegerField: pages> value=4.5
field=<django.db.models.fields.FloatField: rating> value=Decimal('30.00')
field=<django.db.models.fields.DecimalField: price> value=1L
field=<django.db.models.fields.related.ForeignKey: contact> value=1L
field=<django.db.models.fields.related.ForeignKey: publisher> value=datetime.date(2007, 12, 6)
field=<django.db.models.fields.DateField: pubdate> value=1L
@jarshwah
jarshwah / goal.py
Last active August 29, 2015 14:04
goal in python
def g(letters=None):
if letters: return 'gal'
goal = ['go']
def o(letters=None):
assert letters is None or letters == 'al'
if letters:
goal.append(letters)
return ''.join(goal)
goal.append('o')
return o
@jarshwah
jarshwah / output.txt
Created August 26, 2014 05:17
Profiling django tests with Oracle RAC
(django)[vagrant@peppermint django]$ ./runoracletests.py expressions
Testing against Django installed in '/django/django'
Creating test database for alias 'default'...
Creating test user...
Creating test database for alias 'other'...
Creating test user...
..s.................s..................
----------------------------------------------------------------------
Ran 39 tests in 386.525s