Skip to content

Instantly share code, notes, and snippets.

View petdance's full-sized avatar

Andy Lester petdance

View GitHub Profile
#!/usr/bin/env perl
use warnings;
use strict;
use 5.010;
use Text::CSV_XS;
my $csv = Text::CSV_XS->new;
@petdance
petdance / counts.sql
Last active May 3, 2019 13:34
Gender counts per reason
/* The MariaDB I installed doesn't support CTEs, so use a subquery */
SELECT * FROM (
select
reason,
SUM( CASE WHEN gender = 'Male' THEN 1 END) as M,
SUM( CASE WHEN gender = 'Female' THEN 1 END) as F,
SUM( CASE WHEN gender NOT IN ('Male','Female') THEN 1 END) AS X,
COUNT(gender) AS T
from response
inner join reasons on reasons.responseid = response.responseid
@petdance
petdance / jeopardy.pl
Created April 11, 2019 15:08
Most money you can win on Jeopardy
#!/usr/bin/perl
use warnings;
use strict;
use 5.010;
use List::Util qw( sum );
my $score = 0;
@petdance
petdance / diff.patch
Created March 20, 2019 21:23
This update to syntax/perl.vim broke indenting
This update to my syntax/perl.vim made auto indenting break.
If I type
sub foo {
and then hit return, the cursor used to move to the next line and be indented 4 spaces. This is no longer the case.
Index: syntax/perl.vim
===================================================================
# Install Homebrew.
$ su ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Show brew's commands.
$ brew help
# Check current user.
$ echo $(whoami)
# Grant access to the folders.
$ cat prototypes-timings.pl
#!/var/perl/bin/perl
use warnings;
use strict;
use 5.020;
no warnings 'experimental::signatures';
use feature 'signatures';
Category Pri Due Task
Writing A Jul 1 Finish Esther article
Bills A Financial spreadsheet
Blog A Article: vim templates
ackbook A Jul 8 Start chapter 4
Bills B Renew passport
Career C Machine learning 101 slides
Open source C Kill dead POD policy in Perl::Critic
# unprioritized & dated
@petdance
petdance / gist:9c107d8c3d0f2483691a057187e10bc8
Last active May 6, 2019 15:49
vim -c 'source ~/vim-perl/tools/time-it.vim' Lib/TW/Mechanize/Card.pm
TOTAL COUNT MATCH SLOWEST AVERAGE NAME PATTERN
0.089719 2504 66 0.001406 0.000036 perlMatch \%([$@%&*]\@<!\%(\<split\|\<while\|\<if\|\<unless\|\.\.\|[-+*!~(\[{=]\)\s*\)\@<=/\%(/=\)\@!
0.073028 2964 526 0.000167 0.000025 perlString \I\@<!-\?\I\i*\%(\s*=>\)\@=
0.039462 5639 3214 0.000037 0.000007 perlVarPlain \%([@$]\|\$#\)\$*\%(\I\i*\)\=\%(\%(::\|'\)\I\i*\)*\%(::\|\i\@<=\)
0.023359 2438 0 0.000042 0.000010 perlStatementPword \<\%(get\%(pw\%(uid\|nam\)\|gr\%(gid\|nam\)\|login\)\)\|\%(end\|[gs]et\)\%(pw\|gr\)ent\>
0.020884 2864 440 0.000037 0.000007 perlStatementProc \<\%(plan\|use_ok\|require_ok\|ok\|is\|isnt\|diag\|explain\|note\|like\|unlike\|cmp_ok\|is_deeply\|skip\|can_ok\|isa_ok\|pass\|fail\|BAIL_OUT\|subtest\)\>
0.017876 2482 50 0.000091 0.000007 perlStatementIndirObjWrap \%(\<\%(map\|grep\|sort\|printf\=\|say\|system\|exec\)\>\s*\)\@<={
0.015173 2454 16 0
<!DOCTYPE html>
<html>
<head>
<title> </title>
</head>
<body>
<link href="https://cdnjs.cloudflare.com/ajax/libs/tabulator/3.5.2/css/tabulator.min.css" rel="stylesheet">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/tabulator/3.5.2/js/tabulator.min.js"></script>
<div>
START OF TABLE
| HEAD | grep | ag | rg
------------------------------------------------------------------------
ack foo /home/andy/parrot/ | 0.43 | 0.08 | 0.09 | 0.08
ack foo -w /home/andy/parrot/ | 0.40 | 0.08 | 0.08 | 0.09
ack foo\w+ -w /home/andy/parrot/ | 0.36 | 0.09 | 0.12 | 0.07
ack foo\w+ -C10 /home/andy/parrot/ | 0.52 | 0.09 | 0.14 | 0.07
ack (set|get)_\w+ /home/andy/parrot/ | 0.82 | 0.18 | 0.18 | 0.08
------------------------------------------------------------------------
Total | 2.53 | 0.52 | 0.61 | 0.39