Skip to content

Instantly share code, notes, and snippets.

View Ovid's full-sized avatar

Ovid Ovid

View GitHub Profile
@Ovid
Ovid / ma.pl
Last active October 2, 2023 11:05
Molecular Assembly Number In Pure Perl
#!/usr/bin/env perl
use v5.14.0;
use warnings;
use JSON::PP qw(decode_json);
use Data::Dumper;
use Getopt::Long;
GetOptions(
'perl' => \my $perl,
@Ovid
Ovid / flights.pl
Last active June 5, 2023 11:22
A Perl script to track flights of a jet. Defaults to last 7 days of Elon Musk's primary jet
#!/usr/bin/env perl
use v5.20;
use warnings;
use lib 'lib';
use WebService::OpenSky;
use Geo::ICAO 'code2airport';
use Text::CSV_XS 'csv';
use File::Temp 'tempfile';
use Mojo::UserAgent;
@Ovid
Ovid / monty.pl
Created January 25, 2023 09:52
Monty Carlo Problem
#!/usr/bin/env perl
# See also: https://fosstodon.org/@ovid/109745522656272671
# See also: https://priceonomics.com/the-time-everyone-corrected-the-worlds-smartest/
use Less::Boilerplate;
# $does_switch = 0 means they don't switch doors
# $does_switch = 1 means they do switch doors
my $does_switch = 0;
@Ovid
Ovid / data-types-in-perl.md
Created December 23, 2022 11:12
Data Types in Perl

Data Types in Perl

This document is to open discussion about what it takes to create an optional, native data type constraint system for Perl. It it not about building a type system.

In the book Types and Programming Languages by Benjamin Pierce, he writes:

@Ovid
Ovid / RedBlack.pm
Created December 10, 2022 11:44
RedBlack tree mockup in Corinna
# RedBlack tree mockup for Corinna, modeled after https://metacpan.org/pod/Tree::RedBlack
# It is not guaranteed to work
use feature 'class';
# we really want this to be a private class, but we can't yet
class RedBlack::Node {
field $key :reader :writer :param { undef };
field $value :reader :writer :param { undef };
field $parent :reader :writer :param { undef };
@Ovid
Ovid / perlclasstut.pod
Last active December 6, 2022 10:40
Corinna Class Tutorial
@Ovid
Ovid / SeKreT.pm
Created May 15, 2022 10:31
New test SQLite databases on the fly
# I needed to sure I was operating on pristine test databases
# every time my code called $test->schema (DBIx::Class and Test::Class::Moose).
# This handles that for me
package TestsFor::SeKreT {
use Test::Class::Moose;
use Less::Boilerplate; # gives me a sane version of Perl
use File::Copy qw(copy);
use File::Spec::Functions qw(catfile);
use SeKreT::Util::Data qw(
make_slug
@Ovid
Ovid / exception.md
Last active March 21, 2022 06:51
Exceptions in Perl?

Preface

This is something that likely cannot be made into an RFC for the Perl language at this time because implementation would be greatly simplified when the Corinna object model is in core. For example, a base class for what is discussed might look like the following:

# Exception is a poor name for warnings, so a better name is warranted
class Exception :version(v0.1.0) {
    # $message and $description might be from a messaging role
    field $message     :reader :param;
    field $description :reader :param { "" };
@Ovid
Ovid / dep-scanner.pl
Last active November 12, 2021 12:33
Sample of PPR-based dependency scanner
#!/usr/bin/env perl
# I decided it was time to learn PPR::X (Damian Conway's excellent regex-based Perl parser)
#
# This code is still heuristic in nature, but the challenge seemd fun.
#
# I thought it would be an interesting project to try to extract dependencies from
# Perl code. Thanks to `haj` giving me the clue needed to find a parsing error
use strict;
@Ovid
Ovid / Counter.pl
Created February 8, 2021 10:14
user-defined attributes in Cor?
class Counter {
# My::Cor::Attributes is using some hypothetical
# tool to extend Cor attributes. Because it's a
# `use` statement, it happens at compile time
use My::Cor::Attributes ':isa';
has $count :reader :new :isa(PositiveInt) = 0;
method inc () { $count++ }
method dec () { $count-- unless 0 == $count }
}