viernes, 22 de mayo de 2009

Last week on 'Perl Programming'

Hey guys (and TIOBE :),

I'm going to paste a template for my new perl scripts I'm using lately. Well, I know I always should code as if it had to make into CPAN, but well... Sometimes you just don't need all the boilerplate.


#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper::Perltidy;
use Getopt::Long;
use Pod::Usage;

sub man {#{{{
pod2usage(
-exitval => 1,
-verbose => 2
);
}#}}}

# main
GetOptions (
'man' => \&man,
);

__END__#{{{

=head1 NAME


=head1 SEE ALSO


=head1 SYNOPSIS


=head1 DESCRIPTION

=head1 AUTHOR

Raimon Grau Cuscó

=head1 Credits

=cut

# vim: set tabstop=4 shiftwidth=4 foldmethod=marker : ###}}}




It's not anything awesome, but it just does the job. I saved it in ~/.vim/perl.template , and entered a map in vim like this
iab nperl :r ~/.vim/perl.template
However, if I have to write something longer than 100 lines, it goes through the proces of module starter or h2xs (the former is recommended now)

module-starter --module=Unix::RatFinder::IO --author="Raimon Grau" --email="raimonster@gmail.com" --builder=Module::Install
Some random things.

  • Rakudo now passes the 68% of the perl6 specs. yay!
  • I'll go to YAPC::EU::2009! YAY! (thx C.)
  • I'm working on a better Padre::Plugin::Vi a plugin for Padre or at least extending it with new commands. for the moment I've got a commit bit and implemented a couple commands. Yay!
  • Learning lots of things on ironman blogging contest

Cya!

jueves, 14 de mayo de 2009

Explore Io's internals

I haven't touched Io in some time, but about a month ago, I came with this piece of Io code, to explore the Io written methods in default Io installation.

For example, to explore Number blocks (all are written in Io, CFunctions aren't), you just have to type this in Io REPL.

Number slotNames foreach(i,
if(Number getSlot(i) type == "Block" ,
(i .. " -> " .. Number getSlot(i) code) println))

lunes, 11 de mayo de 2009

Farewell sir +f


A wise man, the greatest reverser and one (or two?) of the men who made a lot of reversing knowledge public, to us.

Back in late '90s, some of us started our intenet adventure, and we felt that all that information we had available wasn't enough. We scratched the surface and dug until we found a forest. Yeah, the old Searchlores Castle.

There were some of the smartest people around the techworld, publishing essays and documents about fishing. They not only told us how to get a fish, but made us want to know where fishes came from, and go there. Nevermind the obstacles. Everything is bit .

+HCU gave lots of reversing knowledge to us, poor crackers.

Then we understood the meaning of reversing and started to feel the code. We were starting to use the Zen way of approaching things. Not only reversing code, but reversing the code of life.

When internet was getting too much messy. He started a new project, related to the old forest and philosophy but in a more abstract way. It was about knowing you can get the knowledge. It's meta-knowledge. And this was impossible to cover it all. The field is not enormous (as in reversing) but infinite.

We've spent too many hours reading your smart texts (and probably missunderstanding most of your winks.

Unfortunately, you couldn't make it to 2032, and passed away last May 3rd, but there's plenty of people that will take your word to 2032 and more, and for sure, you can be satisfyed of having given the 'critical thinking' to many of us.

Happy reversing, wherever you are Mr. +fravia.

domingo, 10 de mayo de 2009

Lisp, scheme and live coding

I've been looking at some lisp books lately. When wise people I know talk about lisp, they only say great things about it. That's a clear sign of 'Hey, you should take a look at this, and see what you get from it'.

First, let's start with some books I've been reading/glancing (easy reads and hard ones are mixed, you'll have to find out which is which by yourself).

Warning: Lisp and Scheme are not the same language, but at my level, I just wanted to look at lispy codes, so I read everything I could.


Once we have a basic idea of lisp concepts, and we have already been striked by the "WOW! WTF! what's this?! Oh, ok, hahah! :) ", we can start typing some superlittle project, little bigger than 'hello world'.

Live Coding?


Two weeks ago, Jordi Delgado, in our weekly smalltalk meeting told me about post called 'hacking perl in nightclubs' and its scheme-like version 'Impromptu' . It's about coding in an environment where your code produces sounds or images (or both), and you evaluate the code you're writing at the moment. Unfortunately, impromptu is only available for Macs, so I kept looking for something that worked in my Vectorlinux. Then I discovered fluxus . I only had to build it and start hacking, and mixing scheme with music and graphical effects.

Compiling fluxus in Vector linux (and other Slackware derivatives)

Vectorlinux repositories are getting bigger and bigger, but they aren't big enough to have strange packages like those.

http://www.pawfal.org/fluxus/building/ shows how to compile fluxus and which dependencies it has. you'll have to install plt scheme (don't forget the --enable-shared flag).

Another package you'll have to tweak a bit is glew. In slackware, glut and glew can't be used by the same app, because of a macro redefinition in the codes. Here is an explanation of how to fix it .

Once you have it all. you're ready to start typing '(draw-cube)' lines and evaluating in a graphical environment.

This post is only meant to be a bunch of links to lisp and live coding projects. I hope you can compile it in vector linux. If there's something you want me to clarify, please, comment.

Cheers

viernes, 24 de abril de 2009

Fully vim style linux (part 2) - Vim for latex

Writing documents with latex with vim is fairly pleasant because you have your usual maps available, and you can configure most things with scripts but, as always, someone has already done that (don't reinvent the wheel).

latex-suite


Latex-suite is a great and very complete set of plugins for vim that helps writting faster latex with vim. It has lots of options and configuration bits, but you only need to remember a tiny set of shortcuts to use it (at least at a beginner level)

Environment complete (F5) . you're in a document and you want to insert a tabular environment. Just type 'tabular' and press F5. a full tabular environment will be placed right there, with the appropiate number of params and placeholders (you can navigate to the next placeholder with ctrl-j).

Package inserting (F5): in the preamble section, if you press F5 after typing a word, latex-suite will enclose it into a \usepackage{word}
snipMate

Compiling (ll) : to compile a document, just press your leaderkey followed by 'll' (that's two 'els').

View the compiled doc (lv): just type leader lv to open your viewer program with your dvi/pdf file in it.

There are lots of other useful things in latex-suite. you can find further info in its website.

LaTeX::Table

Tabulars can go from the simplest things to fairly complicate structures. Let there be perl.

There's a small module named LaTeX::Table that helps us to make pseudo ascii tables, and put some options embedded in a comment, and it converts them to fully functional tables.

Try cpan:

sudo cpan LaTex::Table
It uses Moose (a great modern OOP system for Perl 5), so if you don't use perl regularly, cpan will probably install a big bunch of perl modules.

If you have any problem installing those modules from cpan, you can always install them (or at least, the one that fails) with the good old method:

perl Makefile.PL, make, make install

Now a usage example.

theme=Berlin;caption_top=1;caption=foo
one & Two & Three
CAN I & haz a & CHEEZBURGER
& OH & KTHX
FOO & bar & Baz
Just visually select it and apply the !ltpretty filter. You're done

Latexhelp

With latexsuite, there is a latex reference in vim help format, so you can access the syntax of latex commands easily in vim. It doesn't need additional configuration, provided you placed the latex reference file in your doc/ directory and ran helptags on it. Probably :helptags ~/.vim/doc will do.

you can find the separate doc files here.

vim config

There are lots of possible configurations depending on your workflow and/or preferences. My configs are just theese lines.

let g:tex_flavor='latex'
let g:Tex_CompileRule_pdf = 'pdflatex -interaction=nonstopmode $*'

More things

As you probably know, learning to use vim effectively has many paths to go, and what is useful for me, can be painful for you. You can combine plenty of other vim plugins to help you writting faster latex.

For example, using snippetsEmu/snipMate/whatever snippets plugin can be useful, using supertab can speed up your (general) writting, or even little maps like the ones explained in my previous post 'Fully vim style linux (part 1)' can enhance your typing experience.

Please post comments about comments/improvements, and I'll make the appropiate updates.

See ya in the next post.

little update

4 days after my first perl6 script. It's already outdated. You see, rakudo is a fast moving target.

Last thursday, parrot 1.1 was out, and it comes with lots of changes compared to parrot 1.0.

One of the strange syntax present in my last script, was a line like:
while my $tat = =$*IN { ... }

In that case, the first = is the well known assignation, and the second = was a prefix operator, that took the next element of the list that was preceeding.

= as a prefix operator has been deprecated in favour of '.get' function .

so that code, now would be like


#!/tmp/rakudo/perl6

sub printa_rusc($f, $c){

my $first = ' - ' x $c ;
$first.chop.say; #chop is non

my $top_line = '/ \_' x $c;
my $bottom_line = '\_/ ' x $c;

for 1..$f {
$top_line.chop.say;
$bottom_line.chop.say;
}
}

while my $tat = $*IN.get {
my @arr=$tat.split(/\s+/);
@arr.perl.say;
if 2==@arr.elems {
printa_rusc(@arr[0], @arr[1]); #not $arr[0]
} else {
"Bad format. Enter only 2 integers".say;
}
}

# vim: set tabstop=4 shiftwidth=4 foldmethod=marker ft=perl: ##
Nothing else for the moment

lunes, 20 de abril de 2009

My first perl6 dabblings

It's been a month since parrot 1.0 and now , rakudo is passing more than 3000 tests than then. It's an amazing progress IMHO.

I just started to write very simple scripts to get the feeling of perl6. This is my first one.

A script that gets 2 integers per row, and then prints a honeycomb of the given size (rows x cols)

it's a really simple script, but at least it gives little hints of how functions are called, strings printed, and STDIO read.


#!/tmp/rakudo/perl6

sub printa_rusc($f, $c){

my $first = ' - ' x $c ;
$first.chop.say; #chop is non destructive

my $top_line = '/ \_' x $c;
my $bottom_line = '\_/ ' x $c;

for 1..$f {
$top_line.chop.say;
$bottom_line.chop.say;
}
}

while my $tat = =$*IN {
my @arr=$tat.split(/\s+/);
@arr.perl.say;
if 2==@arr.elems {
printa_rusc(@arr[0], @arr[1]); #not $arr[0]
} else {
"Bad format. Enter only 2 integers".say;
}
}

# vim: set tabstop=4 shiftwidth=4 foldmethod=marker ft=perl: ##

We can see some strange things if we're used to perl5.

First the @arr[0] thing. In perl6, sigils are part of the symbol, so the @rray @arr will always be acessed as @arr[1], @arr[1..10] ,... it happens the same with %ashes .

chop is not destructive, meaning that returns a copy of what was choped, but it doesn't modify the given argument.

We see something like @arr.perl.say . As you probably know, .say is the method to print things followed by a "\n". print "hi", "\n" ; is the same as say "hi"; or "hi".say; .

For the moment there's not much more to say.

See the rakudo's progress at http://www.rakudo.org/status . today 23/04/09

To get rakudo, it's pretty easy: (from rakudo.org site)

$ git clone git://github.com/rakudo/rakudo.git

If you don't have git installed, you can get a tarball or zip of Rakudo from github by visiting http://github.com/rakudo/rakudo/tree/master and clicking "Download". Then unpack the tarball or zip.

Once you have a copy of Rakudo, build it as follows:

$ cd rakudo
$ perl Configure.pl --gen-parrot
$ make



That's all!

Thanks to parrot and rakudo devs for this new version of our favourite language