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 / deep.purple.pl
Created February 6, 2013 23:19
How to list all Deep Purple albuns from spotify using Perl ?
use strict;
use warnings;
use English;
use JSON;
use LWP::Curl;
use URI::Escape;
use feature 'say';
use open qw<:std :utf8>;
my $search = "Deep Purple";
@peczenyj
peczenyj / gist:4697935
Last active December 12, 2015 02:18
perl version of each_cons + a small helper function "of"
use strict;
use warnings;
use English;
use feature 'say';
sub of { [ @_ ] }
sub each_cons(&$$) {
my ($code, $p, $array) = @ARG;
my $n = scalar @{$array};
@peczenyj
peczenyj / gist:4641638
Created January 26, 2013 10:45
Strange error in Perl 5.10 and OpenBSD
FAIL Lazy-Bool-0.04.1 v5.10.0 OpenBSD
...
PERL_DL_NONLAZY=1 /home/cpan/pit/thr/perl-5.10.0/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/Lazy-Bool-Cached.t ..
Dubious, test returned 29 (wstat 7424, 0x1d00)
Failed 11/11 subtests
# Failed test 'use Lazy::Bool::Cached;'
@peczenyj
peczenyj / bool.pl
Last active December 11, 2015 10:49
I want to do the same with ruby but it is impossible. only false and nil can be considered "false" values. it is hard coded in the source of the ruby.
package BooleanClass;
use Moose;
has 'bool_value' => (
is => 'ro',
isa => 'Bool'
);
use overload
'bool' => \&_to_bool;
@peczenyj
peczenyj / a.c
Created January 11, 2013 18:19
LOL
#include <stdio.h>
int main (int argc, char const *argv[])
{
int n;
printf("%s: %n ANA\n","hello", &n);
printf("%*s BOB\n", n, "");
return 0;
}
#!/bin/bash
#
# Piano Gripe 3.0 - The Shell Music #
# OBS: Favor nao confundir com axé music ##
# Natal-RN ###
# Autor: Pablo Fernandes (fernandes_pablo@yahoo.com.br) ---------- ####
# ---------------------------------------------- 28.10.2003 #####
# ######
#############################################################################
#
@peczenyj
peczenyj / codility_equi.pl
Created January 10, 2013 13:27
Codility task Equi, solution in perl with score 100 and O(n), see http://codility.com/demo/take-sample-test/
use strict;
use warnings;
use v5.10;
use List::Util qw(sum first);
sub equi {
my (@A) = @_;
my $right = sum(@A);
my $size = scalar @A;
@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)]
@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 / 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