Skip to content

Instantly share code, notes, and snippets.

View Magnus167's full-sized avatar
🧘
thinking...

Palash Tyagi Magnus167

🧘
thinking...
View GitHub Profile
@Magnus167
Magnus167 / get_wiki_table_to_pandas.py
Last active August 16, 2022 20:58
Gist to read a Wikipedia table to pandas. Useful for data analysis in general thanks to bs4 and pandas
import pandas as pd
import bs4, requests
wiki_link = 'https://en.wikipedia.org/wiki/List_of_chess_grandmasters'
# link to wiki page
soup = bs4.BeautifulSoup(requests.get(wiki_link).text, 'html.parser')
# build the soup :P
table = pd.io.html.read_html(str(soup.find('table', id='grandmasters')))
@Magnus167
Magnus167 / padding.py
Created June 7, 2022 01:15
apply padding to strings (or lists) in python
def apply_padding(string, paddingLen, padding='.'):
if len(string) %2 != paddingLen % 2:
string = padding + string
if len(string) >= paddingLen:
return string
else:
return apply_padding(string=padding+string+padding, paddingLen=paddingLen)
inpList = ['apple', 'banana', 'orange', 'choco']
@Magnus167
Magnus167 / import_module_from_url.py
Created June 5, 2022 04:02
Import Python Module directly from URL
import urllib.request
a = urllib.request.urlopen(url)
eval(a.read())
# https://stackoverflow.com/a/47341399/4417821 - Xantium, StackOverflow
# ensure that depending url does't import any that may not exist on a system. use this only for simple scripts.
@Magnus167
Magnus167 / merge_pdfs.py
Created May 26, 2022 00:52
merge pdfs using a python script
# pip install merge-pdf
from merge_pdf import merge
import glob
output_file, outFolder, folder, folderFiles = 'merged_files.pdf', '.', '.', '.'
files_list=glob.glob(folder+'/*.pdf')
merge.Merge (output_file, debug= True).merge_file_list (files_list)
@Magnus167
Magnus167 / images_to_pdf.py
Created May 25, 2022 20:45
python script to convert images to pdfs
import img2pdf, glob, os
from tqdm import tqdm
def main():
os.makedirs(name='imgs_as_pdfs', exist_ok=True)
for img in tqdm(glob.glob('./*.png')):
with open(img, 'rb') as f:
pdf = img2pdf.convert(f)
with open(f'imgs_as_pdfs/{img[:-4]}.pdf', 'wb') as f:
f.write(pdf)
@Magnus167
Magnus167 / viewMD.html
Created May 20, 2022 00:47
HTM to load markdown life in browser
<! ––
usage:
host resume_pdf.htm on website
eg : magnus167.github.io/resume_pdf.htm
get raw link to md file
magnus167.github.io/resumeCV/resume_pdf.htm?src=https://raw.githubusercontent.com/Magnus167/resumeCV/master/resume.md
@Magnus167
Magnus167 / loops_lists_and_sums.ipynb
Created May 18, 2022 04:35
experiments in python to compare speeds of functions that use loops vs loops within lists
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Magnus167
Magnus167 / row_cutter.py
Last active May 12, 2022 20:58
python script to reduce horizontal white space in images from pdfs
import numpy as np
import PIL.Image as Image
import pdf2image
import sys, os, glob
from tqdm import tqdm
def get_files(path, ext='pdf'):
rChar = '/' if sys.platform == 'posix' else '\\'
return [f.split(rChar)[-1] for f in glob.glob(path + '/*.' + ext.lower())]