Skip to content

Instantly share code, notes, and snippets.

View unhammer's full-sized avatar
kevin :: Coffee → Code

Kevin Brubeck Unhammer unhammer

kevin :: Coffee → Code
View GitHub Profile
@unhammer
unhammer / speakersPerLanguage.sparql
Last active April 1, 2025 11:50
Number of speakers per language in the world based on Wikidata (including dupes due to measuring speakers at different times / from different sources). Note that 6915 languages have iso 639-3 codes in wikidata, but only 1614 languages have data for number of speakers (presumably the languages with no data are at the lower end of the list)
SELECT DISTINCT ?item ?numberOfSpeakers ?speakersTime ?iso639_1 ?iso639_3 ?itemLabel ?itemLabel_en
WHERE {
?item wdt:P31 wd:Q1288568; # Any instance of a modern (current use) language
wdt:P220 ?iso639_3; # that has an ISO 639-3 code
# Require number of speakers, but as a statement so we can get the "timestamp" of the property:
?item p:P1098 ?numberOfSpeakersStatement .
?numberOfSpeakersStatement ps:P1098 ?numberOfSpeakers.
optional {
?numberOfSpeakersStatement pq:P585 ?speakersTime.
@unhammer
unhammer / cg2dot.awk
Last active September 11, 2024 12:05
awk -f cg2dot.awk < cg-output.txt > tree.dot && dot -Tpng tree.dot -o tree.png
#!/usr/bin/awk -f
BEGIN {
FS="^\"<|>\""
print "digraph ParseTree {"
print "\tnode [shape=plaintext];"
print "\tedge [fontname=Helvetica, fontsize=10];"
print ""
}
@unhammer
unhammer / similar_images.sh
Last active June 10, 2024 06:57
Find similar images to this one using findimagedupes, open in image viewer
#!/bin/bash
### Prerequisites: findimagedupes, zenity, gthumb (or feh+thunar)
### First run will take some time. By default scans ~/Pictures and
### ~/Desktop for possible matches, customise the "folders" variable
### below to change this.
### Run like: ./similar_images image.jpg
### but it's meant to be run from a file manager like Thunar, so uses
@unhammer
unhammer / ediff-regions-samebuffer.el
Created June 4, 2024 13:37
Hit C-x =, mark a region, C-M-c to confirm, mark a second region, C-M-c to confirm and you have an ediff of regions of the same buffer
(defun ediff--regions-samebuffer (ediff-regions &optional startup-hooks)
(let ((cloned-buffer (clone-indirect-buffer-other-window nil t)))
(unwind-protect
(funcall ediff-regions (current-buffer) cloned-buffer startup-hooks)
(kill-buffer cloned-buffer))))
(defun ediff-regions-samebuffer (&optional wordwise startup-hooks)
"Ediff two regions of the same buffer, automating the clone-and-narrow dance.
Optional interactive argument WORDWISE to do a word-diff instead of line-by-line."
(interactive "P")
(defvar-keymap embark-org-column-map
:doc "Keymap for Embark org-column actions."
:parent embark-org-table-map
"M-r" #'my-cua-enable-and-replace-in-rectangle-embark)
(defun my-embark-org-column-at-point ()
"Target the org-column at point."
(when-let ((org-column
(and (org-at-table-p)
(not (looking-at-p "|")) ; since then we don't know which column you mean
@unhammer
unhammer / progress.sh
Last active April 13, 2023 14:41
Show progress of some command you forgot to pipe through pv
#!/bin/bash
### Save as "/usr/local/bin/progress" and chmod +x, then:
#
# $ progress ~/huge-file.tar.bz2
# $ progress -p $(pidof bzcat)
# $ progress # progress of all open files, shows e.g. how far mpd is through your song :P
#
# source: http://stackoverflow.com/a/238140/69663
@unhammer
unhammer / merlin-init.sh
Last active February 12, 2023 05:40
Create .merlin file for a project with all your ocamlfind packages and .opam sources in there
#!/bin/sh
if test -f .merlin; then
echo ".merlin already exists, bailing out ..." >&2
exit 1
else
# You could add your default EXT's and such to this list:
@unhammer
unhammer / html-parse-print.py
Created April 29, 2014 14:22
parse html, print it out as-is (python3 boilerplate for html template like stuff)
#!/usr/bin/python3
from html.parser import HTMLParser
from sys import stdin
def p(*value):
print(*value, end='')
class MyHTMLParser(HTMLParser):
def handle_startendtag(self, tag, attrs):
@unhammer
unhammer / mwdump-to-pandoc
Last active December 25, 2022 18:34
Turn wikipedia dumps into plaintext using pandoc
#!/bin/bash
declare OUTFORMAT=plain
set -e -u
run () {
local text=false
local -i i=0
local out
@unhammer
unhammer / .mbsyncrc
Last active December 4, 2022 06:41
isync + dovecot + gnus with Fastmail
IMAPAccount fastmail
Host imaps:mail.messagingengine.com
User me@fastmail.com
# you may have to tweak the awk here + filename to your netrc/authinfo:
PassCmd "gpg2 -q --for-your-eyes-only --no-tty -d $HOME/.netrc.gpg | awk '$2==\"mail.messagingengine.com\" && $4==\"me@fastmail.com\" {print $6;exit(0)}'"
Port 992
# Port 992 has a "flat" hierarchy; use with
# mail_location = maildir:~/.Maildir/:LAYOUT=fs:INBOX=~/.Maildir/INBOX
# in dovecot (see also MaildirStore.Inbox below)