Skip to content

Instantly share code, notes, and snippets.

Avatar

Joel Berger jberger

View GitHub Profile
View fetcher.js
export function Fetcher (options) {
if (options.base) this.base = options.base;
};
Fetcher.prototype.fetch = function(input, init) {
if (input instanceof Request) {
return window.fetch(input, init);
}
let url = this.base ? new URL(input, this.base) : new URL(input);
View conf.pl
my $x = {
a => 1,
b => 2,
};
$x->{ref}{a} = $x->{a};
$x; # this must be last
@jberger
jberger / dbix_async
Created Jun 26, 2020
DBIC / DBIx::Class Async Notes
View dbix_async
https://github.com/mcsnolte/Mojo-Pg-DBIC/commit/4f9d48cf52e6aecd782f1e2e20e1e1ae07a795a3#r17468260
https://gist.github.com/ribasushi/032fbb8b58e2b0d62fae#file-gistfile1-txt-L474-L490
I'm leaving these here because I keep thinking that they ARE here and they aren't ... until now.
@jberger
jberger / html_to_pdf.pl
Last active Jun 26, 2020
Extracted from old code, not necessarily recommended
View html_to_pdf.pl
sub _html_to_pdf {
my $cb = ref $_[-1] eq 'CODE' ? pop : undef;
my ($c, $html, $opts) = @_;
$opts||={};
require PDF::WebKit;
PDF::WebKit->configure(sub {
# default `which wkhtmltopdf`
my $exe= $c->executable( 'wkhtmltopdf' );
$_->wkhtmltopdf($exe);
});
View distify.markdown

SCN-App-Distify

A perl distribution builder for ServerCentral perl projects.

To build a module named SCN-Module-Foo ...

cd SCN-Module-Foo
distify SCN-Module-Foo
View markdown.pl
use Mojolicious::Lite -signatures;
use CommonMark;
# server markdown from markdown/ within app's home
my $root = app->home->child('markdown');
get '/*file' => sub ($c) {
#TODO handle traversal attacks
my $path = $root->child($c->stash('file'));
View socks
#!/bin/bash
PID=$(pgrep -f 'ssh -D')
CMD=$1
if [[ $CMD == '--stop' ]]
then
if [[ ! "$PID" ]]
then
echo 'socks proxy is not running';
View ovid.pl
use Mojo::Base -strict, -signatures;
use Mojolicious;
use Mojo::IOLoop;
use Mojo::Server::Daemon;
use Mojo::UserAgent;
# mock external websocket application
# waits 5s after connection then sends time and closes
my $external = Mojolicious->new;
View handled.diff
diff --git a/lib/Mojo/Promise.pm b/lib/Mojo/Promise.pm
index 0c66018db..db09a0033 100644
--- a/lib/Mojo/Promise.pm
+++ b/lib/Mojo/Promise.pm
@@ -185,6 +185,7 @@ sub _defer {
my $cbs = $self->{status} eq 'resolve' ? $self->{resolve} : $self->{reject};
@{$self}{qw(cycle resolve reject)} = (undef, [], []);
+ $self->{handled} = 1 if $self->{status} eq 'reject' && @{ $cbs || [] };
$self->ioloop->next_tick(sub { $_->(@$result) for @$cbs });
View gist:2a4387dcebdb8c155677797367cb4b96
$ git diff
diff --git a/t/mojo/promise_async_await.t b/t/mojo/promise_async_await.t
index 049253e47..084ad8de3 100644
--- a/t/mojo/promise_async_await.t
+++ b/t/mojo/promise_async_await.t
@@ -79,6 +79,13 @@ async sub test_two {
return $text;
}
+async sub returns_promise {
You can’t perform that action at this time.