Skip to content

Instantly share code, notes, and snippets.

View devxpy's full-sized avatar

Dev Aggarwal devxpy

View GitHub Profile
@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:
@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 / aplay_player.py
Created April 1, 2018 15:59
A music player in python that uses aplay as backend, written using zproc ( https://github.com/devxpy/zproc )
# pip install delegator.py zproc
# (python3.6 only!)
#
# python aplay_player.py
# (remember to set path to an audio file of your choice at bottom)
import atexit
import os
import signal
from pathlib import Path
$ flutter doctor --verbose
[✓] Flutter (Channel beta, v0.5.1, on Linux, locale en_US.utf8)
• Flutter version 0.5.1 at /home/dev/Apps/flutter
• Framework revision c7ea3ca377 (6 weeks ago), 2018-05-29 21:07:33 +0200
• Engine revision 1ed25ca7b7
• Dart version 2.0.0-dev.58.0.flutter-f981f09760
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.1)
• Android SDK at /home/dev/Android/Sdk
• Android NDK location not configured (optional; useful for native profiling support)
somevar = 60
def outer():
somevar = -1
def inner(num):
return "My answer is " + str(num + 1)
return fnhash(inner)
@devxpy
devxpy / toy_robot.py
Created October 16, 2018 11:05
The toy robot problem, using python decorators
def pos_safe(fn):
def wrapper(self):
old = self._pos.copy()
fn(self)
for i in range(2):
if not (0 <= self._pos[i] <= self.bounds[i]):
self._pos = old
raise ValueError("Robot shall not pass!")
self.curpos()
@devxpy
devxpy / .gitignore
Created October 25, 2018 09:43
Gitignore for python + pycharm dev
.idea
zproc/*.c
zproc/*.so
# Created by https://www.gitignore.io/api/python,pycharm
### PyCharm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
def roundrobin(pending):
remaining = set(pending)
index = 0
while remaining:
for requester in list(remaining):
try:
if process_success(requester, pending[requester][index]):
del pending[requester][index]
except IndexError:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
dot-wave dot {
display: inline-block;
width: 12px;
@devxpy
devxpy / test.dart
Last active February 7, 2019 06:36
A demo of how to create a structure of chapter-wise lessons, from a Set of Lesson objects
import 'package:meghshala_app_flutter/core/dynamodb.dart';
import 'package:meghshala_app_flutter/core/lesson_store.dart';
// fetch lessons from database
Set<Lesson> lessons = await DynamoDB.listLessons();
// or, fetch from local storage
Set<Lesson> lessons = await LessonStore.getLessons();