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 / 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)
@aljiwala
aljiwala / levenshteinDistance.go
Created Apr 22, 2017
Measure Levenshtein Distance in Golang
View levenshteinDistance.go
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 Mar 24, 2017
Awesomeness of Golang by uhub
View Awesome_GO.md

#awesome-go

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

You can’t perform that action at this time.