Skip to content

Instantly share code, notes, and snippets.

View dspinellis's full-sized avatar

Diomidis Spinellis dspinellis

View GitHub Profile
@dspinellis
dspinellis / gist:7716549
Created November 30, 2013 08:03
Rename one or more AWS EC2 snapshots
ec2-describe-snapshots --filter tag:Name=OLDNAME |
awk '$1 == "SNAPSHOT" {print $2}' |
while read id ; do
ec2-create-tags $id --tag Name=NEWNAME
done
@dspinellis
dspinellis / frequent-one-line-changes.sh
Created April 2, 2016 11:29
Most frequent one-line changes in a Git repository
#!/bin/sh
git log --pretty='SHA %H' --numstat |
awk '/^SHA/ {sha = $2} NF == 3 && $1 == 1 && $2 == 1 {print "git show --oneline --unified=0", sha, "--", $3}'|
sh |
sed -n '/^- /{;s/^-[ \t]*//;h;};/^+ /{s/^+[ \t]*//;H;g;s/\n/$/;p;}' |
sort |
uniq -c |
sort -rn |
head
@dspinellis
dspinellis / md5decompress.sh
Last active February 16, 2020 12:58
Decompress an MD5 checksum into the file it represents :-)
#!/bin/bash
#
# "Decompress" an MD5 sum into the file it represents.
# This was created following a tongue-in-cheek challenge by Tom Limoncelli.
# https://twitter.com/yesthattom/status/716670884698828800
#
# Try md5decompress.sh c1a5298f939e87e8f962a5edfc206918
#
if [ "x$1" = x ] ; then
@dspinellis
dspinellis / decimal.sed
Last active May 16, 2021 20:23
Filter to add decimal separators to long numbers
#!/bin/sed -Ef
#
# Add a LaTeX thin space (\,) decimal separator to long digit sequences
#
# Diomidis Spinellis, October 2018
#
# Save this as a file and add it to your path, or run at as a one-liner:
# sed -E ':a;s/([0-9])([0-9]{3})([^0-9]|$)/\1\\,\2\3/g;ta'
#
@dspinellis
dspinellis / pandoc.css
Last active October 27, 2018 15:13 — forked from killercup/pandoc.css
Add this to your Pandoc HTML documents using `--css pandoc.css` to make them look more awesome. (Tested with Markdown and LaTeX.)
/*
* I add this to html files generated with pandoc.
*/
html {
font-size: 100%;
overflow-y: scroll;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
@dspinellis
dspinellis / lockf.py
Last active January 22, 2019 17:11
Lock a file using lockf(3)
#!/usr/bin/env python
#
# Lock through a file using fcntl(2), i.e. lockf(3), rather than flock(2)
# as used in flock(1)
#
# Example: lockf /var/lib/dpkg/lock apt-get update
#
# Copyright 2018 Diomidis Spinellis
#
# Licensed under the Apache License, Version 2.0 (the "License");
@dspinellis
dspinellis / reachable.gvpr
Last active August 26, 2019 13:30
Given a directed graph and two specified nodes a, b succeed if node a is reachable from node b.
#!/usr/bin/env gvpr -f
#
# Given a directed graph and two specified nodes a, b succeed if
# node a is reachable from node b.
# The program exits with success (0) if a path is found and failure (1)
# if a path isn't found.
#
# Example invocation:
# gvpr -f reachable.gvpr -a sourcename -a targetname file.dot && echo yes
#
@dspinellis
dspinellis / sapi-speech-to-text.cpp
Created October 8, 2019 10:30
Command-line tool to convert speech in a WAV audio file into text using Windows SAPI
/*
* Convert the specified speech WAV file into text output
* on the program's standard output.
*
* Diomidis Spinellis, October 2019
* Based on https://stackoverflow.com/a/40002268/20520
*/
#include <iostream>
#include <sapi.h>
@dspinellis
dspinellis / third-person.sed
Last active June 11, 2020 12:43
Convert code review text to third person singular
#!/bin/sed -Ef
#
# Convert code review text to third person singular
# Author: Diomidis Spinellis, June 2020
# Released to the public domain
#
# you write -> the code contains
s/\<you write/the code contains/g
@dspinellis
dspinellis / anagrams.sh
Created April 24, 2021 15:25
Find all anagrams in the system's dictionary
#!/bin/sh
#
# Find all anagrams in the system's dictionary by mapping the words
# into a product of prime numbers associated with each letter
#
# Process plain ASCII characters
export LC_ALL=C
# Create commands for the calculator bc