Skip to content

Instantly share code, notes, and snippets.

View somian's full-sized avatar

Sören Andersen somian

  • toolsmith, independent contractor: python, perl, unix shell; systems admin
  • A city near the eastern Great Lakes, USA
View GitHub Profile
@somian
somian / LilMonstaNumber12
Last active August 29, 2015 14:06
LilMonstaNumber12 for GNU/Linux X11 uses X clpbd to find URLs of CPAN pkgdists and saves them in a hierarchical fs loc (creating dirs where needed).
#!/bin/dash
#--+++-- cpan-grabdist.sh
# NODBG=ON # comment out after debugging
#--+++--
export HO_ME=$(echo ~)
TO_SUDO_OR_NOT=""
BEST=$(echo ~Public/Downloads)
TARGET=${BEST:+"$BEST/CPAN-SRC"}
@somian
somian / gist:6c17da88c76ff4e180c2
Created August 9, 2014 00:58
NMC - Google-Chrome Debian .deb inst file snippet causing BIG trouble
#
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# sources.list setting for google-chrome updates.
REPOCONFIG="deb http://dl.google.com/linux/chrome/deb/ stable main"
@somian
somian / std-lib-foo Makefile
Last active August 29, 2015 14:04
A Makefile that compensates for a difficult pkg-config case v2.91
# GNU Makefile
## GMakefile-std-lib-foo
THIS_MAKEFILE := $(firstword $(MAKEFILE_LIST))
PROGRAM = testargv
CODE := $(CURDIR)/code/
PROGRAM_FILES = testinput.cc
_CODEF := $(wildcard $(CODE)*.cc)
_CODEF ||= None
LIB_Called_WHAT =
@somian
somian / PySlode
Last active January 2, 2016 17:19
A simple but usable skeleton example of a (conservative, error-checking) "local python module code file loader" in Vim Script (vimL)
"^-^" vim: set filetype=vim et sw=4
" This file contains free software: you can redistribute it and/or modify
" it under the terms of the GNU General Public License as published by
" the Free Software Foundation, either version 3 of the License, or
" (at your option) any later version.
"
" The code herein is published informally in the hope that it will be useful,
" but WITHOUT ANY WARRANTY; without even the implied warranty of
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
" GNU General Public License for more details.
@somian
somian / krumblies
Last active December 27, 2015 20:49
#!/bin/bash
declare -x TOPDIR_STORAGE=${HOME:-"/home/retread"}/.config/virt/virtualdisks
declare CLOO=$1 # e.g. "SANDISK"
declare -a DISK_GRP=(\
$(awk --sandbox -F : '/disk/{print $1,$3}' /etc/group)\
)
declare DISK_GID=${DISK_GRP[1]}
@somian
somian / gist:6790687
Created October 2, 2013 08:31
Karl Runge's rx11vnc script
#!/bin/sh
#
# usage: rx11vnc [-s] <host>:<xdisplay>
# rx11vnc [-s] <host> (assumes xdisplay is 0)
#
# -s means use ssh instead of rsh.
# -S tries to tunnel the vnc traffic thru ssh. (experimental...)
#
#set -xv
@somian
somian / mkblklabel
Created September 2, 2013 11:26
A slightly more useful stab at the previous gist.
blkid -s TYPE|egrep vfat | cut -d \: -f 1| xargs /sbin/blkid -c value|
xargs perl -MCarp -MFile::Util="" -e '$it=File::Util->new();' \
-e 'my($lab)= grep{$_} map{/LABEL=([^=]+)(?=[[:space:]][[:upper:]]+[=])*/;' \
-e '($1 ? do{($_=$it->escape_filename($1))=~s{[[:space:]]}{_}g and qq[/media/byLABELISH/$_]}' \
-e ': q[])} grep {LABEL} @ARGV; print qq[We shall try to make $lab if it does not exist.\n];' \
-e 'unless (-d $it){$it->make_dir($lab) || croak qq[Well, that failed somehow.\n]}'
@somian
somian / blklabel
Last active December 22, 2015 03:39
shell pipeline to get a suffiently safe filename from a disk volume LABEL as a mount point (directory name) to mount a hotplugged device.
blkid -s TYPE|egrep vfat |
cut -d \: -f 1|
xargs /sbin/blkid -c value|
xargs perl -MFile::Util="" \
-e '$it=File::Util->new();' \
-e 'print for map{/LABEL=([^=]+)(?=[[:space:]][[:upper:]]+[=])*/;' \
-e '($1 ? do{($_=$it->escape_filename($1))=~s{[[:space:]]}{_}g and qq[/media/byLABELISH/$_\n]}' \
-e ' : q[])} grep {LABEL} @ARGV'
# get some metadata about present disk devices.
function disklookup
{
if [[ x"$1 " != x"" ]]
then
PATT="$1"
for LOL in `blkid -o device -t TYPE=ext4`
do blkid -o full -s 'UUID' -s 'LABEL' $LOL
done |
sed -n "/$PATT/{p}"
@somian
somian / Bash GNU-Linux DiskMountReporter
Last active December 20, 2015 08:19
Bash user function (typically executed from an interactive shell while doing system work or just stuff) on GNU-Linux. Point is see mounted disk devices neatly printed.
## earlier version was fubar
function diskmounts {
cat /proc/mounts | perl -nawl \
-e 'if ($F[0]=~ m{/dev/(loop[[:digit:]]+ | sd[a-z][[:digit:]]? | sr[[:digit:]]+) | UUID= | LABEL=}x) {' \
-e ' push @dp=>[@F[0,1]]' \
-e '} END {print for map { $_->[1] } sort {$a->[0] cmp $b->[0]} map { [$_->[0], join (qq[\t\t],@$_)] }@dp}'
}