Skip to content

Instantly share code, notes, and snippets.

View dvarrazzo's full-sized avatar

Daniele Varrazzo dvarrazzo

View GitHub Profile
#!/bin/bash
# A backup solution based on rsync with hard links and no deletion of old images
# Deletion would be delegated to a script such as weeder
# https://pypi.org/project/weeder/
set -euo pipefail
set -x
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#!/usr/bin/env python3
"""Render a view of the k8s status in a namespace.
Example:
# Display the state in console
k8splore.py -n my-ns -c my-cx --format text
# Display the state as a graph, with some nodes omitted.
k8splore.py -n my-ns -c my-cx --drop-kind ReplicaSet Pod Job \\
@dvarrazzo
dvarrazzo / dfhash.py
Created February 1, 2020 13:59
Stable hash of Dockerfile content
#!/usr/bin/env python3
"""Emit an hash on stdout of a dockerfile and the files added by it.
- Dockerfile comments don't affect the hash value.
- If a directory is added by dockerfile, only the git-versioned files are
included in the hash.
- A single file hash matches md5sum result.
"""
import os
diff -u --recursive --new-file v1.1.41/linux/kernel/sched.c linux/kernel/sched.c
--- v1.1.41/linux/kernel/sched.c Wed Aug 3 09:32:33 1994
+++ linux/kernel/sched.c Tue Aug 9 09:34:45 1994
@@ -161,7 +161,7 @@
* information in task[0] is never used.
*
* The "confuse_gcc" goto is used only to get better assembly code..
- * Djikstra probably hates me.
+ * Dijkstra probably hates me.
*/
@dvarrazzo
dvarrazzo / exmany.py
Last active February 1, 2017 13:11
Test for a different implementation of psycopg executemany
import os
import time
import psycopg2
from psycopg2 import extensions as ext
def paginate(seq, page_size=100):
page = []
it = iter(seq)
while 1:
@dvarrazzo
dvarrazzo / timeenc.py
Created October 12, 2016 00:42
Benchmark program to measure psycopg decoding speed
"""
Test fetching unicode strings for the database.
"""
from __future__ import print_function
from timeit import Timer
def main():
opt = parse_cmdline()
@dvarrazzo
dvarrazzo / dedup.py
Created March 24, 2016 16:20
A psycopg2 namedtuple cursor de-duplicating repeated fields names
"""
An example of named tuple cursor de-duplicating repeated fields names.
This is **not** a good idea: it makes the program unpredictable. But if you put
the foot and really look for a gun...
See https://github.com/psycopg/psycopg2/issues/418
"""
from itertools import count
from collections import OrderedDict, namedtuple
@dvarrazzo
dvarrazzo / META.yaml
Last active January 13, 2016 11:23
Hypothetical definition of a PGXN package description in YAML
# This file specifies all information for a PGXN distribution. Full spec is at
# http://pgxn.org/spec/ *NOTE* A single distribution can contain multiple
# extensions! See http://pgxn.org/spec/#Terminology.
#
# Keys marked REQUIRED or Optional are what you'd expect. Keys marked Unusual
# are keys you don't normally need to use. The pgxntool Makefile will strip
# out empty keys to produce a working META.json, so it's fine to leave them
# here.
# REQUIRED. Name of distribution.
@dvarrazzo
dvarrazzo / find-rated-pics
Created May 20, 2015 23:12
Find pictures rated one star or more
#!/usr/bin/env python
"""Find pictures rated one star or more and print their file names.
The output can be used e.g. with rsync --files-from
"""
import os
import sys
from glob import glob
from xml.etree import cElementTree as ET
@dvarrazzo
dvarrazzo / gist:b7c8f050bbd39dd2c104
Last active September 27, 2018 14:43
Accessing EscapeIdentifier from Python
From an email about ukulele:
[...], but I have a trick for you. We always refused to
"bless" it into psycopg because it may break in the future (well, it
will only in psycopg3 which is not really on anybody's roadmap, only
on mine if I manage to clone myself at least 4 times). But...
In [5]: class Identifier(str): pass
In [7]: psycopg2.extensions.register_adapter(Identifier, psycopg2.extensions.AsIs)