Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib $FindBin::Bin;
my %u;
opendir(my $DP, '.') or die $!;
while (my $p = readdir $DP) {
package Mojo::JSON::Patch;
use Mojo::Base 'Mojo::JSON::Pointer';
use Carp 'croak';
use Mojo::Path;
sub set {
my $self = shift;
my $path = Mojo::Path->new(shift);
my $val = shift;
diff --git a/lib/Mojo/JWT.pm b/lib/Mojo/JWT.pm
index 11fdb2b..0281ff1 100644
--- a/lib/Mojo/JWT.pm
+++ b/lib/Mojo/JWT.pm
@@ -5,6 +5,9 @@ use Mojo::Base -base;
our $VERSION = '0.05';
$VERSION = eval $VERSION;
+our @EXPORT_OK = qw/decode_jwt encode_jwt/;
+
@jhthorsen
jhthorsen / checkbox.css
Created December 11, 2017 07:54
Css for styling checkboxes with css
label.checkbox,
label.radio {
cursor: pointer;
position: relative;
}
label.checkbox input + span,
label.radio input + span {
margin-left: 1.6rem;
}
@jhthorsen
jhthorsen / ClassMeta.pm
Last active February 14, 2018 16:03
How to extract methods and attributes
package ClassMeta;
use Mojo::Base -strict;
use Hook::AfterRuntime;
use B::Hooks::EndOfScope;
sub import {
my $class = shift;
my $caller = caller;
my %meta = (ATTRS => {}, METHODS => {});
my %ignore;
(function(w) {
/*
* Allow multiple clients share the same connection, but send/receive data on a topic they want
*
* var ws = WebSocketChannel("wss://example.com/mux", "testTopic");
* var ws = WebSocketChannel("wss://example.com/mux", {topic: "..", protocols: ...});
* var ws = WebSocketChannel({url: "wss://example.com/mux", topic: "..", protocols: ...});
* ws.onopen = function(e) { this.send({some: data}) };
*/
w.WebSocketChannel = function(url, params) {
@jhthorsen
jhthorsen / keep_alive.pl
Created September 26, 2018 09:28
Show how you need prevent the object from going out of scope
#!perl
use Mojolicious::Lite;
get '/' => sub {
my $c = shift;
my $ua = Mojo::UserAgent->new;
# Try keeping this object alive with http://localhost:3000?keep_alive=1
$c->stash(ua => $ua) if $c->param('keep_alive');
@jhthorsen
jhthorsen / git-report.pl
Last active September 27, 2018 08:16
Check when you worked in the git repos
#!/usr/bin/env perl
use strict;
use warnings;
my $dir = ($ARGV[0] and -d $ARGV[0]) ? shift @ARGV : '.';
my @ymd = (shift @ARGV);
my @today = (localtime)[5, 4]; # (year, mon)
$today[0] += 1900 if $today[0] <= 1900;
$today[1]++;
@jhthorsen
jhthorsen / wikipedia.css
Last active September 10, 2019 14:52
Stylus styling for wikipedia.org
#content {
border: 0;
padding: 40px 50px 30px 350px;
margin: 0;
}
#mw-page-base {
display: none;
}
@jhthorsen
jhthorsen / wedsites.css
Last active September 22, 2019 11:48
Custom css for https://wedsites.com/
h2,
h3 {
text-transform: uppercase;
}
.site {
letter-spacing: 0.1em;
line-height: 1.6rem;
text-transform: none;
max-width: 100% !important;