Skip to content

Instantly share code, notes, and snippets.

maschine bimmerlabs

View GitHub Profile
@bimmerlabs
bimmerlabs / DBAdmin.pm
Created Jun 6, 2017
Mojo:PG migration - I'm having some trouble and it's because I don't quite understand what it's doing.
View DBAdmin.pm
package MyApp::Model::DBAdmin;
use Mojo::Base -base;
has 'database';
sub new { bless {}, shift }
sub create_table {
my ($self, $tablename) = @_;
$tablename = "test";
@bimmerlabs
bimmerlabs / myapp.pl
Created Oct 27, 2017
If I comment out the line with 'test2' it works - but otherwise, it times out. What am I missing? taken from http://bit.ly/2zJHEK1
View myapp.pl
use Mojolicious::Lite;
use Mojo::IOLoop;
get '/' => sub {
my $c = shift;
$c->delay(
sub { say 'test1'; Mojo::IOLoop->timer(1 => shift->begin); },
sub { say 'test2'; my $test = 'test'; },
sub { say 'test3'; $c->render(text => 'Hi'); },
);
@bimmerlabs
bimmerlabs / myapp.pl
Last active Jan 11, 2018
A Mojolicious::Lite forZip file streaming with Mojo::Asset::Memory
View myapp.pl
#!/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 =
Mojo::Asset::File->new(
@bimmerlabs
bimmerlabs / Downloads.pm
Created Feb 14, 2018
stream Mojo::Asset::Memory object
View Downloads.pm
# 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)
$self->res->headers->content_disposition(
'attachment; filename=' . $filename . '.zip;');
$self->res->headers->content_type('application/zip');
$self->reply->asset(Mojo::Asset::Memory->new->add_chunk($zipfile));
@bimmerlabs
bimmerlabs / deployment.bat
Created Feb 28, 2018
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.
View deployment.bat
@echo off
perl C:\Users\yournamehere\myapp\myapp.pl daemon -m production
@bimmerlabs
bimmerlabs / myapp_broken.pl
Last active Jul 13, 2018
Subprocess error: Connection already closed when using a line like "if (defined $self->param('foo') { ... }" and the param is not defined
View myapp_broken.pl
#!/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;
$self->render_later;
Mojo::IOLoop->subprocess(
@bimmerlabs
bimmerlabs / tekla_cloud_utility.pl
Last active Nov 28, 2018
Renames Tekla Structures pointcloud files to be human readable
View tekla_cloud_utility.pl
#!/usr/bin/perl
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.
View conditional = vs == warning
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;
You can’t perform that action at this time.