Skip to content

Instantly share code, notes, and snippets.

View ricomoss's full-sized avatar
🎲
Would rather be playing board games.

Rico Cordova ricomoss

🎲
Would rather be playing board games.
View GitHub Profile
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)
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:
#!/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
@ricomoss
ricomoss / python
Last active November 12, 2015 22:16
# 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:
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,
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
(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;
}
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:
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')
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