Skip to content

Instantly share code, notes, and snippets.

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

Mohsin aljiwala

☯️
Present.
View GitHub Profile
@aljiwala
aljiwala / example_google.py
Created April 6, 2020 13:47
Google Style Python Docstrings: Example
# -*- coding: utf-8 -*-
"""Example Google style docstrings.
This module demonstrates documentation as specified by the `Google Python
Style Guide`_. Docstrings may extend over multiple lines. Sections are created
with a section header and a colon followed by a block of indented text.
Example:
Examples can be given using either the ``Example`` or ``Examples``
sections. Sections support any reStructuredText formatting, including
@aljiwala
aljiwala / parse_url.py
Created July 26, 2018 10:19
Parse URL
from re import match
from urllib.parse import urlparse
from urllib.parse import ParseResult
def get_parsed_url(url):
p = urlparse(url, 'http')
netloc = p.netloc or p.path
path = p.path if p.netloc else ''
if not netloc.startswith('www.'):
netloc = 'www.' + netloc
@aljiwala
aljiwala / n_sized_chunks.py
Last active July 24, 2018 08:45
Divide CSV data into chunks
# Built-in imports.
from sys import argv
from os.path import join as join_path
# Third party imports.
from pandas import read_csv
def get_row_count(src_filepath):
with open(src_filepath, 'r') as f:
@aljiwala
aljiwala / standalone_script.py
Created March 14, 2018 11:32
Django Standalone Script
import sys, os, django
sys.path.append("/path/to/store") #here store is root folder(means parent).
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "store.settings")
django.setup()
from store_app.models import MyModel
@yydai
yydai / kafka-py.py
Last active September 27, 2018 16:58
python kafka consumer producer
# from: https://github.com/dpkp/kafka-python/blob/master/example.py
import threading, logging, time
import multiprocessing
from kafka import KafkaConsumer, KafkaProducer
class Producer(threading.Thread):
def __init__(self):
@ziadoz
ziadoz / install.sh
Last active April 20, 2024 10:18
Install Chrome, ChromeDriver and Selenium on Ubuntu 16.04
#!/usr/bin/env bash
# https://developers.supportbee.com/blog/setting-up-cucumber-to-run-with-Chrome-on-Linux/
# https://gist.github.com/curtismcmullan/7be1a8c1c841a9d8db2c
# https://stackoverflow.com/questions/10792403/how-do-i-get-chrome-working-with-selenium-using-php-webdriver
# https://stackoverflow.com/questions/26133486/how-to-specify-binary-path-for-remote-chromedriver-in-codeception
# https://stackoverflow.com/questions/40262682/how-to-run-selenium-3-x-with-chrome-driver-through-terminal
# https://askubuntu.com/questions/760085/how-do-you-install-google-chrome-on-ubuntu-16-04
# Versions
CHROME_DRIVER_VERSION=`curl -sS https://chromedriver.storage.googleapis.com/LATEST_RELEASE`
@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')
@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 / 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.
 
@brunogaspar
brunogaspar / README.md
Last active October 7, 2022 09:08
Install wkhtmltopdf on Ubuntu (14.04 64-bit) or (16.04 64-bit)

Install wkhtmltopdf on Ubuntu

This was tested on:

  • Ubuntu 14.04 x64
  • Ubuntu 16.04 x64

Installation