This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojo::Base 'Mojolicious'; | |
use CGI::Expand; | |
sub startup | |
{ | |
my $self = shift; | |
$self->hook(before_dispatch => sub { | |
my $c = shift; | |
my $hash = CGI::Expand->expand_hash($c->req->params->to_hash); | |
$c->param($_ => $hash->{$_}) for keys %$hash; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my ($c, $name) = (shift, shift); | |
my $cb = sub {''}; | |
if(@_ % 2) { | |
if(ref $_[-1] && ref $_[-1] eq 'CODE') { | |
$cb = pop; | |
} | |
else { | |
my $value = shift; | |
$cb = sub {$value}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tested with 1.0.0-pre.2, 0.9.7 or less does not work. | |
// Chosen modified to search on @results_data[n].text not .html | |
App.ChosenMultipleSelect = Em.Select.extend({ | |
multiple: true, | |
attributeBindings: [ 'multiple' ], | |
didInsertElement: function() { | |
this._super(); | |
this.$().chosen(); | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub register | |
{ | |
my ($self, $app) = @_; | |
$self->helper(include_static => sub { | |
my ($c, $path) = @_; | |
return unless $path; | |
if($path !~ m|^/|) { | |
my $root = first { -f "$_/$path" } @{$c->app->renderer->paths}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojo::ByteStream; | |
app->helper(alerts => sub { | |
my $c = shift; | |
my $html = ''; | |
for my $message (qw|success info error|) { | |
my $css = "alert alert-$message"; | |
if($c->flash($message)) { | |
$html .= $c->tag('div', class => $css, $c->flash($message)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Oops, here's the right benchmark snippet. | |
use Locale::Country::Multilingual; | |
use List::MoreUtils qw(zip pairwise); | |
use Benchmark 'timethese'; | |
use Unicode::Collate; | |
my $lcm = Locale::Country::Multilingual->new; | |
my $c = Unicode::Collate->new; | |
my ($lang, $format) = qw(en_US LOCALE_CODE_ALPHA_2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Need to remove font lock stuff before printing | |
(defun perl-module-version-after-point () | |
(interactive) | |
(save-excursion | |
(if (search-forward-regexp "\\([A-Za-z]\\w*\\(::\\w+\\)*\\)" (point-at-eol) t) | |
(let* ((module (match-string 1)) | |
; syntax for cmd.exe and *nix | |
(command (format "perl -e\"eval qq|require %s|; print %s->VERSION unless qq|$@|\"" module module)) | |
(version (shell-command-to-string command))) | |
(message "%s: %s" module (if (string= version "") "unknown" version))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Single or Plural Count Helper for Mojolicious using Lingua::EN::Inflect::PL | |
# usage: | |
# $size = 10 | |
# count($size, 'user') | |
# 10 users | |
# | |
# $users = an array ref with one User object | |
# count($users) | |
# 1 User | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Turn text from a text area into HTML paragraph elements. | |
$self->helper(paragraphs => sub { | |
my ($c, $text) = @_; | |
return unless $text; | |
my $html = join '', map $c->tag('p', $_), split /^\s*\015\012/m, $text; | |
Mojo::ByteStream->new($html); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> create table t (id int, v1 int, v2 int); | |
Query OK, 0 rows affected (0.05 sec) | |
mysql> insert into t values (1,100,200),(2,101,201),(3,102,202); | |
Query OK, 3 rows affected (0.00 sec) | |
Records: 3 Duplicates: 0 Warnings: 0 | |
mysql> select * from t; | |
+------+------+------+ | |
| id | v1 | v2 | |