Skip to content

Instantly share code, notes, and snippets.

@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';
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);
});
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;
#!/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;
@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;
package Backend;
use Mojo::Base -base;
has 'pg';
has 'db';
sub bulk_insert {
my ($self, $table, $data, $options) = @_;
$options ||= {};
my $tx = $self->db->begin;
#!/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");
@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
@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 / 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, @_) } : ();