This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git remote add upstream https://github.com/whoever/whatever.git | |
git fetch upstream | |
git checkout master | |
git rebase upstream/master |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\pset format wrapped; | |
select now() - query_start as duration, query from pg_stat_activity order by duration desc; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
// hallo.js plugin to use paragraphs by default | |
// https://github.com/bergie/hallo/issues/157 | |
// https://github.com/torchbox/wagtail/issues/559 | |
function getLastChildElement(el){ | |
var lc = el.lastChild; | |
while(lc && lc.nodeType != 1) { | |
if(lc.previousSibling) | |
lc = lc.previousSibling; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.cache import cache | |
from django.utils.hashcompat import md5_constructor | |
from django.utils.http import urlquote | |
def invalidate_template_fragment(fragment_name, *variables): | |
args = md5_constructor(u':'.join([urlquote(var) for var in variables])) | |
cache_key = 'template.cache.{0}.{1}'.format(fragment_name, args.hexdigest()) | |
cache.delete(cache_key) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tables for owned by 'tableowner' | |
select 'drop table if exists "' || tablename || '" cascade;' from pg_tables where tableowner='tableowner'; | |
# all sequences | |
select 'drop sequence if exists "' || relname || '" cascade;' from pg_class where relkind = 'S'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ value|floatformat|floatformat }} | |
or: | |
{{ value|floatformat:-1|floatformat:-1 }} | |
1.0 -> 1 | |
1.01 -> 1 # this would be 1.0 with one floatformat filter | |
1.10 -> 1.1 | |
1.123 -> 1.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find . -name \*.py -type f -exec sh -c 'command $0' {} \; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set ruler | |
set sm | |
set nocp | |
set bs=2 | |
syn on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fix_id_sequence(model_class): | |
from django.db import connection | |
next_val = model_class.objects.all().order_by("-id")[0].id + 1 | |
cursor = connection.cursor() | |
cursor.execute("select setval('%s_id_seq', %d, True)" % (model_class._meta.db_table, next_val)) | |
row = cursor.fetchone() | |
cursor.close() | |
return row[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fab pull_data_from_production --gateway [email protected] | |
# first it might ask for a password for the root user but that is actually for [email protected] | |
# then press Ctrl+D to continue if it opens an interactive ssh session on the production server | |
# alternatively use env.gateway = '[email protected]' |