Skip to content

Instantly share code, notes, and snippets.

View kwakwaversal's full-sized avatar

Paul Williams kwakwaversal

View GitHub Profile
@kwakwaversal
kwakwaversal / perl-stubbing-ua.pl
Last active September 18, 2017 14:33
How to stub Mojo::UserAgent the right way #mojo #perl
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;
@kwakwaversal
kwakwaversal / irc_websocket.pl
Last active September 18, 2017 14:33
IRC websocket #perl
#!/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$$"});
@kwakwaversal
kwakwaversal / 0_reuse_code.js
Last active September 19, 2017 13:00
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@kwakwaversal
kwakwaversal / check_json.pl
Last active September 18, 2017 14:23
Nagios check - checks JSON url and path and outputs a nagios friendly response #perl #shell
#!/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;

Exporting code to Git and tiding up its history

Author

Tiago Alves Macambira [tmacam burocarata org]

Licence

Creative Commons By-SA

Table of Contents

@kwakwaversal
kwakwaversal / spike-oauth2
Last active September 18, 2017 14:26 — forked from zakame/spike-oauth2
#mojo #perl
#!/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';
@kwakwaversal
kwakwaversal / get_date_range.pl
Last active September 18, 2017 14:26
Returns an array of dates #perl
=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);
#!/usr/bin/env perl
use Modern::Perl;
use DBI;
use DBD::Pg qw(:async);
use Coro;
use AnyEvent;
use Time::HiRes qw(time);
@kwakwaversal
kwakwaversal / multiple_ssh_setting.md
Last active September 18, 2017 14:24 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH Keys settings for different github account #shell

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
@kwakwaversal
kwakwaversal / is_within_ascii.pl
Last active September 18, 2017 14:27
Method to check a string only contains ASCII characters #perl
# 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;