Skip to content

Instantly share code, notes, and snippets.

xyb /
Created November 2, 2023 03:41
generate reproducable excel file with openpyxl
# requires:
# pip install openpyxl repro-zipfile
from pathlib import Path
import openpyxl
from repro_zipfile import ReproducibleZipFile
def save_reproducible_excel(path: Path, workbook: openpyxl.Workbook) -> None:
"""save a reproducible/deterministic excel file
xyb /
Last active August 23, 2023 05:32 — forked from tclancy/
Django middleware for Pympler (compatible with Django 2.0+)
# Derived from Piotr Maliński's example with a few modifications to use logging and :
import logging
import os
from django.conf import settings
from pympler import muppy
from pympler.asizeof import asizeof
from pympler.muppy import summary
xyb /
Last active August 20, 2023 12:09
compute osdb ( hash code with the file size value, allowing to not download the entire file
import struct
import os
BLOCK_SIZE = 65536
# based on
def osdb_hash(filename, filesize=0):
xyb /
Created April 6, 2023 05:59
Deploying a Frontend Application with Dynamic Environment Variables Using Docker, Kubernetes, and Nginx

Deploying a Frontend Application with Dynamic Environment Variables Using Docker, Kubernetes, and Nginx

This guide demonstrates how to deploy a frontend application using Docker and Kubernetes (k8s) with dynamic environment variables that can change across different namespaces. We will use Nginx as a web server to serve the frontend static files.

1. Create a Dockerfile

Create a Dockerfile for your frontend project:

# Use a Node.js base image
FROM node:14 AS build
xyb /
Created April 4, 2023 08:39
some functions to help read or generate excel files
import csv
import io
import logging
import openpyxl
logger = logging.getLogger("excel")
def excel_to_csv(path):
xyb /
Created March 23, 2023 08:09
convert excel to csv
import openpyxl
import csv
import sys
input = sys.argv[1]
output = sys.argv[2]
print(f'{input} ==> {output}')
wb = load_workbook(input)
sh =
xyb /
Last active March 23, 2023 08:07
unmerge excel cell and export as csv
#!/usr/bin/env python3
# Usage: $0 input.xlsx output.csv
from openpyxl.workbook import Workbook
from openpyxl import load_workbook
from openpyxl.utils.cell import range_boundaries
import sys
import csv
xyb /
Last active February 17, 2023 03:23
get audio volumes samples, assited by ChatGPT
from pydub import AudioSegment
import numpy as np
def get_volumes(audio_path, format, chunks_number=100):
audio = AudioSegment.from_file(audio_path, format=format)
segment_length = len(audio) // chunks_number
volumes = []
for i in range(chunks_number):
xyb /
Last active May 5, 2024 20:47 — forked from ukn/
Install the kernal module required for the facetimehd camera to work on Linux
set -e
# For current kernel
export KERNELRELEASE=$(cat /proc/version | awk '{print $3}')
temp_dir=$(mktemp -d)
echo "Installing FacetimeHD camera for $KERNELRELEASE"
xyb / crx2zip.nim
Last active January 11, 2022 04:07
Convert CRX to zip file
# Convert CRX to zip file.
# Inspired by
# nim c -d:release --gc:none --stackTrace:off --lineTrace:off --opt:size uncrx.nim
import system
import os
import streams
import strutils
zipMagicNumber = "PK\x03\x04"