Skip to content

Instantly share code, notes, and snippets.

View Ovid's full-sized avatar

Ovid Ovid

View GitHub Profile
@Ovid
Ovid / decribe-image.pl
Created October 5, 2024 11:12
Use generative AI to describe images
#!/usr/bin/env perl
use v5.40.0;
use warnings;
package Image::Describe::OpenAI;
use Carp;
use OpenAPI::Client::OpenAI;
use Path::Tiny qw(path);
@Ovid
Ovid / vector.txt
Created August 30, 2024 06:58
GenAI provides real value. Vector databases.
I'm getting more pushback on #Mastodon that #GenAI doesn't provide any real value that traditional software can't provide cheaper or more reliably. <voice type="Samuel Jackson">Allow me to retort.</voice>
I'll try not to be too technical. Further, this is based on real work I did for a client and not something I just read about in a blog post.
Consider search engines. For "traditional" databases (RDBMs and NoSQL), you might have a search engine for videos. A user types in "videos about cats." With stemming and stop words, that becomes "cat."
What the heck is "stemming" and "stop words"? Stemming is the process of taking a word and reducing it to a common form. For example, consider the words run, runs, running, ran, runner, runners. All of those might be stemmed down to the word "run". This way, if someone searches for "videos about running", everything which has those words is a candidate for being returned in search results.
Stop words are different. Stop words are common words like "the," "is," "and,"
@Ovid
Ovid / Chat.pm
Last active July 6, 2024 13:24
An OpenAI chatbot in Perl and Corinna
# See also: https://curtispoe.org/articles/an-openai-chatbot-in-perl.html
use v5.40.0;
use experimental qw( class );
class OpenAI::Chat;
use OpenAPI::Client::OpenAI;
use Data::Printer;
use Carp qw( croak );
use utf8::all;
@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 October 2, 2024 15:35
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;