Skip to content

Instantly share code, notes, and snippets.

View dmanto's full-sized avatar

Daniel Mantovani dmanto

  • Córdoba, República Argentina
View GitHub Profile
#!/usr/bin/env bash
# Migrate tags to future @mojojs/core release 2.0.0 format
# assetTag, checkBoxTag, colorFieldTag, dateFieldTag, datetimeFieldTag, emailFieldTag,
# faviconTag, fileFieldTag, hiddenFieldTag, imageTag, inputTag, monthFieldTag,
# numberFieldTag, passwordFieldTag, radioButtonTag, rangeFieldTag, scripTag,
# searchFieldTag, styleTag, submitButtonTag
perl -p -i -e 's/ctx\.(\w+)Tag\(/ctx.tags.$1(/g' `find ./src ./test -name '*.[jt]s'`
perl -p -i -e 's/ctx\.(\w+)Tag\(/tags.$1(/g' `find ./views -name '*.html.tmpl'`
# buttonTo
perl -p -i -e 's/ctx\.buttonTo\(/ctx.tags.buttonTo(/g' `find ./src ./test -name '*.[jt]s'`
@dmanto
dmanto / index.js
Last active March 10, 2023 23:33
mapbox api proxyied to keep api key private
import mojo from '@mojojs/core';
const app = mojo();
// TO MAKE THE MAP APPEAR YOU MUST
// ADD YOUR ACCESS TOKEN FROM
// https://account.mapbox.com
const apiKey = 'your token here';
app.any('/', async ctx => {
ctx.stash.proxyUrl = ctx.urlFor('proxy-route', {absolute: true}).replace(/\/$/, '');
await ctx.render({inline: indexTemplate});
@dmanto
dmanto / del_test.t
Created August 24, 2022 21:35
Problem redirecting inside a delete route (perl mojolicious)
use Mojo::Base -strict;
use Test::Mojo;
use Test::More;
use Mojolicious::Lite;
get '/' => sub {shift->render(text => 'Hello!')};
del '/droute' => sub {shift->redirect_to('/')};
my $t = Test::Mojo->new;
$t->ua->max_redirects(1);
@dmanto
dmanto / aa_cover.t
Created October 2, 2020 18:04
Devel::Cover warnings when async await is used
use Mojo::Base -strict;
use Test::More tests => 1;
use Mojo::Base -async_await;
async sub hello_p {
return 'Hello Mojo!';
}
hello_p()->then(sub {ok 1})->wait;
#
# when you run this code, you don't get a line with "DESTROY called for two"
# as I guess it should be the case
#
# Is this behavior right? How can I force the DESTROY method to be called
# on a "started" object?
{
package MyServer;
use Mojo::Base 'Mojo::EventEmitter';
@dmanto
dmanto / ldtest.pl
Created April 26, 2019 20:59
Problems loading from __DATA__ section with Mojo::Loader
use strict;
use warnings;
use v5.10;
# this script should never give you the "Error (undef)" line.
# however, and depending on where you run it, you will get it time to time.
# For instance, running this on my macbook (perl 5.28.1, Mojolicious 8.14):
#
# $> for i in {1..20};do perl ldtest.pl;done
# # 3: Error (undef)