Skip to content

Instantly share code, notes, and snippets.

View devxpy's full-sized avatar

Dev Aggarwal devxpy

View GitHub Profile
@devxpy
devxpy / midi_numbers.py
Last active June 17, 2025 17:59
A python script that converts MIDI message numbers to notes and instruments (and vice-versa)
INSTRUMENTS = [
'Acoustic Grand Piano',
'Bright Acoustic Piano',
'Electric Grand Piano',
'Honky-tonk Piano',
'Electric Piano 1',
'Electric Piano 2',
'Harpsichord',
'Clavi',
'Celesta',
@devxpy
devxpy / forms.py
Last active January 20, 2018 21:09
Django dynamic Authentication Form that works with Custom Backends. Can also be used as a drop-in replacement for django-admin login
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth import forms as auth_forms, authenticate, get_user_model
from django.utils.text import capfirst
UserModel = get_user_model()
class DynamicAuthenticationForm(auth_forms.AuthenticationForm):
"""
@devxpy
devxpy / create_user.py
Created December 31, 2017 07:54
Django create user view that dynamically selects the authentication method, based on a groupdomain object thats one-to-one with the Group and profile which is one-to-one with the User
def create_user(request):
redirect_to = request.POST.get(REDIRECT_FIELD_NAME,
request.GET.get(REDIRECT_FIELD_NAME, urlresolvers.reverse(user_panel)))
group = get_object_or_404(GroupDomain, domain=request.META['HTTP_HOST']).group
verification_methods = group.groupdomain.verification_method
ctx_forms = {'grade': forms.GradeForm}
# Get the appropriate forms based on the domain settings
if GroupDomain.USERNAME in verification_methods: