Skip to content

Instantly share code, notes, and snippets.

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

Mohsin aljiwala

☯️
Present.
View GitHub Profile
@aljiwala
aljiwala / random_username_generator.py
Created February 27, 2017 18:00
Generate a random username for Django
from random import choice
from string import ascii_lowercase, digits
from django.contrib.auth.models import User
def generate_random_username(length=16, chars=ascii_lowercase+digits, split=4, delimiter='-'):
username = ''.join([choice(chars) for i in xrange(length)])
if split:
username = delimiter.join([username[start:start+split] for start in range(0, len(username), split)])
@aljiwala
aljiwala / random_string_generator.py
Created February 27, 2017 18:35
Generate Random String using Python
import random, string
def random_generator(size=6, chars=string.ascii_uppercase + string.digits):
"""
Usage:
>>> random_generator().lower()
'w9gz1z'
>>> random_generator(3, "6793YUIO")
'6U7'
"""
@aljiwala
aljiwala / client_key_and_secret_generator.py
Created February 28, 2017 06:38
Generate a suitable client key and secret
def generate_client_key():
"""
Generate a suitable client key
"""
api_key = hashlib.sha1(os.urandom(32)).hexdigest()
return api_key
def generate_client_secret():
"""
Generate a suitable client secret
@aljiwala
aljiwala / disposable_email_domains.py
Last active March 14, 2017 08:35
Python list of disposable email address domains.
"""
List of all disposable email service domains.
Possible usage:
- To prevent email address from temporary email services while registering users.
"""
DESPOSABLE_EMAIL_DOMAINS = [
'0-mail.com',
'027168.com',
'0815.ru',
@aljiwala
aljiwala / virtual_env_tutorial.sh
Created March 24, 2017 10:40
Install and run virtualenv with virtualenvwrapper on Ubuntu
# Run the following command:
sudo apt-get install python-setuptools python-dev build-essential
# Install pip:
sudo apt-get install python-pip
# Install `virtualenv`:
pip install virtualenv
@aljiwala
aljiwala / awesome_go_storage.md
Created March 24, 2017 14:56
Awesome Go Storage by gostor

Awesome Go Storage Awesome

A curated list of awesome Go storage projects and libraries. Inspired by awesome-go.

Contributing

Please take a quick gander at the contribution guidelines first. Thanks to all contributors; you rock!

If you see a package or project here that is no longer maintained or is not a good fit, please submit a pull request to improve this file. Thank you!

@aljiwala
aljiwala / levenshteinDistance.go
Created April 22, 2017 14:53
Measure Levenshtein Distance in Golang
func levenshteinDistance(s string, t string) int {
s = strings.ToLower(s)
t = strings.ToLower(t)
if s == t {
return 0
}
if len(s) == 0 {
return len(t)
}
if len(t) == 0 {
@aljiwala
aljiwala / compress_image.py
Created November 25, 2017 05:53
Compress the size of the given file with the particular `scale` until `max_size` limit is achieved.
from PIL import Image
from io import BytesIO
def compress_image(original_file, max_size, scale):
"""
It should compress the size of the given file with the particular `scale`
until `max_size` limit is achieved.
"""
assert(0.0 < scale < 1.0)
@aljiwala
aljiwala / case_insensitive_lookup_mixin.py
Created November 25, 2017 05:57
Mixin to any view or viewset to get kwargs with lowercase values. Based on a `lookup_field` attribute.
from rest_framework.generics import get_object_or_404
class CaseInsensitiveLookupMixin(object):
"""
Apply this mixin to any view or viewset to get kwargs with lowercase
values. Based on a `lookup_field` attribute.
"""
def get_object(self):
queryset = self.get_queryset() # Get the base queryset
@aljiwala
aljiwala / export-to-csv.gs
Created July 18, 2018 06:47 — forked from mderazon/export-to-csv.gs
Google apps script to export to individual csv files all sheets in an open spreadsheet
/*
* script to export data in all sheets in the current spreadsheet as individual csv files
* files will be named according to the name of the sheet
* author: Michael Derazon
*/
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var csvMenuEntries = [{name: "export as csv files", functionName: "saveAsCSV"}];
ss.addMenu("csv", csvMenuEntries);