Skip to content

Instantly share code, notes, and snippets.

View aljiwala's full-sized avatar
☯️
Present.

Mohsin aljiwala

☯️
Present.
View GitHub Profile
@aljiwala
aljiwala / celery.sh
Created January 4, 2017 14:08
Basic Celery Useful Commands
/* Useful celery config.
app = Celery('tasks',
broker='redis://localhost:6379',
backend='redis://localhost:6379')
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
CELERY_QUEUES=(
Queue('default', routing_key='tasks.#'),
@aljiwala
aljiwala / traverse.py
Last active December 23, 2016 09:46
Traverse Generator Function in Python
def traverse(o, tree_types=(list, tuple)):
if isinstance(o, tree_types):
for value in o:
for subvalue in traverse(value, tree_types):
yield subvalue
else:
yield o
data = [(1,1,(1,1,(1,"1"))),(1,1,1),(1,),1,(1,(1,("1",)))]
print list(traverse(data))
@aljiwala
aljiwala / app.js
Last active December 3, 2016 20:44
Google Maps/Places Autocomplete (AngularJS Directive)
var myApp = angular.module('myApp', []);
myApp.directive('googleplace', function() {
return {
require: 'ngModel',
link: function(scope, element, attrs, model) {
var options = {
types: [],
componentRestrictions: {}
};
@aljiwala
aljiwala / linked_list.py
Created November 29, 2016 05:51
Linked List Implementation (Python)
class Node :
def __init__( self, data ) :
self.data = data
self.next = None
self.prev = None
class LinkedList :
def __init__( self ) :
self.head = None
@aljiwala
aljiwala / get_pip.py
Created November 7, 2016 10:34
Get Pip (Python)
This file has been truncated, but you can view the full file.
#!/usr/bin/env python
#
# Hi There!
# You may be wondering what this giant blob of binary data here is, you might
# even be worried that we're up to something nefarious (good for you for being
# paranoid!). This is a base85 encoding of a zip file, this zip file contains
# an entire copy of pip.
#
# Pip is a thing that installs packages, pip itself is a package that someone
# might want to install, especially if they're looking to run this get-pip.py
@aljiwala
aljiwala / bin_packing.py
Created November 4, 2016 07:30
Bin Packing Algorithm
''' Partition a list into sublists whose sums don't exceed a maximum
using a First Fit Decreasing algorithm.
'''
class Bin(object):
''' Container for items that keeps a running sum '''
def __init__(self):
self.items = []
self.sum = 0
@aljiwala
aljiwala / read_related_notifications.py
Created October 27, 2016 10:40
Mark Notification as Read automatically after visiting that URL!
@aljiwala
aljiwala / admin.py
Created October 27, 2016 09:56
Unicode usernames in Django admin panel
"""
This code aims to override the username's regex of the Django admin panel to be
able to allow unicode usernames.
Just add this code to an app as admin.py and everything will be done.
"""
import re
from django import forms
from django.contrib import admin
@aljiwala
aljiwala / database_router_settings.py
Last active September 16, 2023 14:57
Django Database Router using Settings
from django.conf import settings
 
class DatabaseAppsRouter(object):
    """
    A router to control all database operations on models for different
    databases.
 
    In case an app is not set in settings.DATABASE_APPS_MAPPING, the router
    will fallback to the `default` database.