Skip to content

Instantly share code, notes, and snippets.

View JohnMertz's full-sized avatar

John Mertz JohnMertz

View GitHub Profile
@JohnMertz
JohnMertz / multiscan.pl
Created January 20, 2021 18:24
Scan and automatically crop many images with SANE and ImageMagick
#!/usr/bin/perl
use strict;
use warnings;
use POSIX ":sys_wait_h";
STDOUT->flush();
use File::Which qw( which );
foreach ( qw| convert scanimage | ) {
@JohnMertz
JohnMertz / stream_podcasts.pl
Created November 24, 2020 09:37
Daily podcast player
#!/usr/bin/perl
use strict;
use warnings;
# Dependencies
use LWP::UserAgent; # Usually pre-installed, available on CPAN
use XML::Hash::XS; # CPAN or libxml-hash-xs-perl on Debian
# Feeds that should be used if no arguments are provided
@JohnMertz
JohnMertz / sway_displays.pl
Last active August 27, 2020 17:01
Automatically configure display layout and waybar for Sway
#!/usr/bin/perl
########################################################################
# Dependencies
########################################################################
#
# Depends on JSON::XS and Proc::ProcessTable
#
# Debian:
# apt install libjson-xs-perl libproc-processtable-perl
@JohnMertz
JohnMertz / update_minecraft.pl
Created August 16, 2020 04:36
Minecraft Server Backup and Upgrade Script
#!/usr/bin/perl
# Accompanying SystemD Unit file compatible with these locations/user: https://gist.github.com/JohnMertz/c6bb4a9298dd3dc53b8030ff50466226
#
# Expects the following minecraft directories:
# ./ The PWD is taken dynamically. In the SystemD unit, it is /var/lib/minecraft
# current The latest version. This will be the executable directory.
# 1.16.2 Directories will be created for every old version
# update_minecraft.pl This script
#
@JohnMertz
JohnMertz / minecraft.service
Last active August 17, 2020 02:45
Minecraft SystemD Unit File
[Unit]
Description=Minecraft
After=network.target
[Service]
Type=simple
User=minecraft
Group=minecraft
WorkingDirectory=/var/lib/minecraft/current
ExecStart=java -jar -Xmx2G -Xms1G server.jar --nogui
@JohnMertz
JohnMertz / amihome.pl
Created May 28, 2020 19:19
Is a device currently up on LAN (determine if my phone is at home).
#!/usr/bin/perl
use strict;
use warnings;
use Net::Ping;
my $file = "/tmp/amihome";
my $host = "192.168.2.127";
@JohnMertz
JohnMertz / dialpad.pl
Created April 10, 2020 11:53
Translate letters to dialpad numbers and numbers to possible words
#!/usr/bin/perl
# TODO: at the moment, words are only broken up by 0 and 1. Should search for smaller sequential words. For example:
# 6908378 finds: mytest
# but 1698378 does not
use strict;
use warnings;
# Default Debian ispell dictionary
@JohnMertz
JohnMertz / traffic.pl
Created April 10, 2020 11:44
Ottawa traffic news and alerts
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dump qw | dump |;
use LWP::UserAgent;
use JSON::XS;
my $ua = LWP::UserAgent->new();
@JohnMertz
JohnMertz / battery.pl
Created April 10, 2020 11:38
Battery status script
#!/usr/bin/perl
# Not proud of this one. It had multi-battery supported shunted on when I got a new laptop and Waybay output taped on too. Could use to be cleanud up a lot, but it does the job.
my $output;
my $bar = 0;
if ($ARGV[0] eq '-h' || $ARGV[0] eq '--help') {
print'
pow.pl - Power Status Script
@JohnMertz
JohnMertz / net.pl
Created April 10, 2020 11:30
Script to get network interfaces as nested hashes
#!/usr/bin/perl
use strict;
use warnings;
my $addr = `ip addr`;
my %links;
my $current;
foreach (split '\n', $addr) {