This file contains 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
# See also | |
# http://www.perlmonks.org/bare/?node_id=881003 | |
# http://www.freebsd.org/cgi/man.cgi?query=getpeereid | |
use strict; | |
use warnings; | |
use IO::Socket::UNIX; | |
use Socket qw( SO_PEERCRED SOL_SOCKET ); | |
if (@ARGV) { | |
IO::Socket::UNIX->new(Peer => $ARGV[0], Type => SOCK_STREAM, Timeout => 10) or die $@; |
This file contains 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 Mojo::IOLoop::Tail; | |
use Mojo::Base "Mojo::IOLoop::Stream"; | |
has check_timeout => 0.01; | |
sub close { | |
my $self = shift; | |
return unless my $handle = $self->{handle}; | |
seek $handle, 0, 1; |
This file contains 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/perl | |
# Usage: echo -en "1.1.0.1\n127.0.0.1\n" | sudo /usr/bin/perl stdinping | |
# A lot of this code is mostly copy/paste/modify from Net::Ping | |
BEGIN { | |
# Make sure we don't load code that is not owned by root | |
$^X eq "/usr/bin/perl" or die "Invalid perl: $^X\n"; | |
my @perl_stat = stat $^X; | |
unshift @INC, sub { | |
my ($code, $module) = @_; |
This file contains 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
(function() { | |
/* | |
var swagger = new SwaggerClient({swagger: "2.0", info: {}, paths: {}}); | |
swagger.listPets({limit: 10}, function(err, xhr) { | |
console.log(xhr.code, xhr.body); | |
}); | |
*/ | |
window.SwaggerClient = function(spec) { | |
var self = this; |
This file contains 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 Mojo::Cursor; | |
=head1 NAME | |
Mojo::Cursor - General purpose async iterator | |
=head1 DESCRIPTION | |
L<Mojo::Cursor> is a class for instantiating an iterator object. |
This file contains 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
# $self->query_to_where({name => "Bruce"}, {name => "eq"}) => ["name = ?"], ["Bruce"] | |
# $self->query_to_where({name => "Bruce"}, {name => "like"}) => ["name LIKE '%?%'"], ["Bruce"] | |
# $self->query_to_where({age => ">=42"}, {age => "num"}) => ["name >= ?"], [42] | |
sub query_to_where { | |
my ($self, $q, $rules) = @_; | |
my (@where, @bind); | |
for my $col (sort keys %$rules) { | |
if (!length $q->{$col} // '') { | |
1; # next |
This file contains 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 sh | |
## | |
# This is script with usefull tips taken from: | |
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx | |
# | |
# install it: | |
# curl -sL https://raw.github.com/gist/2261536/hack.sh | sh | |
# |
This file contains 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
#!/bin/sh | |
# nytprofmojo.sh <time> <port> | |
# nytprofmojo.sh 10s 8080 | |
MOJO_PORT=${2:-3456} | |
perl -d:NYTProf -Ilib examples/hello.pl daemon -l http://*:$MOJO_PORT -m production 2>stderr.log & | |
MOJO_PID=$! | |
sleep 1 | |
wrk -c 100 -d ${1:-10} http://localhost:$MOJO_PORT | |
kill $MOJO_PID |
This file contains 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; | |
use List::Util 'reduce'; | |
use Time::Piece; | |
use Time::Seconds; | |
sub off { | |
return ( | |
'01-01' => 'Nyttårsdag', | |
'04-02' => 'Skjærtorsdag', |
This file contains 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 void; | |
use strict; | |
use Exporter 'import'; | |
use Carp; | |
our @EXPORT = 'void'; | |
sub void { | |
return unless defined wantarray; | |
my $caller = (caller 1)[3]; |