Skip to content

Instantly share code, notes, and snippets.

View ian-kent's full-sized avatar

Ian Kent ian-kent

View GitHub Profile
@ian-kent
ian-kent / Broken.scala
Created February 16, 2014 17:31
Fix for "The play Cache is not alive (STATUS_SHUTDOWN)"
package ReactiveAPI
import org.specs2.mutable.Specification
import play.api.mvc.{Action, Results}
import play.api.test.{WithApplication, FakeApplication}
import play.api.cache.Cache
class ExampleSpec extends Specification with Results {
val appWithRoutes = FakeApplication(withRoutes = {
case ("GET", "/") => Action{ Ok }
@ian-kent
ian-kent / Authentication.scala
Created February 11, 2014 19:10
Akka based authentication and authorisation for Play Framework
package wrappers
import play.api._
import play.api.mvc._
import scala.concurrent._
import scala.concurrent.Future
import play.mvc.Http.Status
import ExecutionContext.Implicits.global
import play.libs.Akka
import akka.actor.{Actor, Props}
#!/usr/bin/env perl
BEGIN {
$ENV{'HTTP_PROXY'} = '<INSERT PROXY>';
$ENV{'HTTPS_PROXY'} = '<INSERT PROXY>';
$ENV{'MOJO_PROXY'} = 1;
$ENV{'MOJO_USERAGENT_DEBUG'} = 1;
}
use Mojolicious::Lite;
$r->bridge('/:something')->to(cb => sub {
my $something = shift->stash('something');
my $type = type_of_something($something);
if($type eq 'girl') {
# route to foo#bar
} elsif ($type eq 'boy') {
# route to baz/qux
}
});
@ian-kent
ian-kent / mango_cursor.pl
Last active December 29, 2015 13:19
Mango cursor repeating in non-blocking mode
use Mango;
use strict;
use warnings;
print "Mango version: $Mango::VERSION\n";
my $mango = Mango->new($ENV{MANGO_URI} // "mongodb://localhost:27017");
my $db = $mango->db('test_db');
my $collection = $db->collection('test_collection');
#!/usr/bin/env perl
use Mojolicious::Lite;
my $r = app->routes;
$r->get('/')->to(cb => sub {
my $self = shift;
$self->render(text => 'test');
});
my $b = $r->bridge('/#arg1/#arg2')->to(cb => sub {
package MooseRole;
use Moose::Role;
sub dosomething {
my ($field, %args) = @_;
my $package = caller;
use Data::Dumper;
print Dumper $package->meta->get_attribute($field);
}
String found where operator expected at test.pl line 14, near "dosomething 'test'"
(Do you need to predeclare dosomething?)
syntax error at test.pl line 14, near "dosomething 'test'"
Execution of test.pl aborted due to compilation errors.
@ian-kent
ian-kent / also errors.pl
Created July 15, 2013 21:23
Some examples - working, erroring and segfaulting
package obj2;
sub new { my ($package, %args) = @_; bless { %args }, 'obj2' };
sub render { shift->{obj}->() };
package obj;
sub new { bless {}, 'obj' };
sub capture { return obj2->new(obj => pop) }
package main;
@ian-kent
ian-kent / gist:6002917
Last active December 19, 2015 18:59
Text xslate undefined function with virtual templates
package main;
use Data::Dumper;
use Text::Xslate;
my $count = 0;
my $macro = undef;
my $xslate = Text::Xslate->new(
path => {
'test.tx' => qq{