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 / 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 / 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/;
@jbarrett
jbarrett / reclaimWindows10.ps1
Created August 30, 2017 13:03 — forked from alirobe/reclaimWindows10.ps1
This Windows 10 Setup Script turns off a bunch of unnecessary Windows 10 telemetery, removes bloatware, and privacy invasions. Not guaranteed to catch everything. Review and tweak before running. Reboot after running. Scripts for reversing are included and commented. Fork of https://github.com/Disassembler0/Win10-Initial-Setup-Script (different …
##########
# Tweaked Win10 Initial Setup Script
# Primary Author: Disassembler <disassembler@dasm.cz>
# Modified by: alirobe <alirobe@alirobe.com> based on my personal preferences.
# Version: 2.6.1, 2017-08-02
# Primary Author Source: https://github.com/Disassembler0/Win10-Initial-Setup-Script
# Tweaked Source: https://gist.github.com/alirobe/7f3b34ad89a159e6daa1/
# Tweak difference:
#
# @alirobe's version is a subset focused on safely disabling telemetry, 'smart' features, and 3rd party bloat ...
@jbarrett
jbarrett / adflabel.pl
Last active August 31, 2016 19:09
Dump Amiga Disk Format (ADF) disk label (-ish, sometimes).
#!/usr/bin/env perl
use strict;
use warnings;
use bytes;
use Carp;
my $filename = $ARGV[0] or croak "usage: $0 <ADF filename>";
-f $filename or croak "File does not exist: $filename";