Skip to content

Instantly share code, notes, and snippets.

View tbnorth's full-sized avatar

Terry Brown tbnorth

View GitHub Profile
@tbnorth
tbnorth / .screenrc
Last active December 3, 2019 15:31
Launch multiple named screen sessions, offset date display, etc.
backtick 1 60 60 date -d-1hour +%H:%M
caption always
caption string "%{gk}%-w%{= ky}%45>*%t%{-}%+w%<"
# leave the above in so install_env doesn't re-add it
caption string "%{gk}%1` %-w%{= ky}%45>%t%{-}%+w%<"
# screen bash
shell "/usr/bin/bash"
# bind ^a^c screen bash
@tbnorth
tbnorth / uniqify.sql.sh
Created August 22, 2019 18:06
Script that generates SQL to remove duplicate records from a table
# change these bits then run the script to generate the SQL, e.g.
# <edit file>
# <save file>
# bash uniqify.sql.sh >fix_mytable.sql
# then execute the SQL line by line checking the results, preferably in
# a transaction you can roll back or a copy of the DB
# START OF THINGS TO CHANGE
# the table containing duplicates
"""
docstrings.py - show docstrings for .py files
Terry N. Brown [email protected] Tue Aug 20 16:25:39 EDT 2019
"""
import argparse
import ast
import os
from functools import reduce
@tbnorth
tbnorth / conflict_notes.md
Last active August 14, 2019 14:13
Notes on conflicts

First thing you usually see is a message like this when you try and push:

TBrown02@LZ2626XTBROWN02 MINGW64 /r/conflictdemo2 (master)
$ git push
To https://github.com/tbnorth/conflictdemo.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/tbnorth/conflictdemo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
@tbnorth
tbnorth / to_subdirs.py
Last active August 19, 2019 15:43
Move files to subdirs, similar to git object paths
"""
to_subdirs.py - move directory content to subdirs based on common prefix
Terry N. Brown [email protected] Mon Jun 24 16:11:59 EDT 2019
"""
import os
import re
import sys
from collections import namedtuple, defaultdict
@tbnorth
tbnorth / test.py
Created August 1, 2019 14:21
Test SQLite handling simultaneous connections
# A simple test of SQLite's ability to handle simultaneous connections.
# Result: no problem, DB content at end of test is correct.
# Note: by default, SQLite seems to sync. the disk on .commit(), so the
# test below will grind a physical disk for a long time. The DB path
# used below is a RAM disk, execution is acceptably fast on that.
import multiprocessing
import sqlite3
DB = "/home/tbrown/r/test.db"
@tbnorth
tbnorth / send_large_data.md
Last active October 17, 2018 18:42
Notes for sending a large amount of data

Say you have a large amount of data you want to send in a folder, say /path/to/large/data. Make a new folder, somewhere it can be accessed by your recipient, by FTP / scp / ssh / HTTP, whatever. E.g. /other/path/to/parts. Then do:

SOURCE="/path/to/large/data"
DEST="/other/path/to/parts"
tar cf - "$SOURCE" | gzip | split -da6 -b10M - "$DEST"/part.
sha1sum "$DEST"/part.* >"$DEST"/checksums.txt

Be careful to omit trailing slashes, as in the first two lines above.

@tbnorth
tbnorth / notes.md
Last active October 1, 2018 18:48
notes on printing notes from GitHub markdown to pdf

One time,

echo -e '\usepackage{extsizes}\n\usepackage[margin=0.25in]{geometry}' >extsizes.inc

because -V geometry:margin=0.25in is ignored for some reason.

Then

pandoc https://raw.githubusercontent.com/tbnorth/deltest/554550cf/toolsdemo.md \
 --include-in-header extsizes.inc -V documentclass=extarticle \
@tbnorth
tbnorth / guacdock.md
Last active February 20, 2021 19:44
Set up Apache Guacamole using Docker

Apache Guacamole using Docker to put your personal desktop on the web

  • This guide doesn't cover security issues at all.
  • This guide is intended to just get your personal desktop onto the web so you can use it remotely, it doesn't cover serious multi-user Guacamole deployment.
  • At the end of this file there are some notes on installing docker, running a VNC server, and setting up a web proxy, but this guide really isn't meant to cover those topics.
  • This guide is based on [Installing Guacamole with Docker
@tbnorth
tbnorth / sedcol.md
Last active November 16, 2020 01:49
sed select column

A sed solution that selects a column by number:

echo 0 1 2 3 iv 5 6 | sed -E 's/^(\S+\s+){4}(\S+).*/\2/'

or

echo 0 1 2 3 iv 5 6 | sed 's/^\(\S\+\s\+\)\{4\}\(\S\+\).*/\2/'