This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## this snippet allows you to fastly convert post from wordpress xml format to txt | |
from xml.dom.minidom import parse, parseString | |
import os | |
dom = parse('jobyme88.xml') # parse an XML file by name | |
os.path.makedirs('blogs') | |
items = dom.getElementsByTagName('item') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# extract pdf to jpg | |
from pdf2image import convert_from_path | |
from tqdm import tqdm | |
import os | |
import uuid | |
input_path = 'corridor.pdf' | |
uid = uuid.uuid4().hex[:4] | |
output_path = uid + '-' + input_path.split('.')[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_nan(a): | |
import math | |
import numpy as np | |
if isinstance(a, float): | |
return math.isnan(a) | |
elif isinstance(a, np.float64): | |
return np.isnan(a) | |
else: | |
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%Source: https://www.overleaf.com/learn/latex/code_listing% | |
\usepackage{listings} | |
\usepackage{xcolor} | |
\definecolor{codegreen}{rgb}{0,0.6,0} | |
\definecolor{codegray}{rgb}{0.5,0.5,0.5} | |
\definecolor{codepurple}{rgb}{0.58,0,0.82} | |
\definecolor{backcolour}{rgb}{0.95,0.95,0.92} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: https://www.kaggle.com/lopuhin/panda-2020-level-1-2 | |
def crop_white(image: np.ndarray, value: int = 255) -> np.ndarray: | |
assert image.shape[2] == 3 | |
assert image.dtype == np.uint8 | |
ys, = (image.min((1, 2)) < value).nonzero() | |
xs, = (image.min(0).min(1) < value).nonzero() | |
if len(xs) == 0 or len(ys) == 0: | |
return image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# you have run this code in .py file (cannot be in .ipynb) | |
# you have to add the head `if __name__ == '__main__':` | |
if __name__ == '__main__': | |
start = time.time() | |
img_ids = df.image_id.values # a list | |
pool = Pool(processes=multiprocessing.cpu_count()) | |
pool.map(crop_all_img, img_ids) # (function, list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# detect two duplicate photos | |
# 1 get hash function | |
import cv2 | |
import imagehash | |
funcs = [ | |
imagehash.average_hash, | |
imagehash.phash, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
</head> | |
<body> | |
<form> | |
<input type='text'></input> | |
<select id='voiceSelect'></select> | |
<input type="submit"></input> | |
</form> | |
<script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def soundex(string): | |
# keep first letter of a string | |
string = string.lower() | |
result = string[0] | |
string = string[1:] | |
OlderNewer