Skip to content

Instantly share code, notes, and snippets.

@datagrok
datagrok / tw5-server.py
Created Feb 8, 2021
A local server for TiddlyWiki5 that allows saving wiki.
View tw5-server.py
#!/bin/python3
"""
Just barely enough DAV protocol to enable Tiddlywiki 5 to persist its data to the filesystem.
Based on https://tiddlywiki.com/#Saving%20via%20a%20Minimal%20Ruby%20Server
Don't run this in production or expose it to the public internet.
"""
from http import HTTPStatus
@datagrok
datagrok / README.md
Created Jun 14, 2019
Elixir's Stream.transform doesn't emit its accumulator at the end of the input. What to do?
View README.md

I want to lazily process an input file, which contains tokens separated by whitespace.

The naive way is to let Elixir hand me lines, then split the lines:

def tokenize_lines(enum)
  enum
  |> Stream.flat_map(&String.split/1)
end
@datagrok
datagrok / randr.py
Created Nov 17, 2018
set randr settings by monitor EDID
View randr.py
#!/bin/python3
"""
The xrandr names (DP-1, DP-2) for my monitors tends to flip around depending on
which one happens to become active first. This script figures out which is which
by the EDID, and runs xrandr to apply the layout correctly.
"""
import re
import subprocess
@datagrok
datagrok / multi_iec16022.py
Created Aug 8, 2018
A script to create paper-printable backups of binary data.
View multi_iec16022.py
#!/usr/bin/python3
'''
Break input data into chunks and use 'dmtxwrite' to create a DataMatrix 2D
barcode for each chunk. Dump all these into an HTML page for easy printing.
The size of the chunk depends on the target size of the barcodes; see
https://www.idautomation.com/barcode-faq/2d/data-matrix/#DataMatrix_Formats
Intended for making hard (paper) copies of small but highly important data,
like GPG keys, that can be retrieved faster and more reliably (one hopes) than
@datagrok
datagrok / README.md
Last active May 30, 2020
Various code snippets
View README.md

This is an unmodified selection of code I wrote for and under contract to AT&T, so AT&T holds all copyright.

AT&T released it to the public under the terms of the Apache 2.0 License (as described in license headers in the source code) as part of a larger body of work.

I retrieved these copies from their public repositories on 1/9/2018 after I was no longer under contract to them. I am hosting it here in compliance with the terms of their license. The links below point to AT&T's public repositories.

  • rgwa_client.py, a simplistic Requests-based wrapper for the Ceph RADOS Object Gateway Admin Operations API.
  • in_temp_dir.py, a little context manager to make it easy to perform some function within a temporary director
@datagrok
datagrok / README.md
Last active Mar 12, 2019
What's the best way to write function pipelines in Python?
View README.md

I agree with Guido, in that I think

[ x * 2 for x in some_list if x < 12 ]

is much easier to read than the equivalent

map(lambda x:x * 2, filter(lambda x:x<12, some_list))
@datagrok
datagrok / django-storages-config.md
Last active Apr 28, 2017
a list of configuration options for django-storages' boto backends
View django-storages-config.md

Configuration options used by S3BotoStorage and S3Boto3Storage

This is a list of common and divergent configuration options for django-storages' boto backends:

  • storages.backends.s3boto.S3BotoStorage
  • storages.backends.s3boto3.S3Boto3Storage and

Created to cope with the documentation which reads:

"Available are numerous settings. It should be especially noted the following:"

View keybase.md

Keybase proof

I hereby claim:

  • I am datagrok on github.
  • I am datagrok (https://keybase.io/datagrok) on keybase.
  • I have a public key ASCrSLf3jYbRq3V0I7pJgP1UEqtjxqqP5iTBLfN5VXNq-Qo

To claim this, I am signing this object:

@datagrok
datagrok / README.md
Last active Jan 8, 2018
Home video and photo management system
View README.md

A home photo and video management system

I want some tools to help me manage my photos and videos, conforming to some of my particular requirements.

I've already begun tinkering on some of my own, but with every line of code I think, "surely, someone must have done this already." Have you?

Components

  • Backup. I have a local fileserver, but I want offsite backup too. Backblaze B2 looks cheapest but I also already have a DreamObjects account.
  • A thing to make it effortless to get photos off devices and into long-term storage.
@datagrok
datagrok / README.md
Last active Dec 4, 2016
How to refactor code that is too reliant on **kwargs
View README.md

Refactoring from an overuse of **kwargs

Compare:

def a(**kwargs):
  if 'A' not in kwargs:
    kwargs['A'] = 1
  if 'B' not in kwargs:
    kwargs['B'] = 2
  success, result = b(**kwargs)