Skip to content

Instantly share code, notes, and snippets.

View aljiwala's full-sized avatar

Mohsin aljiwala

View GitHub Profile
aljiwala /
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.
Examples can be given using either the ``Example`` or ``Examples``
sections. Sections support any reStructuredText formatting, including

Keybase proof

I hereby claim:

  • I am aljiwala on github.
  • I am aljiwala ( on keybase.
  • I have a public key ASAVREBd3BSfzkZGpjGWKOxdUJWDwHPjcJkfnyQ28YpjIAo

To claim this, I am signing this object:

aljiwala /
Created July 26, 2018 12:09
Get meta keywords and description from website.
def get_soup(url):
# Func which should return `BeautifulSoup` object.
def get_meta_from_website(url, attrs=['description', 'keywords']):
Should return meta data from given website URL.
* Receives:
- url (string)
aljiwala /
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
import requests
from time import sleep
from bs4 import BeautifulSoup
def extract_from_ed_india():
final = list()
pages = range(1, 32)
for i in pages:
aljiwala /
Created July 18, 2018 06:47 — forked from mderazon/
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);
aljiwala /
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 /
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")
from store_app.models import MyModel
aljiwala /
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 /
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)