Skip to content

Instantly share code, notes, and snippets.

☯️
Present.

Mohsin aljiwala

☯️
Present.
Block or report user

Report or block aljiwala

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@aljiwala
aljiwala / example_google.py
Created Apr 6, 2020
Google Style Python Docstrings: Example
View example_google.py
# -*- 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
View keybase.md

Keybase proof

I hereby claim:

  • I am aljiwala on github.
  • I am aljiwala (https://keybase.io/aljiwala) on keybase.
  • I have a public key ASAVREBd3BSfzkZGpjGWKOxdUJWDwHPjcJkfnyQ28YpjIAo

To claim this, I am signing this object:

@aljiwala
aljiwala / meta_from_website.py
Created Jul 26, 2018
Get meta keywords and description from website.
View meta_from_website.py
def get_soup(url):
# Func which should return `BeautifulSoup` object.
pass
def get_meta_from_website(url, attrs=['description', 'keywords']):
"""
Should return meta data from given website URL.
* Receives:
- url (string)
View parse_url.py
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
View education_india_in_extractor.py
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
aljiwala / export-to-csv.gs
Created Jul 18, 2018 — forked from mderazon/export-to-csv.gs
Google apps script to export to individual csv files all sheets in an open spreadsheet
View export-to-csv.gs
/*
* 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
aljiwala / n_sized_chunks.py
Last active Jul 24, 2018
Divide CSV data into chunks
View n_sized_chunks.py
# 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 Mar 14, 2018
Django Standalone Script
View standalone_script.py
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
@aljiwala
aljiwala / case_insensitive_lookup_mixin.py
Created Nov 25, 2017
Mixin to any view or viewset to get kwargs with lowercase values. Based on a `lookup_field` attribute.
View case_insensitive_lookup_mixin.py
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 / compress_image.py
Created Nov 25, 2017
Compress the size of the given file with the particular `scale` until `max_size` limit is achieved.
View compress_image.py
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)
You can’t perform that action at this time.