Skip to content

Instantly share code, notes, and snippets.

STATIONNAME:"87600=北京文艺广播,88700=CRI HitFM,90000=央广音乐之声,90500=CRI环球资讯,91500=CRI EasyFM,94500=北京新闻广播,96600=央广经济之声,97400=北京音乐广播,99600=央广中国交通广播,100600=北京京津冀之声,101800=CNR经典音乐广播,103900=北京交通广播,104400=央广老年之声,106100=央广中国之声,106600=央广文艺之声,102500=北京体育广播,88100=河北音乐广播,88300=河北农民广播,90800=河北经济广播电台,91000=河北生活广播,91100=天津生活台,91900=河北交通广播,92000=天津滨海台,92800=延庆人民广播电台,92900=顺义人民广播电台,93800=承德人民广播电台,94800=河北文艺广播,95100=廊房人民广播电台,97200=天津新闻,99300=河北交通广播,100300=廊房交通广播电台,105200=河北人民广播电台,107300=北京城市广播副中心之声"
@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