Skip to content

Instantly share code, notes, and snippets.

@scottw
scottw / hydrate.pl
Created July 9, 2018 13:56
An example of a no-dependency template in Perl
#!/usr/bin/env perl
use strict;
use warnings;
# hydrate: poor man's templating
#
# usage: hydrate key1=value1 key2=value2 ... path/to/file.in > path/to/file.out
#
# substitutes all strings '{{key1}}' in file.in with 'value1'
@scottw
scottw / brew-depends-on.pl
Created January 26, 2018 22:39
Script to see what casks depend on other casks (the inverse of 'brew deps')
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';
my %deps = map { $_ => [] } map { chomp; $_ } `brew list`;
for my $cask (sort keys %deps) {
print STDERR "\r\e[2KInspecting cask: '$cask'";
@scottw
scottw / inject
Last active December 14, 2017 20:36
Minion job injector and worker
#!/usr/bin/env perl
use Mojo::Base -strict;
use Minion;
my $minion = Minion->new(Pg => 'postgresql://postgres@/test');
for (1..10) {
$minion->enqueue('my-task', [name => "Number $_"], {delay => $_});
say STDERR "Injected $_";
}
$app->plugin(OpenAPI => {url => $app->home->rel_file('schema.yaml'),
spec_route_name => 'docs'});
sub docs {
my $c = shift->openapi->valid_input or return;
$c->app->routes->lookup('docs')->to->{cb}->($c);
}
--- local/lib/perl5/Mojolicious/Plugin/OpenAPI.pm~ 2017-03-02 16:35:26.000000000 -0700
+++ local/lib/perl5/Mojolicious/Plugin/OpenAPI.pm 2017-03-14 09:34:37.000000000 -0600
@@ -223,7 +223,7 @@
local $spec->{id};
delete $spec->{id};
- local $spec->{basePath} = $c->url_for($spec->{basePath});
+# local $spec->{basePath} = $c->url_for($spec->{basePath});
local $spec->{host} = $c->req->url->to_abs->host_port;
--- local/lib/perl5/Mojolicious/Plugin/OpenAPI.pm~ 2017-03-02 16:35:26.000000000 -0700
+++ local/lib/perl5/Mojolicious/Plugin/OpenAPI.pm 2017-03-13 17:45:31.000000000 -0600
@@ -71,6 +71,7 @@
my $spec_route = $route->get->to(cb => \&_reply_spec);
if (my $spec_route_name = $config->{spec_route_name} || $api_spec->get('/x-mojo-name')) {
$spec_route->name($spec_route_name);
+ $spec_route->route($spec_route_name);
$route_prefix = "$spec_route_name.";
}
package Meta;
sub docs {
my $c = shift->openapi->valid_input or return;
$c->respond_to(openapi => $c->openapi->spec(''), any => $c->openapi->spec('')); ## FIXME
}
1;
__DATA__
package Meta;
sub docs {
my $c = shift->openapi->valid_input or return;
$c->render(openapi => $c->openapi->spec(''));
}
1;
__DATA__
## purpose:
##
## create a Terrform override file containing temporary role
## credentials generated from an account protected with MFA.
##
## usage:
##
## $ make credentials aws_override.tf PROFILE=my-profile TOKEN_CODE=123456
## $ terraform apply
##