Skip to content

Instantly share code, notes, and snippets.

@wisnij
wisnij / printmsg.pl
Created May 10, 2019 18:22
A simple script to make printers display a silly message
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket::INET;
my ($host, $msg) = @ARGV;
$host ||= '...';
$msg ||= 'FEED ME A STRAY CAT';
my $port = 9100;
@wisnij
wisnij / print-tree.pl
Last active December 21, 2018 21:11
Function for printing tree structures as text
=pod
B<print_tree>($I<ROOT>, \&I<PROCESS_NODE>)
Prints a textual representation of a hierarchical tree structure.
I<ROOT> is the top-level node in the tree.
I<PROCESS_NODE> is a subroutine reference which is called for each node in the
tree. It is given one argument, which is the current node; C<$_> is also
@wisnij
wisnij / ps1.sh
Last active January 5, 2024 21:17
Bash $PS1
RED="\[\e[01;31m\]"
GREEN="\[\e[01;32m\]"
BLUE="\[\e[01;34m\]"
NORMAL="\[\e[00m\]"
JOBS='if [[ $(jobs) != "" ]]; then echo "(\j) "; fi'
STATUS="s=\$?; if [ \$s != 0 ]; then echo \"${RED}\$s${NORMAL} \"; fi"
HOST_COLOR="\[\e[1;38;5;$((22 + 10#$(hostname | cksum | cut -d' ' -f1) % 210))m\]"
case $USER in
root)
PROMPT_COLOR=$RED
@wisnij
wisnij / ssc.pl
Last active September 29, 2015 11:57
Persistent screen session wrapper
#!/usr/bin/perl
# adapted from http://stackoverflow.com/questions/1075947/can-i-use-gnu-screen-completely-transparently-automatically
use strict;
use warnings;
use Getopt::Long qw(:config bundling require_order);
my $usage = "Usage: $0 [OPTION...] HOST [SESSION_NAME] [SSH_OPTION...]\n";
my $helpmsg = $usage . <<'EOF;';
Log into a remote machine and start a screen session named SESSION_NAME. If a
@wisnij
wisnij / startxterm.sh
Last active September 27, 2015 20:38
Cygwin startxterm script
#!/bin/sh
#
# Start an xterm (and X if necessary) with a shortcut with this setting:
# C:\cygwin\bin\run.exe /usr/bin/bash.exe -l -c /path/to/startxterm
lockfile='/tmp/.X0-lock'
running=0
if [[ -e $lockfile ]]; then
pid=`cat $lockfile`
if [[ -e /proc/$pid ]]; then