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
obj_sets = [some_model.foreign_key_set for some_model in SomeModel.objects.all()] | |
qs = SomeOtherModel.objects.filter(pk__in=[some_pk_set]) | |
for obj_set in obj_sets: | |
qs | SomeOtherModel.objects.filter(some_filter_param__in=obj_set) | |
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 itertools import product, compress | |
def combinations(items): | |
return (set(compress(items,mask)) for mask in product(*[[0,1]]*len(items))) | |
vals = [1, 2, 3, 4, 5, 6, 7, 8, 9] | |
combs = combinations(vals) | |
count = 0 | |
for comb in combs: |
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
#!/usr/bin/env python | |
import os | |
import subprocess | |
import re | |
from signal import SIGTERM | |
from datetime import datetime, timedelta | |
TIMEOUT = 10 | |
CLIP_DURATION = 60 * 60 |
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 a bit messy | |
try: | |
program = student_schedule.zm_course.program | |
except AttributeError: | |
if program is None: | |
print("warning, could not add to class resource due to old model") | |
return | |
else: | |
program = program | |
if program is None: |
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.test import TestCase, Client | |
class SomeTestCase(TestCase): | |
def test_post_success(self): | |
client = Client() | |
data = { | |
'api_key': self.rod_client.api_key, | |
'username': 'test_user1', | |
'hero_name': 'test_hero1', | |
'zone_index': 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
class Mixin1(Base1): | |
def get_data(self): | |
# Gather some data in some way | |
class Mixin2(Base2): | |
def get_data(self): | |
# Gather some data in another way | |
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
(function () { | |
//Websocket and Stomp config | |
init_stomp = function( socket_url, username, password, vhost, disable_debug ) { | |
// Stomp.js boilerplate | |
var ws = new SockJS(socket_url), | |
client = Stomp.over(ws); | |
if(disable_debug){ | |
client.debug = null; | |
} |
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 YourClass(object): | |
# this decorator will only work with internal class functions | |
def api_retry(func): | |
api_retry_limit = 3 | |
def wrapped(*args): | |
self = args[0] | |
for i in range(api_retry_limit): | |
try: | |
result = func(*args) | |
except ValueError: |
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 Tcpa(models.Model): | |
wording = models.CharField(max_length=1024) | |
class ExpressWrittenConsent(models.Model): | |
wording = models.CharField(max_lengh=1024) | |
class TcpaByClient(models.Model): | |
client = models.ForeignKey('relationships.Client') |
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 MyModelA(models.Model): | |
model_b = models.ForeignKey(MyModelB, blank=True, null=True) | |
class MyModelB(models.Model): | |
name = models.CharField(max_length=10) | |
# Fixtureless use case | |
from django.test import TestCase |
NewerOlder