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
import sys | |
import csv | |
import ujson | |
input_file_name, output_file_name = sys.argv[1:3] | |
headers = sys.argv[-1].split(',') | |
print input_file_name, | |
output_rows = [] |
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 django.contrib.admin import ModelAdmin | |
class MyTableAdmin(ModelAdmin): | |
... | |
paginator = LargeTablePaginator | |
... | |
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
-- User Table | |
CREATE TABLE user ( | |
id serial PRIMARY KEY, | |
account_id int not NULL, | |
name varchar(10) | |
); | |
-- Purchase Table | |
CREATE TABLE purchase ( | |
id SERIAL PRIMARY KEY, |
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
SELECT "purchase"."id" | |
FROM "purchase" | |
INNER JOIN "user" ON ("purchase"."user_id" = "user"."id") | |
WHERE "user"."account_id" IN | |
(SELECT generate_series(1,1000)); |
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
WITH user_ids AS | |
(SELECT id | |
FROM user | |
WHERE account_id IN | |
(SELECT generate_series(1,1000))) | |
SELECT purchase.id | |
FROM purchase | |
WHERE user_id IN | |
(SELECT id | |
FROM user_ids); |
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
q = MyModel.objects.values('some_fk_id').annotate( | |
avg_duration=Avg('duration'), | |
perc_90_duration=RawSQL('percentile_disc(%s) WITHIN GROUP (ORDER BY duration)', (0.9,)), | |
) | |
print q.query | |
# SELECT "some_fk_id", | |
# AVG("duration") AS "avg_duration", | |
# (percentile_disc(0.9) WITHIN |
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
class RawAnnotation(RawSQL): | |
""" | |
RawSQL also aggregates the SQL to the `group by` clause which defeats the purpose of adding it to an Annotation. | |
""" | |
def get_group_by_cols(self): | |
return [] | |
# The Query | |
q = MyModel.objects.values('some_fk_id').annotate( | |
avg_duration=Avg('duration'), |
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 django.conf import settings | |
from raven.contrib.django.client import DjangoClient | |
ignore_exc_msg_prefixes = getattr(settings, 'CUSTOM_SENTRY_CLIENT_IGNORE_EXCEPTION_MESSAGE_PREFIXES', []) | |
class IgnoreExceptionsDjangoClient(DjangoClient): | |
""" | |
Overrides DjangoClient's `skip_error_for_logging` method.CUSTOM_SENTRY_CLIENT_IGNORE_EXCEPTION_MESSAGE_PREFIXES |
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 django.conf import settings | |
# NOTE | |
# The timeout values here only restrict the roles from application code. The actual timeout set in the DB could | |
# be a different value. | |
# Timeout set in DB on 27/03/2018 is 50s. | |
DEFAULT_DB_TIMEOUT_IN_MS = 50000 | |
default_conn = settings.DJANGO_DEFAULT_DB_CONNECTION_NAME |
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
var express = require('express'); | |
var router = express.Router(); | |
var multer = require('multer'), //for handling multipart/form-data | |
fs = require('fs'), | |
S3FS = require('s3fs'), //abstraction over Amazon S3's SDK | |
s3fsImpl = new S3FS('your-bucket-here', { | |
accessKeyId: 'Your-IAM-Access', | |
secretAccessKey: 'Your-IAM-Secret' | |
}); |
OlderNewer