Skip to content

Instantly share code, notes, and snippets.

View petdance's full-sized avatar

Andy Lester petdance

View GitHub Profile
Testing under Perl 5.026000, /home/andy/perl5/perlbrew/perls/perl-5.26.0/bin/perl
| 1.96 | 2.22 | 2.999_01 | 2.999_02 | 2.999_03 | HEAD | grep | ag | rg
--------------------------------------------------------------------------------------------------------------------------
ack foo /home/andy/linux/ | 11.24 | 14.60 | 16.85 | 8.02 | 6.16 | 6.19 | 1.30 | 2.23 | 0.84
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
sub every(\%) {
my $hash = shift;
my $id = "$hash";
Usage: ack [OPTION]... PATTERN [FILES OR DIRECTORIES]
Search for PATTERN in each source file in the tree from the current
directory on down. If any files or directories are specified, then
only those files and directories are checked. ack may also search
STDIN, but only if no file or directory arguments are specified,
or if one of them is "-".
Default switches may be specified in ACK_OPTIONS environment variable or
an .ackrc file. If you want no dependency on the environment, turn it
Here's how I built a sidebar with sections in Jekyll:
```{% comment %}
The sections for the sidebar are managed through _data/sections.yml. We load
them in the order they're declared (`site.data.sections`), then loop through
each section and list any pages.
To allow pages to be ordered without explicitly requiring it, we sort by
weight. The lower the weight, the higher a page floats in the order (get it?).
{% endcomment %}
{% assign sections = site.data.sections %}
@petdance
petdance / gist:0f1b9e37750cd443bc4bad4b467e7454
Created July 14, 2017 02:07
Why does \Q not work here?
#!perl
use warnings;
use strict;
use 5.010;
use Data::Dumper;
my $re = '\Qfoo(';
warn Dumper( $re );
$ cat foo.t
#!/var/perl/bin/perl
use strict;
use warnings;
use lib '/home/alester/Test-Simple-1.302085/blib/lib';
use Test::Tester;
use Test::More tests => 1;
use strict;
use warnings;
use Test::Tester;
use Test::More tests => 1;
use TW::Test::More;
#check_test( sub { is_fs_custnum( 'GARBAGECRAP' ) }, { ok => 0 }, 'Garbage should fail' );
use strict;
use warnings;
use Test::Tester;
use Test::More tests => 1;
use TW::Test::More;
check_test( sub { is_fs_custnum( 'GARBAGECRAP' ) }, { ok => 0 }, 'Garbage should fail' );
defmodule Euler003 do
# http://projecteuler.net/index.php?section=problems&id=3
# The prime factors of 13195 are 5, 7, 13 and 29.
# What is the largest prime factor of the number 600851475143 ?
def largest_prime_factor( n ) do
factors = prime_factors( n )
[largest|_] = factors
IO.write 'Prime factors are '
@petdance
petdance / gist:7c44793015b58c110a75c7b75f4d49b6
Created April 20, 2017 14:28
dirty, a shell script for showing modified files whether under Git or Subversion.
#!/usr/bin/perl
use warnings;
use strict;
# Try Git.
my @lines = qx{git diff --name-only 2> /dev/null};
if ( $? == 0 ) {
print for @lines;
exit 0;