Skip to content

Instantly share code, notes, and snippets.

View TristinDavis's full-sized avatar

Tristin Davis TristinDavis

  • Thrivent Financial
  • Arkansas, USA
  • 02:44 (UTC -05:00)
View GitHub Profile
use Mojolicious::Lite;
get '/tasks' => sub {
my $self = shift;
$self->stash(
tasks => [
map { [ split /\s+/ ] }
split /\n/, qx(ps axh -o comm,stat,\%cpu,nice,pid,rss,user)
]
#!/usr/bin/env perl
use common::sense;
use lib qw(../.. /tk/lib /tk/mojo2/lib);
use ojo;
use Util;
use Unicode::Normalize 'NFD';
use Data::Dumper;
my $conf = {
@TristinDavis
TristinDavis / myapp-validationclass-example.pl
Created November 16, 2012 01:40
Validation-Class Basics
package MyApp::Validation;
use Validation::Class;
use base 'Validation::Class';
# a validation rule
field 'login' => {
label => 'user login',
error => 'login invalid',
validation => sub {
@TristinDavis
TristinDavis / myapp-validationclass-example.pl
Created November 16, 2012 01:40
Validation-Class Basics
package MyApp::Validation;
use Validation::Class;
use base 'Validation::Class';
# a validation rule
field 'login' => {
label => 'user login',
error => 'login invalid',
validation => sub {
@TristinDavis
TristinDavis / gist:4083155
Created November 16, 2012 01:41
DBIx::Class::Candy +MoreSugar
package Application::Model::Sugar;
# common sugar routines
sub serial {
my %chngs = @_;
my %attrs = ('data_type', 'integer', 'is_auto_increment', 1, null() );
$attrs{$_} = $chngs{$_} for keys %chngs;
return %chngs;
}
package PiffHop;
use strict;
use warnings;
use base 'Mojolicious';
# This method will run once at server start
sub startup {
my $self = shift;
@TristinDavis
TristinDavis / index.pl
Created November 17, 2012 10:25 — forked from dvinciguerra/index.pl
Mojolicious::Lite and Ajax Example
#!/usr/bin/env perl
use DateTime;
use Mojolicious::Lite;
get '/' => 'index';
get '/service/datetime' => sub {
my $self = shift;
my $dt = DateTime->now;
@TristinDavis
TristinDavis / check_webpage.pl
Created November 17, 2012 11:02
Check your website with Mojolicous and Test::Mojo
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 6;
use Test::Mojo;
my $url = 'http://localhost/~rhaen/index.html';
my $t = Test::Mojo->new;
#!/usr/bin/env perl
use Mojolicious::Lite;
use Coro;
use Mojo::IOLoop;
Mojo::IOLoop->recurring(0 => sub {cede});
hook around_dispatch => sub {
my $next = shift;
async { $next->() };
use Mojolicious::Lite;
use EV;
use AnyEvent;
use AnyEvent::Util;
get '/' => sub {
my $self = shift;
# Run Perl oneliner in separate process and capture STDOUT
fork_call {