Skip to content

Instantly share code, notes, and snippets.

View diegok's full-sized avatar

Diego Kuperman diegok

View GitHub Profile
@diegok
diegok / gettext.sh
Created May 18, 2012 13:31
Build and update .po files for catalyst
#!/bin/sh
in_files="--directory=../lib --directory=../root/admin --directory=../root/public"
out_file="../lib/MyApp/I18N/messages.pot"
po_dir="../lib/MyApp/I18N"
msg_up() {
po_file=$po_dir/$1.po
if [ -f $po_file ]
then
@diegok
diegok / exam.pl
Created June 25, 2012 15:59
Example usage of render_not_found().
get '/post/:slug' => sub {
my $self = shift;
my $post = $self->db->posts->find_by_slug( $self->stash('slug') );
return $self->render_not_found unless $post;
# ...
}
@diegok
diegok / app.pl
Created June 25, 2012 21:27
render_exeption() and render_not_found() example.
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/divide/:dividend/by/:divisor' => sub {
my $self = shift;
my $dividend = $self->param('dividend');
my $divisor = $self->param('divisor');
return $self->render_not_found
unless $dividend =~ /^\d+$/ && $divisor =~ /^\d+$/;
@diegok
diegok / gist:3145656
Created July 19, 2012 17:56
Using Mojo::IOLoop->delay "multi-guard"
my $delay = Mojo::IOLoop->delay;
for my $url ('mojolicio.us', 'cpan.org') {
$delay->begin;
$ua->get($url => sub {
my ($ua, $tx) = @_;
$delay->end(
$tx->res->dom->at('title')->text
);
});
}
package My::Search::Product;
use Elastic::Doc;
has 'name' => (
is => 'rw',
isa => 'Str',
boost => 3,
analyzer => 'my_spanish',
);
my $results = $products
->queryb([map {$_=>$query} qw/name brand brands tags/])
->filterb( status => 'avail' )
->search;
my $results = $products->queryb({
-qs => {
query => $query,
fields => ['name','brands','tags','variant'],
default_operator => 'AND',
fuzzy_min_sim => 0.7,
fuzzy_prefix_length => 2,
lenient => 1,
#minimum_should_match => 3,
}
has 'name' => (
is => 'rw',
isa => 'Str',
boost => 5,
analyzer => 'my_clean',
multi => {.
stem => { boost => 2, analyzer => 'my_spanish' },
sound => { boost => 1, analyzer => 'sound_like' },
}
);
======
Query:
======
{
"fields" : [
"_parent",
"_routing",
"_source"
],
"from" : 0,
{ // part of _source
price: {
_mean: 8.05,
carrefour: {
_mean: 8.05,
4ff30e2fc27e955902000009: {
p: 8.05
},
4ff30e2fc27e955902000008: {
p: 8.05