Skip to content

Instantly share code, notes, and snippets.

View jbarrett's full-sized avatar
🤘
Be excellent to each other

John Barrett jbarrett

🤘
Be excellent to each other
View GitHub Profile
@jbarrett
jbarrett / wavsplitter.pl
Last active April 26, 2024 09:28
Sox-based multichannel wav splitter
#!/usr/bin/env perl
# usage:
# ./wavsplitter.pl [--channels=number of channels in output] [--sox=path to sox] file-list
#
# Back up your files before use, provided as-is, no warranty etc.
use strict;
use warnings;
use experimental qw/ signatures /;
@jbarrett
jbarrett / Multimethod.pm
Last active November 11, 2023 11:38
Multimethod hack - example of pluggable keyword
die "This code should not be used, ever!" unless $ENV{MULTIMETHOD_DEATHWISH};
package Multimethod;
use v5.38;
use experimental qw/ try /;
use List::Util qw/ uniq /;
use List::MoreUtils qw/ each_array /;
use Scalar::Util qw/ blessed /;
use Keyword::Declare;
use Object::Pad::MOP::Class qw/ :experimental(mop) /;
@jbarrett
jbarrett / chmayor.pl
Created March 18, 2013 20:38
First pass at a script to change the mayor and organisation name in SimCity 2000 for DOS
#!/usr/bin/env perl
# Change the mayor's name in SimCity 2000
#
# You should probably stick with plain ASCII if you use it.
use strict;
use warnings;
use bytes;
@jbarrett
jbarrett / callback.pl
Created February 8, 2023 16:19
Exploring async event loop integration with RtMidi
#!/usr/bin/env perl
use strict;
use warnings;
use v5.32; # Perl on Windows is still hard...
use experimental 'signatures';
use IO::Async::Timer::Periodic;
use IO::Async::Routine;
use IO::Async::Channel;
@jbarrett
jbarrett / power_switcher.pl
Last active September 20, 2022 17:29
Quick and dirty power profile switching script - detects fullscreen state or process name from a list
#!perl.exe
# Attempt to set power profile based on whether fullscreen app (game) running OR process name
# No guarantees if you have more than one monitor :)
# Edit these
# > powercfg /list
my $LOW = 'a1841308-3541-4fab-bc81-f71556f20b4a';
my $BALANCED = '381b4222-f694-41f0-9685-ff5bb260df2e';
@jbarrett
jbarrett / mozart.pl
Last active September 6, 2021 00:06
Mozart's dice
#!/usr/bin/env perl
use strict;
use warnings;
use v5.32;
use experimental qw/ signatures /;
use MIDI;
use Path::This '$THISDIR';
@jbarrett
jbarrett / munge_bib.pl
Created August 8, 2021 18:42
Fix URLs in Mendeley's BibTeX export
#!/usr/bin/env perl
use IO::All -utf8;
my $in = 'library.bib';
my $out = 'library-munged.bib';
my @lines = io($in)->slurp;
for my $url ( grep { /^url/ } @lines ) {
@jbarrett
jbarrett / perl_weekly_challenge_1.md
Last active March 30, 2019 21:39
Perl weekly challenge 1

As published on https://perlweeklychallenge.org/blog/a-new-week-a-new-challenge/
Submissions demonstrated here using Reply.

Write a script to replace the character ‘e’ with ‘E’ in the string ‘Perl Weekly Challenge’. Also print the number of times the character ‘e’ is found in the string.

I didn't write a script so I fail this challenge already.

0> my $foo = 'Perl Weekly Challenge'
$res[0] = "Perl Weekly Challenge"
@jbarrett
jbarrett / git-cpr
Created February 22, 2019 11:43
Git command : checkout PR
#!/usr/bin/env bash
[ -z "$1" ] && echo PR number required. && exit 1
BRANCHNAME=pr$1
[ ! -z "$2" ] && BRANCHNAME=$2
git fetch origin pull/$1/head:$BRANCHNAME
git checkout $BRANCHNAME
@jbarrett
jbarrett / ntfs_safe.pl
Created December 18, 2018 11:00
Very quick and dirty NTFS file renamer since ntfs-3g will happily write "invalid" filenames.
#!/usr/bin/env perl
use strict;
use warnings;
use File::Copy qw/ mv /;
use File::Find ();
my $dir = $ARGV[0] || '.';
use vars qw/*name *dir *prune/;