Skip to content

Instantly share code, notes, and snippets.

View diegok's full-sized avatar

Diego Kuperman diegok

View GitHub Profile
$_REPL->load_plugin($_) for qw(
History Colors
FancyPrompt Refresh
Interrupt OutputCache
DDC Nopaste
CompletionDriver::Keywords
CompletionDriver::LexEnv
CompletionDriver::Methods
CompletionDriver::INC
@diegok
diegok / DBIC.pm
Created September 4, 2011 12:17
putting some code together for a mojolicious DBIC plugin
package Mojolicious::Plugin::DBIC;
use Mojo::Base 'Mojolicious::Plugin';
our $VERSION = '0.01';
my $schemas = {};
sub register {
my ($self, $app, $cfg) = @_;
@diegok
diegok / mojo_ua_gzip.pl
Created October 10, 2011 01:09
Mojo::UserAgent with gzip support
#!/usr/bin/env perl
use 5.12.0;
use Mojo::UserAgent;
use Compress::Zlib;
my $ua = Mojo::UserAgent->new;
$ua->on( start => sub {
my ( $ua, $tx ) = @_;
@diegok
diegok / repl.rc
Created October 25, 2011 14:22
My Devel::REPL config file (~/.re.pl/repl.rc)
$_REPL->load_plugin($_) for qw(
History Colors
FancyPrompt Refresh
Interrupt OutputCache
DDC Nopaste
CompletionDriver::Keywords
CompletionDriver::LexEnv
CompletionDriver::Methods
CompletionDriver::INC
@diegok
diegok / mojo_ua_time_plus_gzip.pl
Created October 25, 2011 15:28
Mojo::UserAgent with gzip and timing support
=attr ua
User agent configured with logger and timing.
=cut
has ua => sub {
my $self = shift;
my $log = $self->log;
$log->debug( "Building user agent" );
my $ua = Mojo::UserAgent->new;
@diegok
diegok / test.pl
Created January 4, 2012 19:50
Example mojo lite app sending plain json
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/' => sub {
my $self = shift;
$self->render( text => '{"json":"ok"}', status => 201, format => 'json');
};
app->start;
@diegok
diegok / mercadopago.rb
Created January 8, 2012 19:34
Small ruby object to interact with MercadoPago API
class MercadoPago
require 'rubygems'
require 'json/add/core'
require 'uri'
require 'net/https'
attr_accessor :client, :secret, :currency
def initialize(options={})
@client = options[:client_id]
@diegok
diegok / gist:1601462
Created January 12, 2012 16:32
Example code for url_with proposal
$self->helper(
url_with => sub {
my $this = shift;
my $url = $this->req->url->clone;
return $url unless @_;
my $query = ref $_[-1] eq 'HASH'
|| ( ref $_[-1] eq 'ARRAY' and not @{$_[-1]} % 2 )
? pop : [];
sub set_config {
my $self = shift;
my $config = My::Config->new;
$self->app->log->debug( $config->test ); #yay
$self->helper( config => sub { $config } );
$self->log->debug( $self->config->test ); # Can't call method "test" on unblessed reference
}
@diegok
diegok / mojo_example.pl
Created March 24, 2012 09:50
Parallel GET requests into a timer of a mojolicious::lite app example
#!/usr/bin/env perl
use Mojolicious::Lite;
use Mojo::IOLoop;
my $clients = [];
my $timer_id;
set_next_requests();
get '/' => sub { shift->render( text => "I'm alive!" ) };