Skip to content

Instantly share code, notes, and snippets.

View tbnorth's full-sized avatar

Terry Brown tbnorth

View GitHub Profile
@tbnorth
tbnorth / bootreveal.sh
Last active August 15, 2019 17:24
Bash script to start a new reveal.js presentation on GitHub pages
GITUSER="$1"
NAME="$2"
if [ -e "$NAME" ]; then
echo "$NAME exists, quitting"
return 10 2> /dev/null || exit 10
fi
git clone --depth 1 https://github.com/hakimel/reveal.js "$NAME"
if ! cd "$NAME"; then
@tbnorth
tbnorth / cpd.py
Created July 14, 2016 20:50
Simple duplicate code finder
"""
cpd.py - copy paste detector
output is stupidly redundant, but works fine to detect duplicate code
Terry Brown, [email protected], Thu Jul 14 14:40:02 2016
"""
import os
from collections import defaultdict
@tbnorth
tbnorth / status_recur.sh
Last active May 10, 2023 13:27
Recursively show detailed status of git repos.
find . \( -name HEAD -o -name .git \) -print -prune \
| xargs -L1 dirname \
| xargs -IF sh -c ' \
echo; echo -n F ""; \
(cd F; git rev-parse --abbrev-ref HEAD); \
echo "$((cd F; git ls-files --others --exclude-standard) | wc -l) untracked"; \
(cd F; git remote -v) | sed "s/(.*)//" | sort -u; \
(cd F; git cherry -v 2>/dev/null); \
[ -d F/.git ] && (cd F; git -c core.fileMode=false status -uno -s) \
' \
@tbnorth
tbnorth / httpcp.py
Last active December 7, 2018 21:07
GET and put (POST) files over HTTP(S)
"""
Quick hack to get read/write access to remote files over port 80 or 443.
WebDAV is probably a better solution, if available.
When it starts, it prints a random key, which must be included in request
headers as X-RandKey. For chrome, you can do this with an extension like
ModHeader. For curl, use
curl -H "X-RandKey: 0.05982546114570.452987805101" ...
@tbnorth
tbnorth / git_repo_diff.sh
Last active May 12, 2016 18:43
Show commits that exist in one git repository but not another
# color version
read -p "Path to other repo.: " OTHER; echo; \
diff --new-line-format "%c'\033'[31m- %L" \
--old-line-format "%c'\033'[32m+ %L" --unchanged-line-format '' \
<(git log --all --format='%H' | sort) \
<(git -C "$OTHER" log --all --format='%H' | sort); echo -e '\033[0m'
# no color version
@tbnorth
tbnorth / read_reveal_md.py
Last active May 11, 2016 18:22
reveal.js HTML slides markdown importer for Leo
# reveal.js markdown uses two blank lines to separate stacked slides
# and three to separate side by side slides. This snippet reads
# such markdown into the appropriate tree layout in the Leo
# editor (http://leoeditor.com/)
lines = p.b.strip().split('\n')
while lines[0][0] == '@':
del lines[0]
nd = p.insertAfter()
@tbnorth
tbnorth / repo_branch.md
Last active April 25, 2018 19:17
Git commands to use branches as independent light-weight repositories within a real repository

Note on git commands to use branches as independent light-weight repositories within a real repository.

Assume the remote repo. already exists, e.g. https://example.com/user/a_repo.git. Create a new empty repository and do things there:

git init subrepo
cd subrepo
date >README.md
git add README.md

git commit -am'one file'

@tbnorth
tbnorth / kml_multigeom_points.py
Last active June 23, 2017 16:17
Convert KML MultiGeometries containing points to their first Point, for GPSBabel input.
"""
kml_multigeom_points.py - Convert KML MultiGeometries
containing points to their first Point, for GPSBabel input.
Also deletes descriptions which can crash GPSBabel.
Usage:
python kml_multigeom_points.py < orig.kml > new.kml
Terry Brown, [email protected], Mon Nov 23 09:51:01 2015
@tbnorth
tbnorth / arcmap2ckan.md
Last active February 18, 2016 18:33
Make ArcMap HTML metadata suitable for general use, e.g. with CKAN

Make ArcMap HTML metadata suitable for general use, e.g. with CKAN

When you view the Description of something in ArcMap or ArcCatalog, that's an HTML page you're looking at. You can right-click -> Properties to see where it's saved, something like file:///C:/Users/tbrown/AppData/Local/Temp/arc5E14/tmpDE3C.tmp.htm, and copy it for use elsewhere. It's in UTF-16 (two bytes per character) encoding, and the link to the thumbnail will probably break - this simple program below fixes both those issues. Example usage:

python arcmap2ckan.py tmpBC5A.tmp.htm GLStress5971.metadata.html GLStress5971.view.jpg
@tbnorth
tbnorth / showsel.sh
Created July 7, 2015 18:13
show selection / clipboard content
while true; do
echo
for thing in primary secondary clip-board; do
echo $thing
text=$(xclip -out -selection $thing 2>/dev/null || echo N/A)
echo " " ${text:0:40}
done
sleep 1
done