Skip to content

Instantly share code, notes, and snippets.

View peczenyj's full-sized avatar
💻
coding

Tiago Peczenyj peczenyj

💻
coding
View GitHub Profile
@peczenyj
peczenyj / dsl_for_html_generation.rb
Created March 2, 2009 18:09 — forked from fabiokung/dsl_for_html_generation.rb
HTML DSL, adicionando atributos
def method_missing(name, *args)
attributes = args.last.to_a.collect {|y| y = "#{y[0]}=\"#{y[1]}\"" } .join(" ") if args.size > 1
puts "<#{name} #{attributes}>#{args.first}"
yield if block_given?
puts "</#{name}>"
end
html do
body do
h1 "My internal DSL"
@peczenyj
peczenyj / fib_all.pl
Created June 5, 2011 18:40
fibonacci examples
use Modern::Perl;
use Attribute::Memoize;
use Inline qw(C);
=cut
Benchmark: running memoize, nativo, nativo_memoize, normal for at least 2 CPU seconds...
   memoize: 2.086 wallclock secs ( 2.08 usr +  0.01 sys =  2.09 CPU) @ 299315.79/s (n=625570)
    nativo: 2.2446 wallclock secs ( 2.24 usr +  0.01 sys =  2.25 CPU) @ 3131.11/s (n=7045)
nativo_memoize: 2.04854 wallclock secs ( 2.05 usr +  0.00 sys =  2.05 CPU) @ 291284.88/s (n=597134)
    normal: 2.07676 wallclock secs ( 2.06 usr +  0.00 sys =  2.06 CPU) @ 13.59/s (n=28)
@peczenyj
peczenyj / a.pm
Created October 19, 2011 20:38
Exemplo de Role + Delegation
package Closeable;
use Moose::Role;
requires 'close';
1;
package Connector;
use Moose;
@peczenyj
peczenyj / sleepsort.sh
Created December 1, 2011 17:32
Sleep Sort
for i in 4 9 8 7 1 2; do
sleep $i && echo $i &
done
@peczenyj
peczenyj / Progress.pm
Created December 8, 2011 02:50
middleware para verificar progresso
package FileHandleProxy;
use base qw/FileHandle/;
# constructor
sub new {
my ($class, %args) = @_;
my $self = \%args;
bless $self, $class;
@peczenyj
peczenyj / a.pl
Created January 30, 2012 12:49
Alphabet Soup
#!/usr/bin/perl
use Data::Dumper;
use List::Util qw(reduce min);
use feature 'say';
use Modern::Perl;
open (my $fh, '<', $ARGV[0]) or die $!;
my $i = 0;
my $total = readline($fh);
@peczenyj
peczenyj / logfile.txt
Created June 28, 2012 19:10
erro bizarro api
peczenyj Dashboard Notifications 18 Account Settings Log Out New Gist My Gists Starred Gists All Gists Back to GitHub
peczenyj (owner)
Revisions
8ee7cd peczenyj 4 minutes ago
gist: 1ab7b4824f57e9543c75
Description:
globo.com ruby erro bizarro edit
Private Clone URL:
git@gist.github.com:1ab7b4824f57e9543c75.git
logfile.txt # raw
@peczenyj
peczenyj / logfile.txt
Created June 28, 2012 19:10
erro api
/opt/railsapps/webmediaapi/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/networking.rb:335: [BUG] rb_register_sigaltstack: th->altstack not initialized
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0089 p:---- s:0374 b:0374 l:000373 d:000373 CFUNC :read
c:0088 p:0027 s:0369 b:0369 l:000368 d:000368 METHOD /opt/railsapps/webmediaapi/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/networking.rb:335
c:0087 p:0015 s:0362 b:0362 l:001498 d:000361 BLOCK /opt/railsapps/webmediaapi/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/networking.rb:316
c:0086 p:0111 s:0360 b:0360 l:0015b0 d:0015b0 METHOD /opt/generic/ruby-1.9.3/lib/ruby/1.9.1/timeout.rb:68
c:0085 p:0043 s:0348 b:0348 l:001498 d:001498 METHOD /opt/railsapps/webmediaapi/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/networking.rb:315
@peczenyj
peczenyj / spelling.awk
Last active December 10, 2015 07:58
Usage: gawk -v word=some_word_to_verify -f spelling.awk [ big.txt [ big2.txt ... ]] Gawk version with 15 lines -- 04/13/2008 Author: tiago (dot) peczenyj (at) gmail (dot) com Based on : http://norvig.com/spell-correct.html
# Usage: gawk -v word=some_word_to_verify -f spelling.awk [ big.txt [ big2.txt ... ]]
# Gawk version with 15 lines -- 04/13/2008
# Author: tiago (dot) peczenyj (at) gmail (dot) com
# about.me/peczenyj
# Based on : http://norvig.com/spell-correct.html
function edits(w,max,candidates,list, i,j){
for(i=0;i< max ;++i) ++list[substr(w,0,i) substr(w,i+2)] # deletes
for(i=0;i< max-1;++i) ++list[substr(w,0,i) substr(w,i+2,1) substr(w,i+1,1) substr(w,i+3)] # transposes
for(i=0;i< max ;++i) for(j in alpha) ++list[substr(w,0,i) alpha[j] substr(w,i+2)] # replaces
for(i=0;i<= max ;++i) for(j in alpha) ++list[substr(w,0,i) alpha[j] substr(w,i+1)] # inserts
@peczenyj
peczenyj / spelling2.awk
Created January 1, 2013 14:10
Usage: gawk -f spelling.awk words.txt big.txt
# Usage: gawk -f spelling2.awk file_with_words_one_per_line.txt [ big.txt [ big2.txt ... ]]
# Gawk version with 15 lines -- 04/13/2008
# Author: tiago (dot) peczenyj (at) gmail (dot) com
# about.me/peczenyj
# Based on : http://norvig.com/spell-correct.html
function edits(w,max,candidates,list, i,j){
for(i=0;i< max ;++i) ++list[substr(w,0,i) substr(w,i+2)]
for(i=0;i< max-1;++i) ++list[substr(w,0,i) substr(w,i+2,1) substr(w,i+1,1) substr(w,i+3)]
for(i=0;i< max ;++i) for(j in alpha) ++list[substr(w,0,i) alpha[j] substr(w,i+2)]
for(i=0;i<= max ;++i) for(j in alpha) ++list[substr(w,0,i) alpha[j] substr(w,i+1)]