Install Multiple Python Versions for Specific Project
This file contains 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 collections import defaultdict | |
from django.db.models.signals import * | |
class DisableSignals(object): | |
def __init__(self, disabled_signals=None): | |
self.stashed_signals = defaultdict(list) | |
self.disabled_signals = disabled_signals or [ | |
pre_init, post_init, | |
pre_save, post_save, |
This file contains 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
# This is just a cheat sheet: | |
# On production | |
sudo -u postgres pg_dump database | gzip -9 > database.sql.gz | |
# On local | |
scp -C production:~/database.sql.gz | |
dropdb database && createdb database | |
gunzip < database.sql.gz | psql database |
This file contains 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
#!/bin/bash | |
# extract all postgres databases from a sql file created by pg_dumpall | |
# this script outputs one .sql file for each database in the original .sql file | |
# unless you pass the name of a database in the dump | |
if [ $# -lt 1 ] | |
then | |
echo "Usage: $0 <postgresql sql dump> [dbname]" >&2 | |
exit 1 | |
fi |
This file contains 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
# creating and testing permissions and test groups in django tests. | |
from django.contrib.auth.models import User, Permission, Group | |
from django.test import TestCase | |
from django.test import Client | |
class ExampleGroupPermissionsTests(TestCase): | |
def setUp(self): | |
#create permissions group |
This file contains 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
#!/bin/bash | |
TIME=$(date +%s) | |
varnishadm vcl.load r_$TIME /etc/varnish/default.vcl | |
varnishadm vcl.use r_$TIME |
This file contains 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
CREATE OR REPLACE FUNCTION array_sort (ANYARRAY) | |
RETURNS ANYARRAY LANGUAGE SQL | |
AS $$ | |
SELECT ARRAY(SELECT unnest($1) ORDER BY 1) | |
$$; |
This file contains 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
DROP FUNCTION IF EXISTS anyarray_uniq(anyarray); | |
CREATE OR REPLACE FUNCTION anyarray_uniq(with_array anyarray) | |
RETURNS anyarray AS | |
$BODY$ | |
DECLARE | |
-- The variable used to track iteration over "with_array". | |
loop_offset integer; | |
-- The array to be returned by this function. | |
return_array with_array%TYPE := '{}'; |
This file contains 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 main(): | |
key_path = os.path.join(settings.INTERNAL_FILES, 'crm2', 'service_account_secrets.json') | |
credentials = get_api_credentials(key_path=key_path) | |
if not credentials: | |
logger.info("No credential found, so stopping") | |
return | |
active_users = User.objects.filter(is_active=True) |
This file contains 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
CREATE EXTENSION IF NOT EXISTS "unaccent" | |
CREATE OR REPLACE FUNCTION slugify("value" TEXT) | |
RETURNS TEXT AS $$ | |
-- removes accents (diacritic signs) from a given string -- | |
WITH "unaccented" AS ( | |
SELECT unaccent("value") AS "value" | |
), | |
-- lowercases the string | |
"lowercase" AS ( |
NewerOlder