Skip to content

Instantly share code, notes, and snippets.

Michael J South msouth

Block or report user

Report or block msouth

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@msouth
msouth / newton.pl
Created Jul 29, 2019
Watch Newton's method converge
View newton.pl
my $square = shift or die "Usage: $0 3 [where 3 is the number you want to find the square root of]";
my $guess;
print
"This is an implementation of Newton's method for finding roots.
(Specifically, we're finding square roots here, although Newton's
method can be used for many different kinds of functions.)
The only goal is for you to see how rapidly it converges, it is
otherwise quite useless :D.\n\n\n";
@msouth
msouth / add_inflate_snippet.sh
Last active Jan 18, 2017
quick test of inflate/deflate stuff using column filter in DBIX::Class
View add_inflate_snippet.sh
perl -ni -e '$cutting = 1 if /#.*start_inflate/; print unless ($cutting or $_=~/\s*1;\s*/); $cutting = 0 if /#.*end_inflate/;' lib/Test/Schema/Result/TestDeflate.pm
cat inflate_snippet.pl >> lib/Test/Schema/Result/TestDeflate.pm
View flip.pl
#!/usr/bin/env perl
use strict;
use warnings;
my $flips = shift @ARGV // 1000;
print "I'm going to flip a coin [$flips] times...\n";
my @thresholds = (5, 10);
View gist:bdf987d50fa500bc9085
use strict;
use warnings;
while (<DATA>) {
s/[<>]//g;
s{\[((/)?(b|i|s))\]}{<$1>}g;
print;
}
__DATA__
View whatever.pl
use strict;
#########################################
############# would be in Animal.pm normally
#########################################
package Animal;
sub new {
my $package = shift;
# this 'bless' call tells that anonymous hash "if someone calls ->foo on you, look in $package for a sub named 'foo',
View convert_to_markdown.pl
use DBI;
use strict;
use warnings;
my $db_name = shift or die "call as $0 [database_name] [mysql user] [mysql password]";
my $mysql_user = shift || 'root';
my $mysql_password = shift || '';
my $dbh = DBI->connect("dbi:mysql:database=$db_name", $mysql_user, $mysql_password) || die DBI->errstr;
@msouth
msouth / Foodle.pm
Created Aug 6, 2013
quick store/retrieve with Storable in a Dancer app
View Foodle.pm
package Foodle;
use Dancer ':syntax';
use Storable;
our $VERSION = '0.1';
get '/' => sub {
template 'index';
};
@msouth
msouth / tt.pl
Created Aug 5, 2013
single file tt test
View tt.pl
use Template;
my $tt = Template->new( START_TAG=>'<%', END_TAG=>'%>' );
$tt->process(\*DATA, {}, \*stdout) ;
__DATA__
<% index = 0; last = 0; %>
index is now <% index %>
View config.yml
# This is the main configuration file of your Dancer app
# env-related settings should go to environments/$env.yml
# all the settings in this file will be loaded at Dancer's startup.
# Your application's name
appname: "Acme::Test::Dancer::Plugin::Database"
# The default layout to use for your application (located in
# views/layouts/main.tt)
layout: "main"
@msouth
msouth / gist:5959998
Created Jul 9, 2013
double-encode some utf-8 stuff for artistically interesting output
View gist:5959998
use utf8;
use v5.10;
my $string = "áéíóú";
binmode(STDOUT, ":utf8");
say $string;
use Encode qw/encode decode/;
my $bob = encode( 'UTF-8', $string);
You can’t perform that action at this time.