Skip to content

Instantly share code, notes, and snippets.

View diegok's full-sized avatar

Diego Kuperman diegok

View GitHub Profile
@diegok
diegok / bluetooth-state.pl
Last active January 19, 2020 23:41
Script to handle bluetooth before and after systemd-suspend
#!/usr/bin/env perl
use Mojo::Base -strict, -signatures;
use Mojo::File;
use Term::ANSIColor;
my $guard_file = Mojo::File->new('/tmp/bluetooth.status.guard');
(sub($name) {
({
wakeup => \&awake,
@diegok
diegok / start-hook.pl
Last active November 15, 2018 22:19
before_server_start is never trigger
use Mojolicious::Lite -signatures;
get '/' => sub($c) {
$c->render( text => $c->req->url->to_abs->port )
};
# Does not work
hook before_server_start => sub($server, $app) {
app->log->debug('before_server_start');
};
@diegok
diegok / autorandr.pl
Created September 4, 2018 10:42
Script to auto-configure external displays
#!/usr/bin/env perl
use FindBin qw($Bin);
use lib "$Bin/local/lib/perl5";
use Mojo::Base -strict, -signatures;
use Mojo::File qw( path );
use Parse::EDID qw/ parse_edid /;
use Mojo::JSON qw/ to_json /;
my $cards = cards_info();
#!/usr/bin/env perl
use Mojo::Base -strict, -signatures;
use Data::Dump qw/pp/;
say pp diffhash( { map { $_ => 1 } 1..30 }, { map { $_ => 1 } 20..60 } );
sub diffhash($h1, $h2) {
my ($h1p, $h2p) = ({%$h1}, {%$h2});
for (keys %$h1) {
use Mojo::Base -strict;
use Mojo::IOLoop;
my $promise = Mojo::IOLoop->delay;
Mojo::IOLoop->timer(2 => sub{ $promise->resolve(2) });
$promise->then(sub{
my $waited = shift;
my ($t1, $t3) = map { Mojo::IOLoop->delay } 1..2;
" gist-vim
let g:gist_open_browser_after_post = 1
let g:gist_clip_command = 'xclip -selection clipboard'
map <silent> ,g :Gist<CR>
#!/usr/bin/env perl
use common::sense;
use Mojo::UserAgent;
use Email::Address;
my $url = shift || say("Usage: $0 URL") && exit;
my $dom = Mojo::UserAgent->new->get($url)->res->dom;
say $_->address for Email::Address->parse( $dom->content );
use Mojo::DOM
use v5.24;
# Example of Mojo::DOM (7.33) mungling &nbsp; whitespaces
my $dom = Mojo::DOM->new('<div><h1>This is<span>&nbsp;Just Some&nbsp;Test</span></h1></div>');
say $dom->content; # <div><h1>This is<span>Just SomeTest</span></h1></div>
say $dom->at('h1')->all_text # This isJust SomeTest
@diegok
diegok / .replyrc
Created May 8, 2017 10:54
My reply and re.pl configs...
script_line1 = use strict
script_line2 = use warnings
script_line3 = use feature ':5.10';
script_line4 = use lib './lib'
script_line5 = use utf8
[Interrupt]
[DataDump]
[Colors]
[ReadLine]
package Resque::WorkingClass;
use Moose ();
use Moose::Exporter;
Moose::Exporter->setup_import_methods(
with_meta => [ 'perform' ],
also => 'Moose',
);
sub perform {