Skip to content

Instantly share code, notes, and snippets.

View jqb's full-sized avatar

Kuba Janoszek jqb

  • Zurich, Switzerland
View GitHub Profile
# Defaultowe nazwy tabel:
# Code => <app>_code
# Kategories => <app>_kategories
# Code m2m to Kategories => <app>_code_kategorie
# Stworz nastepujaca migracje:
class Migration(SchemaMigration):
def forwards(self, orm):
db.add_column('<app>_code_kategorie', 'business_id', self.gf('django.db.models.fields.CharField')(max_length=100))
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
@jqb
jqb / gist:5646362
Last active December 17, 2015 17:29
Confy (almost) final loading api
import confy
# 1
with confy.loader(__file__) as confy:
locals().update(confy.merge(
confy.from_modules('base', confy.env('CONFIGURATION_MODE', 'development')),
confy.from_modules('local', silient=True),
confy.from_environ_vars([
'DATABASE_HOST',
@jqb
jqb / gist:5641900
Created May 24, 2013 07:38
Sample use of confy global variable
# base.py
PROJECT_PATHS = confy.new(
root = confy.rootpath('..', '..'),
lock = "{root}/lockdir/",
tmp = "{root}/tmp/",
log = "{root}/log/",
static = "{root}/project/static/",
)
@jqb
jqb / gist:5641860
Created May 24, 2013 07:29
Sample use of confy for multi-wsgi-app projects
import confy
with confy.loader(__file__) as confy:
MODE = confy.env('CONFIGURATION_MODE', 'gameapp/development')
locals().update(confy.from_modules({
# GAME
'gameapp/development': 'default,gameapp/development',
var notification = $('<div>')
.addClass('notification') .addClass(settings.type)
.append($('<div>').addClass('notification-image'))
.append($('<div class="notification-title">').html(text));
@jqb
jqb / gist:5039424
Created February 26, 2013 15:41
Nice pattern for clean property definiiton
class Class(object):
def prop(self):
def fget(self):
# stuff to get the value
def fset(self, value):
# stuff to set the value
return locals()
prop = property(**prop())
@jqb
jqb / gist:4747859
Last active December 12, 2015 08:59
Yet another example of python-like classes for JS
var User = Class.$new(SuperType1, SuperType2, function (self, opts) {
self.name = opts.name;
self.lastname = opts.lastname;
}).classvars({
classLevelVar: "Value"
}).def("fullName", function (self) {
return self.name + " " + self.lastname;
@jqb
jqb / gist:1663394
Created January 23, 2012 14:28
another setting loading solution
import os
def projectpath(*a):
from os.path import join, abspath
return join('/'.join(abspath(__file__).split('/')[0:-2]), *a)
files_base_names = [
'default',
os.environ.get('DJANGO_ENV', 'dev'),
'local_settings'
@jqb
jqb / manage.py
Created January 20, 2012 19:20
django settingsloader idea
#!/usr/bin/env python
from django.core.management import execute_manager
try:
import settings
except ImportError, e:
import sys
sys.stderr.write(
"\n\n"
"Error: Can't find the file or directory 'settings' in the directory\n"