Skip to content

Instantly share code, notes, and snippets.

(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 / 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;
@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;
}
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/;
+
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;
#!/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) {
@jhthorsen
jhthorsen / void.pm
Last active September 30, 2016 11:48
This is stupid, but I made it anyway
package void;
use strict;
use Exporter 'import';
use Carp;
our @EXPORT = 'void';
sub void {
return unless defined wantarray;
my $caller = (caller 1)[3];
#!/usr/bin/env perl
use Mojolicious::Lite;
use List::Util 'reduce';
use Time::Piece;
use Time::Seconds;
sub off {
return (
'01-01' => 'Nyttårsdag',
'04-02' => 'Skjærtorsdag',
@jhthorsen
jhthorsen / nytprofmojo.sh
Last active February 19, 2016 11:44
NYTProf for Mojolicious
#!/bin/sh
# nytprofmojo.sh <time> <port>
# nytprofmojo.sh 10s 8080
MOJO_PORT=${2:-3456}
perl -d:NYTProf -Ilib examples/hello.pl daemon -l http://*:$MOJO_PORT -m production 2>stderr.log &
MOJO_PID=$!
sleep 1
wrk -c 100 -d ${1:-10} http://localhost:$MOJO_PORT
kill $MOJO_PID
@jhthorsen
jhthorsen / hack.sh
Created February 7, 2016 00:26 — forked from aki-null/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2261536/hack.sh | sh
#