Skip to content

Instantly share code, notes, and snippets.

package Backend;
use Mojo::Base -base;
has 'pg';
has 'db';
sub bulk_insert {
my ($self, $table, $data, $options) = @_;
$options ||= {};
my $tx = $self->db->begin;
@s1037989
s1037989 / dedup.pl
Created April 20, 2018 12:48
This script deduplicates files based on md5sum. Wherever there are copies of a file this script removes the copies and replaces them with hardlinks
use String::Truncate qw(elide);
my $_md5sum = '';
my $_file;
my $c = 0;
# TODO: what Linux command generates the "md5\tpath" file
open MD5, 'md5sum-sort.txt';
while ( local $_ = <MD5> ) {
chomp;
#!/usr/bin/env perl
use lib 'lib';
use lib 'Mojocron/lib';
use Mojo::Log;
use Mojo::HelloWorld;
use Mojo::IOLoop;
use Mojo::Server::Daemon;
use Mojo::Server::Morbo;
use Mojo::Base -strict;
use Mojo::Util 'dumper';
use Algorithm::Diff 'sdiff';
my @a = split //, 'acaagaaaagagacgaaagacacaggggcgccgagggcagaagaaagagcaacgacggcccacaaaagcgggaacgccag';
my @b = split //, 'acaagaaaagatatgaaagacacaggggcgccgagggcagaagaagcaacgacggcccacaaaagcgggaggctgaaacgccag';
my @sdiff = sdiff(\@a, \@b);
say join '', map { $_->[1] || ' ' } @sdiff;
my $dry = 1;
# Remove query string from files on disk
$home->list_tree->slice(0)->each(sub{
/^(.*?)\?|\@/ or return;
say "$_ => $1";
return if $dry;
$_->move_to($1);
});
@s1037989
s1037989 / export
Created September 28, 2018 05:09
hubspot api export
use Mojo::Base -strict;
use Mojo::File 'path';
use Mojo::JSON 'j';
use Mojo::UserAgent;
use Mojo::URL;
# Usage:
# HUBSPOT_HAPIKEY=8....d HUBSPOT_USERID=3....0 perl export 3 2 1
our $base = 'https://api.hubapi.com';
@s1037989
s1037989 / json2tsv
Last active December 16, 2018 05:27
use ojo;
no warnings;
my $j = j(<>);
my %c = ();
$c{$_}++ foreach map { keys %$_ } @$j;
my @c = sort keys %c;
say join "\t", @c;
say join "\t", @$_{@c} foreach @$j;
package Mojolicious::Command::router;
use Mojo::Base 'Mojolicious::Command';
use Mojo::Log;
use Mojo::UserAgent;
use Mojo::Server::Prefork;
use Mojo::File 'path';
use Mojo::Util qw'dumper getopt';
use Mojo::Collection 'c';
use Mojo::ByteStream 'b';
use Mojo::Base -strict;
use Mojo::Util 'dumper';
use Mojo::File 'path';
use Mojo::ByteStream 'b';
my ($at, $qb) = map { b(path($_)->slurp)->split("\n") } @ARGV[0,1];
my %recon;
$at->grep(qr/^\d+\t/)->each(sub {
@s1037989
s1037989 / mycookie
Created February 4, 2019 20:07
Mojolicious::Sessions-like Cookies
package Mojolicious::MyCookie;
use Mojo::Base -base;
use Mojo::JSON;
use Mojo::Util qw(b64_decode b64_encode);
has [qw(cookie_domain secure)];
has cookie_name => 'mycookie';
has cookie_path => '/';
has default_expiration => 3600;