Skip to content

Instantly share code, notes, and snippets.

@xyb
xyb / jnote.py
Last active November 13, 2024 08:13
scripts to setup joplin web clipper api token and create new note
#!/usr/bin/env python3
"""
Joplin Note Creator
A command line tool to create notes in Joplin. Features:
- Create notes from stdin or clipboard
- Specify note title
- Create notes in specific folders (supports partial folder name matching)
Usage:
@xyb
xyb / wgetserver.py
Created October 11, 2024 16:17
http server for offline website retrieved by wget --mirror
# serve your offline website static files retrieved by:
# wget --mirror --convert-links --adjust-extension --page-requisites --no-parent
# usage:
# python3 wgetserver.py [-p 8080]
import http.server
import os
import argparse
class CustomHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
@xyb
xyb / shell.py
Created September 30, 2024 04:29 — forked from ddahan/shell.py
FastAPI context-aware shell with model discovery and other auto-imports
# Requires Python 3.12+, IPython, rich
import datetime
import hashlib
import importlib
import inspect
import json
import logging
import os
import pkgutil
@xyb
xyb / excel.py
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
xyb / middleware.py
Last active August 23, 2023 05:32 — forked from tclancy/middleware.py
Django middleware for Pympler (compatible with Django 2.0+)
# Derived from Piotr Maliński's example with a few modifications to use logging and :
# http://www.rkblog.rk.edu.pl/w/p/profiling-django-object-size-and-memory-usage-pympler/
import logging
import os
from django.conf import settings
from pympler import muppy
from pympler.asizeof import asizeof
from pympler.muppy import summary
@xyb
xyb / osdb_hash.py
Last active August 20, 2023 12:09
compute osdb (opensubtitles.org) hash code with the file size value, allowing to not download the entire file
import struct
import os
BLOCK_SIZE = 65536
MIN_SIZE = BLOCK_SIZE * 2
# based on https://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes#Python
def osdb_hash(filename, filesize=0):
try:
@xyb
xyb / frontend-deploy-with-k8s.md
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
xyb / excel_tools.py
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
xyb / convert-excel-to-csv.py
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 = wb.active
@xyb
xyb / unmerge-excel-cell-and-export-as-csv.py
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