Skip to content

Instantly share code, notes, and snippets.

View kraih's full-sized avatar

Sebastian Riedel kraih

View GitHub Profile
package Mojolicious::Lite::GetPost;
use Mojo::Base -base;
use Mojo::Util 'monkey_patch';
sub import {
my $caller = caller;
monkey_patch $caller, 'get_post', sub {
return $caller->app->routes->any([qw(GET POST)] => @_);
};
package Mojolicious::Plugin::GZip;
use Mojo::Base 'Mojolicious::Plugin';
use IO::Compress::Gzip 'gzip';
# Just set "gzip => 1" in the stash and it will try to compress your content
sub register {
my ($self, $app) = @_;
$app->hook(
after_dispatch => sub {
use warnings;
use strict;
use feature ':5.10';
use B;
# Type and flags for reference
my $obj = B::svref_2object(\(my $dummy = !!1));
my $TYPE = $obj->SvTYPE;
my $FLAGS = $obj->FLAGS;
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 });
use 5.16.1;
use Mojo::UserAgent;
# Fetch web site
my $ua = Mojo::UserAgent->new;
my $tx = $ua->get('mojolicio.us/perldoc');
# Extract title
say 'Title: ', $tx->res->dom->at('head > title')->text;
@kraih
kraih / pr.md
Created August 23, 2012 15:57 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@kraih
kraih / a.pl
Created June 9, 2012 22:07 — forked from tempire/a.pl
use Mojo::UserAgent;
use Modern::Perl;
my $ua = Mojo::UserAgent->new;
my $delay = Mojo::IOLoop->delay;
$delay->begin;
$ua->get(
'tempi.re/ip' => sub {
warn Mojo::UserAgent->new->get('tempi.re/ip')->res->body;
$ git init
$ git add .
$ git commit -m 'Initial version'
$ heroku create -s cedar --buildpack http://github.com/judofyr/perloku.git
$ git push heroku master
...
#!/bin/sh
./myapp.pl daemon -l http://*:$PORT -m production
#!/usr/bin/env perl
use ExtUtils::MakeMaker;
WriteMakefile(
PREREQ_PM => {'Mojolicious' => '2.98'}
);