Skip to content

Instantly share code, notes, and snippets.

View khanfarhan10's full-sized avatar
🎯
Focusing

Farhan Hai Khan khanfarhan10

🎯
Focusing
View GitHub Profile
@khanfarhan10
khanfarhan10 / blog.md
Created August 13, 2023 22:10 — forked from Atlas7/blog.md
Inline commenting within a Jinja2 HTML template

Learnt something new today. If we are to perform an inline commenting within a Jinja2 HTMl template...

The following will be rendered as a comment - via the {# and #} tags.

{# {{ Hello World }} #}

The following however may cause problem - because Jinja2 will try to parse the Python variable Hello and World, which may not exist.

@khanfarhan10
khanfarhan10 / py38-success.ipynb
Created November 28, 2022 02:55 — forked from ngrislain/py38-success.ipynb
py38 success.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@khanfarhan10
khanfarhan10 / gifextract.py
Created August 25, 2022 19:22 — forked from BigglesZX/gifextract.py
Extract frames from an animated GIF, correctly handling palettes and frame update modes
import os
from PIL import Image
'''
I searched high and low for solutions to the "extract animated GIF frames in Python"
problem, and after much trial and error came up with the following solution based
on several partial examples around the web (mostly Stack Overflow).
There are two pitfalls that aren't often mentioned when dealing with animated GIFs -
from PyPDF2 import PdfFileWriter, PdfFileReader
# https://stackoverflow.com/questions/490195/split-a-multi-page-pdf-file-into-multiple-pdf-files-with-python#490203
def pdf_split(fname, start, end=None):
print('pdf_split', fname, start, end)
# pdf_split ~/Downloads/4-27-files/Invoice Email-0.pdf 1 4
#inputpdf = PdfFileReader(open("document.pdf", "rb"))
inputpdf = PdfFileReader(open(fname, "rb"))
@khanfarhan10
khanfarhan10 / repermute.py
Created November 17, 2021 09:01 — forked from Quacky2200/repermute.py
generate all possible permutations of a regex (Python v3)
# -*- coding: utf-8 -*-
#
# Used like this:
#
# from repermute import ipermute
#
# for s in ipermute('[A-Z]\d'):
# print s
#
# Almost all regular expression constructs are supported except for '*'
%%%%%%%%%%%%%%%%%
% This is an example CV created using altacv.cls (v1.1.3, 30 April 2017) written by
% LianTze Lim (liantze@gmail.com), based on the
% Cv created by BusinessInsider at http://www.businessinsider.my/a-sample-resume-for-marissa-mayer-2016-7/?r=US&IR=T
%
%% It may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%% http://www.latex-project.org/lppl.txt

One can use MD5 or plain text diff to see differences in PDF files. If that's not enough, here's how to use diff-pdf which knows how to diff based on appearance or words:

  • brew install diff-pdf
  • edit your ~/.gitconfig to add this:
[difftool "diffpdf"]
  cmd = diff-pdf --view \"$LOCAL\" \"$REMOTE\"
@khanfarhan10
khanfarhan10 / streamlit_colab.ipynb
Created November 6, 2020 06:33 — forked from tuffacton/streamlit_colab.ipynb
Colaboratory Notebook that hosts a streamlit app and creates an ngrok https tunnel for access.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Problem

A lot of GitHub projects need to have pretty math formulas in READMEs, wikis or other markdown pages. The desired approach would be to just write inline LaTeX-style formulas like this:

$e^{i \pi} = -1$

Unfortunately, GitHub does not support inline formulas. The issue is tracked here.

Investigation

@khanfarhan10
khanfarhan10 / scrapeImages.py
Created March 9, 2020 08:11 — forked from genekogan/scrapeImages.py
scraping full size images from Google Images
from bs4 import BeautifulSoup
import requests
import re
import urllib2
import os
import argparse
import sys
import json
# adapted from http://stackoverflow.com/questions/20716842/python-download-images-from-google-image-search