Skip to content

Instantly share code, notes, and snippets.

View MadMartigan's full-sized avatar

Marty Tennison MadMartigan

View GitHub Profile
@MadMartigan
MadMartigan / gist:641318f4d3b407cb8eeac79a591944c1
Created March 10, 2017 15:44
Postgrest SSL reverse proxy config for nginx
# domain.com nginx config
server {
listen 443;
server_name domain.com;
return 301 https://www.$server_name$request_uri;
}
server {
listen 80;
@MadMartigan
MadMartigan / gist:7218147
Created October 29, 2013 16:38
How to loop through an arrayref returned from a helper directly in a template
# the helper
$app->helper(
testarray => sub {
my $self = shift;
my @array = ("Quarter","Dime","Nickel");
return \@array;
}
);
@MadMartigan
MadMartigan / gist:6817097
Created October 3, 2013 21:03
Mojolicious bridges
my $foo = $r->bridge('/foo')->to(cb => sub {
my $self = shift;
$self->app->log->debug('foo cb');
return 1;
});
$foo->route('/')->to(cb => sub {
my $self = shift;
$self->app->log->debug('foo/ cb');
package Mojolicious::Plugin::Pipeline::CSSCompressor;
use Mojo::Base 'Mojolicious::Plugin';
use CSS::Compressor 'css_compress';
sub register {
my ($self, $app) = @_;
# Register "css_compressor" filter
$app->filter(css_compressor => sub { css_compress shift });
@MadMartigan
MadMartigan / gist:5262964
Created March 28, 2013 13:05
Tables using ep
%= t 'table', class => 'myclass', => begin
%= t 'tr', => begin
%= t 'td', => begin
cell content
% end
% end
% end
@MadMartigan
MadMartigan / gist:4739145
Created February 8, 2013 13:53
Undefined first element on arrayref insert
my $arrayref;
for ( 1..5 ) {
push(@$arrayref, $_);
}
$collection->insert({arrayref => $arrayref});
> db.test.find().pretty();
{
"_id" : ObjectId("511502d0acd47abc56010000"),
@MadMartigan
MadMartigan / gist:4724311
Created February 6, 2013 17:43
The mango driver was just release a few hours ago. I thought I would post a little cheatsheet for anyone interested. You can cut an paste this file into your test app to get some data loaded and see a few ways to access it.
<h2>Mango Cheatsheet</h2>
% my $mango = Mango->new('mongodb://localhost:27017')->db('foo')->collection('foo');
% my @records;
% for my $cntr (1..10) {
%
% my @objects;
@MadMartigan
MadMartigan / gist:4527228
Created January 14, 2013 01:44
how to set layout in before_dispatch hook
$self->hook(
before_dispatch => sub {
my $c = shift;
if (!$c->param('layout')) {
if ($c->req->is_xhr) {
$c->stash(layout => 'ajax');
}
}
.....
CORE
Perl (v5.16.0, darwin)
Mojolicious (3.12, Rainbow)
OPTIONAL
EV (not installed)
IO::Socket::IP (not installed)
IO::Socket::SSL (not installed)
@MadMartigan
MadMartigan / gist:3146752
Created July 19, 2012 20:54
Static file error
#!/usr/bin/env perl
use Mojolicious::Lite;
# Documentation browser under "/perldoc"
plugin 'PODRenderer';
get '/' => sub {
my $self = shift;
$self->render('index');
};