Skip to content

Instantly share code, notes, and snippets.

View mjgardner's full-sized avatar
🏠
working from home

Mark Gardner mjgardner

🏠
working from home
View GitHub Profile
@mjgardner
mjgardner / .pl
Created July 25, 2023 19:04 — forked from ology/.pl
Perl map vs foreach
#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark;
my $count = shift || 100_000_000;
timethese($count, {
map_it => \&map_it,
@mjgardner
mjgardner / gunzip_benchmarks.pl
Last active January 3, 2023 18:30
Benchmarking various gzip decompression methods in Perl
#!/usr/bin/env perl
use v5.36;
use Benchmark 'cmpthese';
use File::Temp 'tempfile';
use IO::Compress::Gzip qw(gzip $GzipError);
use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
use IPC::Cmd 'run';
use Gzip::Faster 0.04 'gunzip_file';
@mjgardner
mjgardner / openpgp.md
Created November 18, 2022 21:52
Verifying my cryptographic key for Keyoxide

openpgp4fpr:4dadfefe8e4ad0f92bcbbb8142f3ca898cb08a45

@mjgardner
mjgardner / perl_date_locale.pl
Last active April 20, 2021 21:46
Simple web application that presents today's day and date according to the user's preferred language
#!/usr/bin/env perl
use Mojolicious::Lite -signatures;
use DateTime;
use DateTime::Locale;
use HTTP::AcceptLanguage;
my %locales
= map { $_ => DateTime::Locale->load($_) } DateTime::Locale->codes;
@mjgardner
mjgardner / WebFeedSources2OPML.xslt
Last active April 9, 2017 14:51
Example XSLT stylesheet for transforming macOS Safari "Shared Links" feeds into an OPML file
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/plist">
<opml version="2.0">
<head>
<title>Converted Safari WebFeedSources.plist</title>
</head>
<xsl:apply-templates select="array"/>
@mjgardner
mjgardner / perilo_vs_tie_log.t
Created October 10, 2016 15:15
Test performance of PerlIO::via::Logger vs Tie::Handle::Filter::Output::Timestamp::EveryLine
#!/bin/env perl
use 5.008;
use strict;
use warnings;
use Test::More;
use Benchmark;
use Data::Random qw(rand_set rand_words);
use PerlIO::via::Logger;
@mjgardner
mjgardner / # aria2 - 2016-07-15_18-25-49.txt
Created July 15, 2016 23:27
aria2 on Mac OS X 10.11.5 - Homebrew build logs
Homebrew build logs for aria2 on Mac OS X 10.11.5
Build date: 2016-07-15 18:25:49
@mjgardner
mjgardner / mohammad_mandelbrot.sh
Last active May 20, 2016 18:06
Perl one-liner that outputs an ASCII Mandelbrot set using the name "Mohammad". Since the image is fractal and self-similar, there are an infinite amount of different Mohammads contained in the image as you zoom further in. (Please fork and try to golf this down to a Twitter-friendly <=140 characters.)
seq 39|perl -nE'$y=$_/13-1.5,say map{$a=$b=0;$c=64;$b=2*$a*$b+$y,$a=$p-$q+$_/33-1.5while--$c&&($p=$a*$a)+($q=$b*$b)<2;$c?substr"demmahoM",$c%8,1:" "}0..78'

Keybase proof

I hereby claim:

  • I am mjgardner on github.
  • I am mjgardner (https://keybase.io/mjgardner) on keybase.
  • I have a public key whose fingerprint is E084 AA34 4FC1 A05C E100 97F5 F9B4 4BCF 02BB B06E

To claim this, I am signing this object:

@mjgardner
mjgardner / sort_domains.pl
Created November 13, 2014 21:00
sort domains from input via Schwartzian transform
#!/usr/bin/perl
# sort domains from input via Schwartzian transform
print map { $_->[0] } sort {
eval join ' or ',
map {"\$a->[1][-$_] cmp \$b->[1][-$_]"}
1 .. (
scalar @{$a->[1]} > scalar @{$b->[1]}
? scalar @{$a->[1]} : scalar @{$b->[1]} )
} map { [$_, [cc_tld( split /\./ )]] } <>;