Author: | Tiago Alves Macambira [tmacam burocarata org] |
---|---|
Licence: | Creative Commons By-SA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main; | |
use Mojo::Base -strict; | |
use Test::More; | |
use Mojo::UserAgent; | |
use Mojo::Transaction; | |
# preparing... monkey patch is a good style | |
no warnings 'redefine'; | |
local *Mojo::UserAgent::get = sub { | |
my $tx = Mojo::Transaction->new; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use EV; | |
use AnyEvent::IRC::Client; | |
use Mojolicious::Lite; | |
app->config(hypnotoad => {listen => ['http://*:3000']}); | |
# Join #mojo on irc.perl.org | |
my $irc = AnyEvent::IRC::Client->new; | |
$irc->connect('172.16.0.34', 6667, {nick => "mojobot$$"}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Mojo::Base -strict; | |
use Mojo::UserAgent; | |
die "Usage: $0 http://api.github.com/v1/connected /users[=10] [API_NAME]\n" | |
unless scalar @ARGV >= 2; | |
my $url = shift; | |
my $path = shift; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Mojolicious::Lite; | |
plugin 'OAuth2', | |
google => { | |
key => $ENV{GOOGLE_OAUTH2_CLIENT_ID}, | |
secret => $ENV{GOOGLE_OAUTH2_CLIENT_SECRET}, | |
}; | |
my $service = 'https://www.googleapis.com'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=head2 get_date_range $start, $end | |
Returns a list of dates from the range in YYYY-MM-DD format. | |
$start and $end must also be in the same format. This is assumed and will break | |
if the format is anything other than that. | |
my $now = DateTime->now()->ymd; | |
my $last_month = DateTime->now()->subtract( days => 51 )->ymd; | |
my $date_range = get_date_range($last_month, $now, 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Modern::Perl; | |
use DBI; | |
use DBD::Pg qw(:async); | |
use Coro; | |
use AnyEvent; | |
use Time::HiRes qw(time); |
create different ssh key according the article Mac Set-Up Git
$ ssh-keygen -t rsa -C "[email protected]"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# is_within_ascii | |
# | |
# Returns a copy of the string if it is within ascii. If it is outside of the | |
# range, it will raise an error. | |
sub is_within_ascii { | |
my $string = shift; | |
# look for anything that isn't ascii or pass | |
$string =~ /([^\x{00}-\x{7f}])/ or return $string; |