Skip to content

Instantly share code, notes, and snippets.

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

Mohsin aljiwala

☯️
Present.
View GitHub Profile
@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 / Awesome_GO.md
Created March 24, 2017 14:59
Awesomeness of Golang by uhub

#awesome-go

A curated list of awesome Go frameworks, libraries and software.

@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 / 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 / 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 / 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 / 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 / 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 / s3_meta.py
Created February 24, 2017 21:02
Script to update the metadata on Amazon S3
"""
To run the script
s3_meta.py --access-key=AWS_ACCESS_KEY_ID
--secret-key=AWS_SECRET_ACCESS_KEY
--bucket-name=BUCKET_NAME
-d=METADATA
e.g.
python s3_meta.py --access_key=AKIAIOSFODNN7EXAMPLE --secret-key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY --bucket-name=test-bucket -d '{"Cache-Control": "max-age=3600"}'
"""
@aljiwala
aljiwala / time_celery_task.py
Created January 6, 2017 14:46
Log execution time for every Celery task (Celery 3.1.x)
import logging
import time
from celery import shared_task as orig_shared_task
def timeit(func):
"""A decorator used to log the function execution time."""
logger = logging.getLogger('tasks')