Skip to content

Instantly share code, notes, and snippets.

@mschuerig
mschuerig / docker-enter
Last active February 8, 2017 00:50
Enter a running docker container
#! /bin/sh -e
# See
# http://blog.docker.com/2014/06/why-you-dont-need-to-run-sshd-in-docker/
# https://github.com/jpetazzo/nsenter
case "$1" in
-h|--help)
echo "Usage: docker-enter CONTAINER"
exit 0
@mschuerig
mschuerig / yo_completion
Created July 18, 2014 08:14
Yeoman yo bash completion for generators
_yo() {
local cur prev words cword generators
_get_comp_words_by_ref -n : cur prev words cword
generators=$( \
yo --help \
| sed -n '/Please choose a generator below./{:a;n;/-----------------------------------------/b;p;ba}' \
| sed -n '/^ /p' \
)
@mschuerig
mschuerig / exclaim-errors
Created July 18, 2014 14:50
Print errors logged by journald. Regularly call from cron.
#! /bin/sh -e
STATE=/var/local/exclaim-errors.state
now=$( date +'%Y-%m-%d %H:%M:%S' )
since="$(head -n1 $STATE 2>/dev/null || echo 2000-01-01)"
echo "$now" > $STATE
journalctl --priority=err --since="$since" | tail -n+2
@mschuerig
mschuerig / try-to-sleep
Last active August 29, 2015 14:07
Server sleep scripts. Run in the evening as a cron job.
#! /bin/bash
#
# Save as /usr/local/sbin/try-to-sleep
#
# Have cron try it regularly.
# /etc/cron.d/try-to-sleep:
# 12,27,42,57 22-23,0-5 * * * root /usr/local/sbin/try-to-sleep
#
@mschuerig
mschuerig / flactags.rb
Last active August 29, 2015 14:08
List and apply FLAC file tags. For editing music metadata in a text editor.
#! /usr/bin/ruby2.1 -w
require 'digest/md5'
require 'find'
require 'taglib'
def main
case ARGV[0]
when 'list'
ARGV.shift
function reentrant(f, opts) {
opts = $.extend({catchup: false});
var state = {
running: false,
reentry: false
};
var rf = function() {
if (state.running) {
state.reentry = true;
return;
@mschuerig
mschuerig / git-amnesia.rb
Last active January 31, 2022 10:13
What did I do?
#! /usr/bin/ruby -w
require 'date'
require 'find'
# TODO
# - make work with -p option
def main
logopts = "--color=always --since=#{Date.today - 3} #{ARGV.join(' ')}"