Skip to content

Instantly share code, notes, and snippets.

@s1037989
s1037989 / tiny
Last active June 12, 2017 18:36
Tiny URL clone built with Mojolicious in 1 hour
#!/usr/bin/env perl
use Mojolicious::Lite;
use Mojo::Pg;
use List::Util qw(shuffle);
# tiny.conf
# { pg => 'postgresql://a:b@c/d', };
# Get a quick and free tiny hosted Postgresql database at
@s1037989
s1037989 / admin.out
Last active September 13, 2016 15:35
Mojolicious 'extends' feature
$ perl extends get /admin
[Tue Sep 13 10:19:23 2016] [debug] GET "/admin"
[Tue Sep 13 10:19:23 2016] [debug] Rendering template "admin.html.ep" from DATA section
[Tue Sep 13 10:19:23 2016] [debug] Rendering template "logged_in.html.ep" from DATA section
[Tue Sep 13 10:19:23 2016] [debug] Rendering template "layouts/default.html.ep" from DATA section
[Tue Sep 13 10:19:23 2016] [debug] 200 OK (0.002844s, 351.617/s)
<!DOCTYPE html>
<html>
<head>
<title>Admin</title>
@s1037989
s1037989 / ACME.pm
Last active September 17, 2016 05:07
acme
package ACME;
use Mojo::Base 'Mojolicious';
use 5.20.0;
use feature qw(signatures);
no warnings qw(experimental::signatures);
sub startup {
my $self = shift;
$self->plugin('ACME');
$self->secrets(['new_passw0rd', 'old_passw0rd', 'very_old_passw0rd']);
@s1037989
s1037989 / URLQueue.pl
Created November 16, 2016 17:30 — forked from jberger/URLQueue.pl
Modularization of my answer from SO on URL queuing for non-blocking ua
#!/usr/bin/env perl
package Mojo::URLQueue;
use Mojo::Base 'Mojo::EventEmitter';
use Mojo::UserAgent;
has queue => sub { [] };
has ua => sub { Mojo::UserAgent->new(max_redirects => 5) };
has concurrency => 4;
@s1037989
s1037989 / wp-permissions
Last active November 23, 2017 22:21
Set permissions on wordpress directories
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Original Author: Michael Conigliaro (https://gist.github.com/macbleser/9136424)
# Modified by: Stefan Adams (https://gist.github.com/s1037989/7d2f0989b5a3cb1ed9e8e4452ded9ca6)
#
WP_ROOT=${1:-.} # <-- wordpress root directory
[ -e "$WP_ROOT/wp-config.php" ] || { echo "Usage: $0 /path/to/wordpress"; exit; }
@s1037989
s1037989 / README
Last active May 30, 2017 17:07
nginx mojolicious php-fpm
This will allow you to run a php app behind an nginx reverse proxy on another server and serve the non-php static files with Mojolicious
@s1037989
s1037989 / b-nb.pl
Last active May 6, 2017 05:16
Mojo::Pg example Blog, but non-blocking
package Model;
use Mojo::Base -base;
use Mojo::UserAgent;
has ua => sub { Mojo::UserAgent->new };
sub cb {
my ($self, $cb) = @_;
$cb ? sub { $cb->($self, @_) } : ();
@s1037989
s1037989 / carton-setup.sh
Last active July 7, 2017 06:23 — forked from hatak/carton-setup.sh
install perlbrew + cpanm + carton
#!/bin/bash
PERL_STABLE="5.26.0"
echo '%< --- installing perlbrew ---'
echo
echo 'If this fails, apt install build-essential'
curl -kL http://install.perlbrew.pl | bash
source ~/perl5/perlbrew/etc/bashrc
@s1037989
s1037989 / mojo
Last active July 7, 2017 06:23
mojo acme nginx
# Setup perlbrew + carton
# https://gist.github.com/s1037989/03b9fcf4e4ee0bfe890b7e529965c315
# Configure nginx for SSL with LE
# http://blog.mojolicious.org/post/157710119941/configuring-nginx-for-ssl-with-lets-encrypt
# cat /usr/sbin/mojo-acme
# use Mojolicious::Lite;
# app->log->path('/var/log/mojo-acme.log');
# plugin 'ACME';
# app->start;
# Start mojo-acme
#!/usr/bin/perl -w
# This script calls the SOAP method " DeviceAssetInfoExport" on an N-central server.
# The data structure returned is printed to stdout using Data::Dumper.
use strict;
use SOAP::Lite;
use Data::Dumper;
my $NableServer = SOAP::Lite ->uri("http://server.nable.com/")
->proxy("https://.../dms/services/ServerEI?wsdl");