Skip to content

Instantly share code, notes, and snippets.

@longbowking
longbowking / make_pdf_with_a_list_of_images.py
Last active June 28, 2022 12:01
convert a list of images into pdf file
"""
pip install Pillow
https://datatofish.com/images-to-pdf-python/
https://code-maven.com/create-images-with-python-pil-pillow
https://stackoverflow.com/a/67649020/8671516
"""
import os
from os.path import join as pjoin
from pathlib import Path
@longbowking
longbowking / glibc-check.sh
Last active April 22, 2020 16:17 — forked from fasterthanlime/glibc-check.sh
Prints the various glibc versions required by an executable
#!/bin/bash
# This scripts lets you check which minimum GLIBC version an executable requires.
# Simply run './glibc-check.sh path/to/your/binary'
#
# You can set `MAX_VER` however low you want, although I (fasterthanlime)
# Ubuntu 12.04 has GLIBC 2.15
# Centos 6.9 has GLIBC 2.12
# Centos 7.4 has GLIBC 2.17
@longbowking
longbowking / numpy_tricks.py
Last active March 8, 2020 16:27
useful numpy math utils/methods collection
def sparse_image_arr(arr: np.ndarray, sparsity):
"""
sparse image array according to image intensity
"""
assert arr.ndim == 4
arr_intensity = np.abs(arr).sum(axis=-1) # [B, H, W]
percentile = int((1-sparsity)*100)
thres = np.percentile(arr_intensity, percentile, axis=[1,2]) # [B,]
thres = thres.reshape(thres.shape + (1,) * 2) # [B, H, W]
mask = arr_intensity > thres # [B, W, W]
@longbowking
longbowking / particles_animation_to_letters.py
Created February 15, 2020 15:46
An animation: random particles converge to customized letters in a given time period.
# """
# Author: longbowking
# Email: zhjhe@foxmail.com
# Create time: 2020/2/15
# """
# https://scikit-image.org/docs/dev/auto_examples/edges/plot_skeleton.html
from time import time
@longbowking
longbowking / convert-docx-to-html.py
Last active January 9, 2025 08:37 — forked from phillipkent/convert-docx-to-html.py
Convert a DOCX file to HTML (using python-docx)
# Converts a docx file with tables and images to (simple) HTML
# ORIGINAL CODE BY DAVID SSALI AT SOURCE: https://medium.com/@dvdssali/docx-to-html-1374eb6491a1
#
# Requires the Python module 'python-docx' <https://python-docx.readthedocs.io>
#
# Example use:
# >>> s = convert('./SOURCEDIR', 'SAMPLE.docx')
# >>> print(s)
# or
# $ python .\convert-docx-to-html.py > temp.html
@longbowking
longbowking / convert-docx.py
Last active April 30, 2019 02:49 — forked from phillipkent/convert-docx.py
Convert a DOCX file to another DOCX file (using python-docx)
# Converts a docx file with tables and images to a new docx file
# The new file is based on a 'stub' document which contains preamble text and styles
#
# Requires the Python module 'python-docx' <https://python-docx.readthedocs.io>
# Written for Python 3
#
# Source documents are taken from the directory 'source' and converted documents are saved
# to the directory 'converted'
#
# Two types of source documents are handled: 'Fiscal Guide' or 'Economics Regime'. Each one