Skip to content

Instantly share code, notes, and snippets.

#
# Tested on OS X 10.9.2 (MacBook Air) with Perl 5.18.2 and EV 4.17 (kqueue)
#
# 280.9MB memory usage, 0% CPU usage once roundtrips are finished after 29s
# (with all 10k sockets still open)
#
# Get the latest version of Mojolicious from http://github.com/kraih/mojo
# $ sudo sysctl -w kern.maxfiles=40960 kern.maxfilesperproc=20480
# $ ulimit -n 20480
# $ LIBEV_FLAGS=8 perl c10k_client.pl
@hernan604
hernan604 / gist:8d981811e33503e9e8f4
Created October 1, 2014 22:43
velocity bnf marpa by RNS
#FROM: https://gist.githubusercontent.com/rns/84c79eca7ac17e58fc19/raw/d667224fdd11bc924d1bcea6a9756f32c52baa69/velocity.pl
use 5.010;
use strict;
use warnings;
use Data::Dumper;
$Data::Dumper::Indent = 1;
$Data::Dumper::Terse = 1;
$Data::Dumper::Deepcopy = 1;
#!/usr/bin/env perl
use utf8;
use Mojolicious::Lite;
use DateTime;
get '/' => 'index';
my $clients = {};
websocket '/echo' => sub {
# screen like config
# Ctrl+b " - split pane horizontally.
# Ctrl+b % - split pane vertically.
# Ctrl+b arrow key - switch pane.
# Hold Ctrl+b, don't release it and hold one of the arrow keys - resize pane.
# Ctrl+b c - (c)reate a new window.
# Ctrl+b n - move to the (n)ext window.
# Ctrl+b p - move to the (p)revious window.
@hernan604
hernan604 / gist:61f60a3fdcaebb7aa563
Created May 4, 2014 15:59
postgres partitioning and table inheritance
This was combed from instant messaging session Keith had with Aleksandr.
It describes partitioning as it relates to Postges and how Postgres implements partitioning
(from a user's perspective) using table inheritance.
Keith: do you know what a primary key is?
me: yes
Keith: ok… do you know what a check constraint is
me: yes
Keith: great, do you know what an index is?
@hernan604
hernan604 / gist:5d903fb926d879df29ee
Last active August 29, 2015 14:00
Sort Multicolumn perl vs javascript
////////////////////////////////////////////JAVASCRIPT
x=[
{ idade : 12, nome : "caaaa", prioridade : 0, label : "um" },
{ idade : 12, nome : "caaaa", prioridade : -2, label : "dois" },
{ idade : 12, nome : "bbb" }
];
y=x.sort(function(a, b) {
return (b.idade > a.idade)
@hernan604
hernan604 / gist:11073741
Last active August 29, 2015 14:00
evaluate javascript in vim with perl + vim::x
package JsEval;
use strict;
use warnings;
use Vim::X;
use JavaScript::V8;
#ABSTRACT: Eval lines of js typed in vim. Use 'vim_log(args)' to print output
=head2 .vimrc
@hernan604
hernan604 / gist:11057601
Last active August 29, 2015 14:00
js minifier for vim (using Vim::X + perl)
package JsMinifier;
use strict;
use warnings;
use Vim::X;
use JavaScript::Packer;
=head2 .vimrc
perl push @INC, '/home/hernan/mnt/desktop/home/hernan/mnt/sda4/files/perl/vimx/lib/';
perl use JsMinifier;
@hernan604
hernan604 / .vimrc
Last active August 29, 2015 14:00
Json pretty for vim ( using perl Vim::X )
perl push @INC, '/home/hernan/vimscripts/lib/';
perl use JsonPrettyRange;
map ,json :call Vpretty_range();
@hernan604
hernan604 / .vimrc
Last active August 29, 2015 14:00
javascript beautifier vim plugin (using Vim::X / perl)
perl push @INC, '/home/usuario/vimscripts/perl/vimx/lib/';
perl use JsBeautifier;
map ,js :call Vjs_beautifier();