Skip to content

Instantly share code, notes, and snippets.

View jonathanstowe's full-sized avatar

Jonathan Stowe jonathanstowe

View GitHub Profile
#!/usr/bin/env perl6
use Cro::HTTP::Client;
use HTML::Parser::XML;
my $client = Cro::HTTP::Client.new;
my $url-channel = Channel.new;
$url-channel.send: 'http://rabidgravy.com/';
@jonathanstowe
jonathanstowe / silly-twitter-bio
Last active April 10, 2021 08:03
Pseudo random twitter bio in Perl 6
#!/usr/bin/env perl6
my Str @roles = ("Blogger" , "Unemployed" , "Storyfinder" , "Filmmaker" , "Communicator" , "Performer" , "Sculptor" , "Writer" , "Editor" , "Mastermind" , "Crossfitter" , "Academic" , "Educator" , "Consultant" , "Author" , "Dreamer" , "Dancer" , "Volunteer" , "Fan" , "Geek" , "Community Volunteer" , "Runner" , "Hiker" , "Feminist" , "Journalist" , "Photographer" , "Accountant" , "Alcoholic" , "Innovator" , "Disrupter" , "Chef" , "Gambler" , "Believer" , "Achiever" , "Lawyer" , "Doctor" , "Restauranteur" , "Philanthropist" , "Researcher" , "Foodie" , "Snowboarder" , "Humanitarian" , "Citizen" , "Redhead" , "Curator" , "Compiler" , "Contributor" , "Singer" , "Songwriter" , "Olympian" , "Learner" , "Musician" , "Fisherman" , "Stylist" , "Producer" , "Environmentalist" , "Entertainer" , "Explorer" , "Avatar" , "Extraordinaire" , "Genius" , "Misanthrope" , "Comedian");
my Str @descs = ("Social Entrepreneur" , "Idea Agent" , "Connector of Awesomeness" , "Avid Gamer" , "Social Media Guru" , "U
@jonathanstowe
jonathanstowe / visitor.pl6
Last active April 11, 2019 18:35
Perl6 visitor pattern example as per https://en.wikipedia.org/wiki/Visitor_pattern
#!/usr/bin/env perl6
# Perl6 example of the visitor pattern in https://en.wikipedia.org/wiki/Visitor_pattern
#
role CarElementVisitor {
...
}
class CarElement {
method accept(CarElementVisitor $visitor) {
@jonathanstowe
jonathanstowe / gist:d9a287c27857a0f3c10025cf8aa74c95
Created January 8, 2019 13:02
Perl6 ignore files in dir based on .gitignore.
use IO::Glob;
my @ignore = ".gitignore".IO.lines;
my $test = none(|@ignore.map(-> $l { glob($l) } ), /^\./ ) ;
for ".".IO.dir(:$test) {
.say;
}
@jonathanstowe
jonathanstowe / red-json-roundtrip.p6
Created January 1, 2019 09:32
Demonstrating round trip interoperability between the Red ORM and JSON::Class
use JSON::Class;
use Red;
model Foo is table('foo') does JSON::Class {
has Int $.id is serial;
has Str $.name is column;
}
my $*RED-DEBUG = $_ with %*ENV<RED_DEBUG>;
@jonathanstowe
jonathanstowe / gist:b079184d3483799a5158efc9f065380e
Created September 13, 2017 13:37
Calculatte network address and broadcast address from IP/subnet
my $ip = "130.45.34.36";
my $netmask = "255.255.240.0";
sub inet-aton(Str $ip --> Int) {
my Int $v;
my $i = 0;
for $ip.split(/\./).reverse -> Int() $octet {
$v += ( $octet +< ( 8 * $i++));
}
@jonathanstowe
jonathanstowe / gist:c0b5be2abb2f45d5b1018984f7dcf6ae
Created February 4, 2017 12:30
Remove unwanted submodules
for DIR in *
do
if [ -d $DIR ]
then
if [ -f $DIR/.gitmodules ]
then
pushd $DIR
git status
MOD=`cat .gitmodules | awk '/path = / { print $3 }'`
git reset HEAD
@jonathanstowe
jonathanstowe / ሰላምታ.pm
Created December 25, 2016 13:25
Amharic seasonal greeting in Perl 6
use አማርኛ;
መደብ ሰላምታ {
method ሰላምታ() {
say "መልካም ገና";
}
}
@jonathanstowe
jonathanstowe / Bar,om
Created November 26, 2016 19:22
Weiird Exporthow
use Foo;
outer Blob {
inner Bleep {
}
}
#!/usr/bin/env perl6
use v6.c;
my $sock = IO::Socket::INET.new(host => 'towel.blinkenlights.nl', port => 666);
for $sock.lines -> $v {
next if $v ~~ /^('==='|<:Cc>)/;
say $v if $v;