Skip to content

Instantly share code, notes, and snippets.

open($fh, "<", $path1.$file )
# if path1 fails, try path2 and set missing boolean to 1
or $missing = 1 and open($fh, "<", $path2.$file )
or warn "can't open $file in $path1, $path2;
bimmerlabs /
Last active November 28, 2018 06:27
Renames Tekla Structures pointcloud files to be human readable
use Mojo::Base -base;
use Mojo::Util qw(getopt);
use Mojo::File;
use Mojo::DOM;
getopt 'p|path=s' => \my $path;
sub main {
# look in xml elements for laserscans that have hashes for names, then rename.
bimmerlabs /
Last active July 13, 2018 18:25
Subprocess error: Connection already closed when using a line like "if (defined $self->param('foo') { ... }" and the param is not defined
#!/usr/bin/env perl
use Mojolicious::Lite;
# it turns out a race condition was being caused, that accidentally 'won' every time before -
# but the updated Mojolicious made the broken code apparent. This no longer works:
get '/' => sub {
my $self = shift;
bimmerlabs / deployment.bat
Created February 28, 2018 14:48
Mojolicious server batch file for Windows - runs on startup so you don't need a command prompt open all the time. Put a shortcut to myapp.vbs in the 'startup' folder, the actual myapp.vbs / deployment.bat files go in your app folder.
@echo off
perl C:\Users\yournamehere\myapp\ daemon -m production
bimmerlabs /
Created February 14, 2018 14:42
stream Mojo::Asset::Memory object
# streams $zipfile created in memory (not saved anywhere)
# should work similar with Excel::Writer::XLSX
# (I generate and return the zip file in a Mojo::IOLoop Subprocess)
'attachment; filename=' . $filename . '.zip;');
bimmerlabs /
Last active January 11, 2018 16:54
A Mojolicious::Lite forZip file streaming with Mojo::Asset::Memory
#!/usr/bin/env perl
use Mojolicious::Lite;
use Archive::Zip::SimpleZip qw($SimpleZipError);
get '/#file' => sub {
my $c = shift;
# read a file from disk
my $file1 =
bimmerlabs /
Created October 27, 2017 14:39
If I comment out the line with 'test2' it works - but otherwise, it times out. What am I missing? taken from
use Mojolicious::Lite;
use Mojo::IOLoop;
get '/' => sub {
my $c = shift;
sub { say 'test1'; Mojo::IOLoop->timer(1 => shift->begin); },
sub { say 'test2'; my $test = 'test'; },
sub { say 'test3'; $c->render(text => 'Hi'); },
bimmerlabs /
Created June 6, 2017 16:38
Mojo:PG migration - I'm having some trouble and it's because I don't quite understand what it's doing.
package MyApp::Model::DBAdmin;
use Mojo::Base -base;
has 'database';
sub new { bless {}, shift }
sub create_table {
my ($self, $tablename) = @_;
$tablename = "test";