Skip to content

Instantly share code, notes, and snippets.

@bockor
bockor / gist:ba6f15942182add36a576f22404cf506
Created August 16, 2026 07:25
Python sqlite3.Connection.row_factory
"""
Ref: https://zetcode.com/python/sqlite3-connection-row-factory/
See also: https://zetcode.com/python/sqlite3-row-keys/
"""
import sqlite3
from collections import namedtuple
@bockor
bockor / gist:08cbdd4c7e09ca3cc3eba49873fe4d5d
Last active August 2, 2026 14:23
find illegal unicode charaters in a csv file
Relevant unicode characters reference: https://www.unicode.org/charts/PDF/U2000.pdf
how to type an unicode character in Linux:
CTRL + Shift + U2014 Enter
how to type an unico character in Windoze: (not sure here !)
NumLock ON Alt Down 0151
file_with_illegal_characters.csv
--------------------------------
@bockor
bockor / gist:0774c689c4dfd3f7abac3275130a48b2
Created June 27, 2026 16:35
FIND NETWORK HIERARCHIES in SQLITE using Simple Recursion with Common Table Expressions ( CTE )
FIND NETWORK HIERARCHIES in SQLITE
using
Simple Recursion with Common Table Expressions ( CTE )
======================================================
Ref: https://www.youtube.com/watch?v=7GpyHedM4pw
Ref: https://douglaskline.blogspot.com/2016/06/simple-recursion-in-sql-with-common.html
Recursive CTE Principle:
@bockor
bockor / gist:ae17c54aa13409521d1a66859b4a63ad
Created June 21, 2026 14:52
operations with jq - Command-line JSON processor
# https://stackoverflow.com/questions/74400075/how-to-select-based-on-a-substring-in-jq
# https://jqlang.org/manual/#conditionals-and-comparisons
# https://play.jqlang.org/s/ovqQqRTfNE_Zxw0
# https://www.youtube.com/watch?v=YrVR09v78Dc
curl -s 'https://api.github.com/repos/jqlang/jq/commits?per_page=80' | jq -r '.[].commit.author | select (.email | contains(".us"))'
curl -s 'https://api.github.com/repos/jqlang/jq/commits?per_page=80' | jq '.[].commit.author | select (.email | contains("github") | not) '
curl -s 'https://api.github.com/repos/jqlang/jq/commits?per_page=80' | jq --arg n "github" '.[].commit.author | select (.email | contains($n)) '
@bockor
bockor / gist:d629d5717fb484e5724d501b0a828e69
Created May 17, 2026 14:20
Matching IPs to Subnets in Python in an Efficient Way // python // PyTricia
"""
PyTricia : Matching IPs to Subnets in Python in an Efficient Way
https://jmanteau.fr/posts/matching-ips-to-subnets-in-python-in-an-efficient-way/
https://github.com/jsommers/pytricia
https://www.youtube.com/watch?v=i5zP7iiw91Y ;
What is Python Pickle? A Beginner’s Guide to Data Serialization
@bockor
bockor / gist:d751e252c5bb459bd4c6fe6934a46818
Last active August 23, 2025 14:39
hosting-multiple-flask-apps-using-apache-mod_wsgi
# Inspiration ... where did I start ?:
# https://www.blopig.com/blog/2021/05/hosting-multiple-flask-apps-using-apache-mod_wsgi/
# https://www.rosehosting.com/blog/how-to-install-flask-on-ubuntu-22-04-with-apache-and-wsgi/?srsltid=AfmBOoqkm3GW5tXYBQywDTb_Y6SuLD0URVm9OC3uBqO4QhtSHpndMbz-
# https://stackoverflow.com/questions/29882579/run-multiple-independent-flask-apps-in-ubuntu
# https://serverfault.com/questions/357108/what-permissions-should-my-website-files-folders-have-on-a-linux-webserver
sudo apt install apache2 -y
sudo systemctl status apache2
sudo apt install libapache2-mod-wsgi-py3
apachectl -M | grep wsgi
@bockor
bockor / gist:8ade83eef84cbc57da84390525838d2f
Created July 2, 2025 11:51
SQLITE DATE - TIME - DATETIME notes
SQLITE DATE - TIME - DATETIME YOUTUBE TUT
https://www.youtube.com/watch?v=nJRvz5Rhrx0
# Insert DEFAULT timestamp "now" as INTEGER
# and unixepoch prior SQLITE 3.38 (2022-02-22).
####################################################
create table t1 (c1 TEXT, c2 INTEGER DEFAULT (strftime('%s', 'now')));
insert into t1(c1) values ('drink'),('eat');
@bockor
bockor / gist:f3b450244ca72330f97ca1ed72da18e5
Created June 14, 2025 08:52
python dictionary nested get
"""
The walrus operator “:=” is an operator used to evaluate, assign, and return value from a single statement in Python.
It was introduced in Python 3.8
"""
sss = {'color': 'red', 'size': 'l', 'clips': {'number': 6, 'material': 'metal'}}
if value := sss.get("clips", {}).get("number"):
print(f"Number of clips: {value}")
"""
@bockor
bockor / gist:6a6b74b89ec22a59d8a6e77023baa3a8
Last active June 8, 2025 16:57
Convert a python dictionary into json format. Find and explain the errors
import json
my_favorite = {"product": "Stella", "flavors": ["walnut", "prune"], "ranking": None, "price": 1.15, "in_stock": False }
"""
json.dumps() function converts a subset of Python objects into a json string.
"""
my_favorite_json = json.dumps(my_favorite , indent=2, sort_keys=True)
print(my_favorite_json)
@bockor
bockor / gist:cbf433ef785470b578037a749c629b7c
Created April 30, 2025 06:37
playgarden for api - jwt
# app.py
# https://stackoverflow.com/questions/74213961/how-create-endpoints-in-multiple-files
# https://flask.palletsprojects.com/en/stable/blueprints/
from flask import Flask, jsonify, request
from candy import candy_bp
from beer import beer_bp
from netz import netz_bp