Skip to content

Instantly share code, notes, and snippets.

View manchicken's full-sized avatar
🦀
I pinch.

Mike Stemle manchicken

🦀
I pinch.
View GitHub Profile
@manchicken
manchicken / named_capture.pl
Created January 17, 2014 04:26
This gist shows how to used named capture (along with anchors and /x) in regular expressions.
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use utf8;
use encoding 'utf8';
my $gbp = '£1.30';
my $usd = '$1.50';
@manchicken
manchicken / fork_play.pl
Created January 16, 2014 05:57
A quick demonstration of forking with blocking waits for when the children exit.
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use English;
for ( 0 .. 5 ) {
next if ( fork() > 0 ); # Remember, fork returns zero to the child, and the PID of the child to the parent.
identify_yourself(); # This sends the child process on its merry way.
@manchicken
manchicken / mock_module_fun.pl
Created October 28, 2013 02:20
Gist demonstrating Test::MockModule
#!/usr/bin/env perl
use strict;
use warnings;
use 5.014;
use DateTime;
use Test::More tests => 12;
use Test::MockModule;
# Fancy new package block syntax
@manchicken
manchicken / log_tester.pl
Last active December 23, 2015 22:09
Here's a gist on how to write a log file and then test that you wrote it
#!/usr/bin/env perl
use 5.010;use strict;use warnings;
use Test::More tests => 5;
use DateTime;
use FindBin qw/$Bin/;
use IO::File;
use Fcntl qw/:DEFAULT/;
@manchicken
manchicken / Animal.pm
Last active December 23, 2015 16:19
Here's the demo for 22nd September on abstraction loading. The code here is in the form of snippets. For the full demo, see here: https://github.com/manchicken/gist_per_day/tree/master/Perl/AbstractDemo
package Animal;
use Seahorse;
use Chicken;
sub new {
my ($pkg, %opts) = @_;
my $self = { %opts };
$self->{name} //= 'Dunno';
@manchicken
manchicken / mojo_merge_hashes.pl
Last active December 23, 2015 15:09
This is a simple web app which does validation and all of that, all in one little program.
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
use Mojolicious::Lite;
# Here's our validator construct
plugin 'validator' => {
messages => {
@manchicken
manchicken / android_component.pl
Created September 21, 2013 03:27
The Android portion of the Gist
#!/usr/bin/env perl
use strict;
use warnings;
local $| = 1;
## Yeah, don't do this. There's an issue in SL4A's Perl (or the API) which causes this to make the Android->new() hang.
# local $/ = undef;
use lib qw/./;
@manchicken
manchicken / web_component.pl
Created September 19, 2013 01:27
Here's part one of a two-part Gist, this is the piece that stores the data in Mongo
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
# I know that Mojolicious also uses all of the super-fun use strict and use warnings,
# but I still feel irrationally compelled to put them in myself. I hereby offer my non-apology.
use Mojolicious::Lite;
use MongoDB;
@manchicken
manchicken / fullscreen.xml
Created September 17, 2013 20:12
This is an old example of how to do something super simple in SL4A on Android.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_dark"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
@manchicken
manchicken / bitcounter.pl
Created September 16, 2013 14:46
Here's a very simplistic bit counter...
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
use Test::More tests => 7;
sub count_bits {
my ($num, $size) = @_;