Skip to content

Instantly share code, notes, and snippets.

View Ovid's full-sized avatar

Ovid Ovid

View GitHub Profile
@Ovid
Ovid / ovid.py
Created January 26, 2024 12:06
Bold Toggling Bug
"""
This is a minimum test case for a bug in some code I'm writing. It's for a custom text editor (hobby
project).
The intent is that if I select some text and apply Bold formatting (for example, by hitting "ctrl-b"),
it will toggle the formatting. Specifically, it should remove the bold formatting if all of the selected
text is bold. Otherwise, it will apply the bold formatting.
However, it won't remove the bold formatting.
@Ovid
Ovid / overrides.py
Last active January 22, 2024 13:20
Force validation of overridden methods in Python
def enforce_overrides(cls):
"""
Class decorator to ensure methods marked with @override are actually overriding.
from abc import ABC
class A(ABC):
@abstractmethod
def foo(self):
pass
@Ovid
Ovid / cpan.md
Last active September 5, 2023 07:59
Native CPAN Authoring Tools

The Problem

CPAN uploads are declining. Part of this is the challenge of figuring out how to write a new module, navigate PAUSE, and release it. Many languages make it very easy to share new open source code with their community and that support is often in the core language.

Go Example

To publish a module in Go:

$ go mod tidy
@Ovid
Ovid / masto.pl
Last active February 8, 2024 08:36
Quick hack to post to Mastodon from the command line
#!/usr/bin/env perl
# vim: ft=perl
use Modern::Perl;
use Mastodon::Client;
use Config::Tiny;
use Getopt::Long;
use JSON::PP 'decode_json';
@Ovid
Ovid / perlclasstut.md
Last active August 25, 2023 13:56
Perl class tutorial

This is a work-in-progress based on this class tutorial. It covers features that are not yet implemented.

NAME

perlclasstut - Object-Oriented Programming via the class keyword

DISCLAIMER

This tutorial is a rough work-in-progress and only covers features of the

@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 };