Skip to content

Instantly share code, notes, and snippets.

@mmitch
mmitch / s9y-regexp.php
Last active April 7, 2020 18:00
serendipity_uploadSecure() regexp golf #s9y
<?php
function shorten($input) {
// (1) original regexp:
// if the path has an extension, the directory separator will be captured as part of the extension
// "path.foo/somefile" will become "path.foo/s"
// this fails here -----------.
// v
// return preg_replace('@(\.[^.]{0,5}+)[^./\\\]*[^/\\\]{1,1}?$@', '$1', $input);
// (2) don't match path extensions
@mmitch
mmitch / emacs-stdin-stdout.el
Created February 29, 2020 19:07
emacs batch: read from stdin, write to stdout
;;; emacs-stdin-stdout.el -- duplicate every line from stdin to stdout
;;; Commentary:
;; run this script with:
;; `emacs -batch -l emacs-stdin-stdout.el -f start`
;;
;; see https://joelmccracken.github.io/entries/reading-writing-data-in-emacs-batch-via-stdin-stdout/
;;; Code:
@mmitch
mmitch / buildall.sh
Created April 2, 2017 06:48
jdupes: try to build all configuration combinations
#!/bin/bash
set -e
COUNT=0
SECONDS=0
for MFLAG1 in '' 'OMIT_GET_LONGOPT=1'; do
for MFLAG2 in '' 'ENABLE_BTRFS=1'; do
for MFLAG3 in '' 'LOW_MEMORY=1'; do
@mmitch
mmitch / log10-test.sh
Created December 3, 2016 20:26
demonstration for RRDtool patch "negative logarithms"
#!/bin/bash
# see https://github.com/oetiker/rrdtool-1.x/pull/757
FILE=log10.rrd
IMAGE=log10.png
TIME=1480787200
COUNT=15
./rrdtool create $FILE \
--start $TIME --step 1 \
@mmitch
mmitch / get_wow_lore.sh
Created November 7, 2015 17:25
download public World of Warcraft lore (short stories) from Blizzard website
#!/bin/sh
BASEURL=http://us.battle.net/wow/en/game/lore/
TEMPFILE=$(mktemp)
# download public World of Warcraft lore (short stories) from Blizzard website
#
# needs standard shell utils plus Perl LWP (or rewrite to use wget/curl/whatever instead of GET)
GET $BASEURL \
| grep -A2 lore-info \
@mmitch
mmitch / get_starcraft_lore.sh
Created November 7, 2015 17:22
download public Starcraft lore (short stories) from Blizzard website
#!/bin/sh
# download public Starcraft lore (short stories) from Blizzard website
#
# needs standard shell utils plus Perl LWP (or rewrite to use wget/curl/whatever instead of GET)
BASEURL=http://us.battle.net/sc2/en/game/lore/
TEMPFILE=$(mktemp)
GET $BASEURL \
@mmitch
mmitch / check_child_test.pl
Created May 4, 2014 11:41
check for child PIDs via perl
#!/usr/bin/perl -w
use strict;
use POSIX ":sys_wait_h";
# check for Process::Table on startup
our $have_process_table;
BEGIN {
eval { require Proc::ProcessTable; };
$have_process_table = not $@;
}