Skip to content

Instantly share code, notes, and snippets.

@brianmed
brianmed / catch_all.pl
Created July 8, 2013 06:03
Attemp at catch all route
#!/opt/perl
use Mojolicious::Lite;
get '/' => sub {
my $self = shift;
$self->render('index');
};
@brianmed
brianmed / datachannel.pl
Created October 10, 2013 23:40
WebRTC DataChannel two user chat. Signaling included using websockets.
#!/opt/perl
use Mojolicious::Lite;
use JSON;
get '/' => sub {
my $self = shift;
$self->render("index");
};
@brianmed
brianmed / valid.pl
Last active January 10, 2018 08:58
jQuery Mobile and Mojolicious Validation example
#!/opt/perl
use Mojolicious::Lite;
helper setup_valid => sub {
my $self = shift;
my $topics = shift;
my $v = $self->validation;
@brianmed
brianmed / gist:6966815
Created October 13, 2013 20:02
Might need to check for variable existence with PERL5LIB.
#!/bin/tcsh
if ( ${?VARIABLE} ) then
echo "Joy:${VARIABLE}"
else
echo "Joy"
endif
sub hash_password {
my $self = shift;
my ($plain_text, $settings_str) = @_;
unless ($settings_str) {
my $salt = join('', map { chr(int(rand(256))) } 1 .. 16);
$salt = Crypt::Eksblowfish::Bcrypt::en_base64( $salt );
return(Crypt::Eksblowfish::Bcrypt::bcrypt_hash({
key_nul => 1,
use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
$ua->cert(...);
$ua->transactor->http_proxy(...);
$ua->max_redirects(3);
# Say hello to the Unicode snowman with "Do Not Track" header
say $ua->get('www.☃.net?hello=there' => {DNT => 1})->res->body;
package Mojo::UserAgent::Proxy;
use Mojo::Base -base;
has [qw(http https no)];
sub detect {
my $self = shift;
$self->http($ENV{HTTP_PROXY} || $ENV{http_proxy});
$self->https($ENV{HTTPS_PROXY} || $ENV{https_proxy});
return $self->no([split /,/, $ENV{NO_PROXY} || $ENV{no_proxy} || '']);
use IO::String;
$io = IO::String->new("one\ntwo\nthree\nfour\nfive\n");
$line = (<$io>)[int(rand(5))];
print($line);
var iceServers = {
iceServers: [{
url: 'stun:23.21.150.121'
}]
};
var optionalRtpDataChannels = {
optional: [{DtlsSrtpKeyAgreement: true}, {RtpDataChannels: true }]
};
@brianmed
brianmed / site.txt
Created October 26, 2013 20:24
Attempt to create a sitemap.
[bpm@Orfgum] c:.../playground/sparky/lib>find . | grep Mojo | grep '\.pm$' | /opt/perl go.pl
[bpm@Orfgum] c:.../playground/sparky/lib>cat go.pl
BEGIN { print(qq(<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">)) };
while (<>) {
s#.*#<url><loc>http://mojo.us/$&</loc></url>#;
print;
}
END { print("</urlset>") };