Skip to content

Instantly share code, notes, and snippets.

View e4c5's full-sized avatar
💭
Save trees

Raditha Dissanayake e4c5

💭
Save trees
View GitHub Profile
@e4c5
e4c5 / paginator
Last active January 7, 2022 14:29
The django admin change_list template causes the execution of the 'select count(*) from table_name' type query which can be very slow when the table has a few million entries. The problem is better described at https://code.djangoproject.com/ticket/8408 The following custom paginator will solve this issue by caching the row count for a short per…
import collections
from math import ceil
from django.core.paginator import Page
from django.core.cache import cache
# To use the paginator, add the following to your admin class:
# from myapp import CachingPaginator
#
# ...
@e4c5
e4c5 / round_robin.py
Last active February 9, 2024 08:05
A round robing pairing generator where you are control the round in which certain players get the bye or meet certain other players. If a large number of rounds need to be fixed in this manner and they involve players other than the Bye, there is no guarantee that a pairing exists.
import sys
import random
from itertools import permutations
class RoundRobin(object):
'''
Usage:
r = RoundRobin(['Bye','Nigel','Wellignton','Andrew','Sherwin','Chollapat','David','Craig'])
r.fix_pairing('Nigel',5, 'Bye')
r.fix_pairing( 'Craig',0,'Bye')
@e4c5
e4c5 / docker-cleanup-resources.md
Created February 12, 2018 08:42 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm