Skip to content

Instantly share code, notes, and snippets.

View egasimus's full-sized avatar
🐒
all our telepaths are on leave and the ascended master is currently downshifting

egasimus

🐒
all our telepaths are on leave and the ascended master is currently downshifting
View GitHub Profile
@egasimus
egasimus / cbv_factory.py
Last active October 25, 2020 00:00
Django CBV factory function, with example usage.
from inspect import isfunction
from django.views.generic import View, CreateView, UpdateView, DeleteView, DetailView, ListView
from django.views.generic.edit import ModelFormMixin
from django.views.generic.detail import SingleObjectMixin
def parse_func_dict(selfobj, d):
"""
Recursively goes through a dict, calling functions that refer to a view's
self and therefore need to be called from within -- such as getting extra
kwargs for a form constructor based on request data.
@egasimus
egasimus / Readme.md
Last active January 5, 2021 08:55
A few remarks on the Django REST Framework

A few remarks on the Django REST Framework

For a good while, I've been interested in the topic of automatically generating and routing views. For my last project, I built a haphazard implementation which ran using an elaborate scheme of mixins and decorators. A veritable monstrosity, it was - and the cognitive load of working with it wasted over a month of my time, allowing the project to slowly descend into limbo. I eventually ended up re-writing the heaps of class-based views by hand. Even though making good use of inheritance helped me tremendously, it was still a chore, and my interest in a tool that would save me some boilerplate code for standard CRUD apps remained.

When I first got a glimpse of the Django REST Framework, I was quite impressed by the browsable API; a quick look at the documentation got me hooked onto the concept of ViewSets and Routers. A few days ago, I decided to finally get my feet wet with the DRF and use it in my latest project. I honestly believed that it would b

@egasimus
egasimus / gist:8352602
Created January 10, 2014 14:02
Simple M2M filter for Django admin.
class M2MFilter(admin.SimpleListFilter):
title = _('yourm2mfield')
# Parameter for the filter that will be used in the URL query.
parameter_name = 'yourm2mfield'
def lookups(self, request, model_admin):
return ((x.pk, x.title) for x in YourRelatedModel.objects.all())
def value(self):
@egasimus
egasimus / 1_models.py
Last active August 29, 2015 13:56
django-parler m2m errors
# Here's a pretty basic model with a translatable M2M field.
class ContentItem(TranslatableModel):
translations = TranslatedFields(
title = models.CharField(max_length=200),
content = models.TextField(blank=True),
primary_media = models.ForeignKey(
Hassan shrieks out: "This is your doing, A.J.! You
poopa my party!"
A.J. looks at him, face remote as limestone: "Uppa
your ass, you liquefying gook."
A horde of lust-mad American women rush in.
Dripping cunts, from farm and dude ranch, factory,
brothel, country club, penthouse and suburb, motel
and yacht and cocktail bar, strip off riding clothes, ski
togs, evening dresses, levis, tea gowns, print dresses,
slacks, bathing suits and kimonos. They scream and
Out of sandbox:
[ 1, 2, { '3': 4 } ]
[1 2 {"3" 4}]
Inside of sandbox:
[ 1, 2, { '3': 4 } ]
[ 1, 2, { '3': 4 } ]

Rock and Roll adolescent hoodlums storm the streets of all nations. They rush into the Louvre and throw acid in the Mona Lisa's face. They open zoos, insane asylums, prisons, burst water mains with air hammers, chop the floor out of passenger plane lavatories, shoot out lighthouses, file elevator cables to one thin wire, turn sewers into the water supply, throw sharks and sting rays, electric eels and candiru into swimming pools (the candiru is a small eel-like fish or worm about one-quarter inch through and two inches long patronizing certain rivers of ill repute in the Greater Amazon Basin, will dart up your prick or your asshole or a woman's cunt faute de mieux, and hold himself there by sharp spines with precisely what motives is not known since no one has stepped forward to observe the candiru's life-cycle in situ), in nautical costumes ram the Queen Mary full speed into New York Harbor, play chicken with passenger planes and busses, rush into hospitals in white coats carrying saws and axes and sca

It is also crucial to bear in mind the interconnection between the Decalogue... and its modern obverse, the celebrated 'human Rights'. As the experience of our post-political liberal-permissive society amply demonstrates, human Rights are ultimately, at their core, simply Rights to violate the Ten Commandments. 'The right to privacy' — the right to adultery, in secret, where no one sees me or has the right to probe my life. 'The right to pursue happiness and to possess private property' -- the right to steal (to exploit others). 'Freedom of the press and of the expression of opinion' -- the right to lie. 'The right of free citizens to possess weapons' -- the right to kill. And, ultimately, 'freedom of religious belief' — the right to worship false gods.

@egasimus
egasimus / tiny.js
Last active March 8, 2017 18:36
Self-updating Node.js module in ~39SLOC
var fs = require('fs')
var path = require('path')
var vm = require('vm')
module.exports = {
watch:
function (module) {
fs.watch(module.filename, function (event, filename) {
module.exports.changed(module, this, event, filename); }) },
@egasimus
egasimus / keybase.md
Last active September 10, 2019 10:59

Keybase proof

I hereby claim:

  • I am egasimus on github.
  • I am egasimus (https://keybase.io/egasimus) on keybase.
  • I have a public key ASCNEQV8gWIvCTHEpQqLHsaivEy76Jt8Ysb-Xhgv2kt_BAo

To claim this, I am signing this object: