Skip to content

Instantly share code, notes, and snippets.

View ian-kent's full-sized avatar

Ian Kent ian-kent

View GitHub Profile
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.
package MooseRole;
use Moose::Role;
sub dosomething {
my ($field, %args) = @_;
my $package = caller;
use Data::Dumper;
print Dumper $package->meta->get_attribute($field);
}
#!/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 {
@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');
$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
}
});
#!/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;
@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}
@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 / Fixed.scala
Last active August 29, 2015 13:56
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 app = () => FakeApplication()
"Example" should {
@ian-kent
ian-kent / Fixed.scala
Last active August 29, 2015 13:56
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 }