Skip to content

Instantly share code, notes, and snippets.

View jrobichaud's full-sized avatar

Jules Robichaud-Gagnon jrobichaud

View GitHub Profile
@jrobichaud
jrobichaud / example.py
Created January 19, 2024 20:03 — forked from bblanchon/example.py
Django Subquery Aggregate (Count, Sum...)
from django.db.models import OuterRef
weapons = Weapon.objects.filter(unit__player_id=OuterRef('id'))
units = Unit.objects.filter(player_id=OuterRef('id'))
qs = Player.objects.annotate(weapon_count=SubqueryCount(weapons),
rarity_sum=SubquerySum(units, 'rarity'))
@jrobichaud
jrobichaud / method_mocking_example.py
Last active March 15, 2019 17:48
Code snippet on how to implement appropriate method mocking of inaccessible instance.
import unittest.mock
class Callee:
def __init__(self, member):
self.member = member
def do_something(self, method_argument):
pass
def do_call():
@jrobichaud
jrobichaud / django_naming_things.md
Last active March 7, 2024 00:32
An attempt to create a class naming style for django

Premise

Django code style is well documented however the documentation has no statement on how to name classes. When digging the documentation we can find various examples that does not follow an obvious standard.

Abstract base class documentation

from django.db import models

class CommonInfo(models.Model):
    name = models.CharField(max_length=100)
 age = models.PositiveIntegerField()
@jrobichaud
jrobichaud / django_q_sync_scheduled_tasks.py
Created May 9, 2017 13:27
Context manager to allow to run scheduled tasks "synced" during tests. The calls will run just when leaving the "with" statement.
from unittest import mock
class SyncScheduledTasks:
patch = None
calls = None
def __init__(self):
self.calls = []
self.patch = None
@jrobichaud
jrobichaud / keybase.md
Created September 13, 2016 21:51
keybase.md

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@jrobichaud
jrobichaud / FixAssemblys
Created May 4, 2016 15:15 — forked from horsman/FixAssemblys
FixUnityAssemblys
using UnityEngine;
using System.Collections.Generic;
using UnityEditor;
using System.Text.RegularExpressions;
using System.IO;
using System.Text;
public class ReimportUnityEngineUI
{
[MenuItem( "Assets/Reimport UI Assemblies", false, 100 )]