viernes, 27 de noviembre de 2009

Mastermind setter (scheme) and flibug meeting

Mastermind setter
Last week, I couldn't work on the mastermind solver, but at least, I finished the setter.

It was a good exercice to get in touch with scheme IO, like getting input from user, split strings, and the like.

I finally removed all the functions for IO, because I can supply the inputs as lists on the REPL. I've used drscheme, but as this week I also tried guile (embeding it in a c app. Pretty cool), I might try it for future hacks.
(check-sols '(1 2) '(1 3))

I'm quite excited about how easy it became to do it, and this weekend I'll spend some time on the solver.

flibug
On the other side, this tuesday we had another flibug meeting at oblong. Amazing, as always:
  • Aleix Conchillo made a live presentation about plt slideshow. A module to create slides using scheme. Given that I had invested some time to find a good slides maker and not finding it, this might be a good solution to study further.
  • Andy Wingo showed us a demo of the greatest technology I've seen in many many many (sorry) months. When I arrived home I said "Papa,mama, I'm back from the future".
  • Colin Fleming made a good (also with live demos) presentation about IntelliJ refactoring tools, and he expressed his feeling of the need for clever programing environments. It's impressive how an IDE parses your code, and how much it knows about good/bad practices and hints you with improvements. He started coding a scheme mode for this IDE that already managed some refactorings like var renaming. As editors are a religion matter, some of the assistants had a few doubts of the real benefits of using a 'cool' boxed IDE (although extensible) versus using a swissknife-and-the-kitchen-sink emacs. On my part, being a vim user for 4 years and just starting to dip in emacs, I'll follow this thread really close.
I'd like to thank all the flibuggers and oblong for sharing all that coolness. I wish I could share more with them giving something back (with a presentation). Maybe when I finish my degree project I can prepare something about stumpwm or fluxus.

I'd say it's been a pretty exciting scheme-y week.

miércoles, 25 de noviembre de 2009

lightweight window managers part 1

This is a post (maybe the start of a series of posts) that I was willing to do for some time.

It's related to light window managers. Those wm that do not have lots of dependencies, and that are quite well thought and let you get your job done in a fast and zen-y way.

They usually are a bit hard to get used to (for a wide range values of 'a bit'), but if you try them for some time, you can get hooked to them.

Most of them are made with programmers/geeks in mind, so if you don't feel like programming a bit to configure your wm, or editing a configuration file makes you cringe, you can definately skip this post.

Tiling vs non-tiling
If you don't know what are tiling window managers, it's probable that I won't convince you in this post, but anyway... When I started trying wm as crazy and say tiling window managers for the first time, I thought: "WTF?! I've lost my 'window' feeling" . It didn't convice me because your're too used to have to arrange windows by hand, so not being able to do it by yourself (at least with drag-n-drop) can make you feel caged. Just let time go by, and keep trying one of them from time to time, until you'll see they make you more productive.

Ratpoison wm

Ratpoison is the window manager I've been using for the last 4 years (more or less). It's the most minimalist one I've seen, and due to it's screen-ish keybindings, I just feel@home with it. It has no dependencies besides X, and the compiled binary is 116kb . ratpoison++;

It's a 100% tiling wm. with no window decorations, no menus, no icons, no nothing. It doesn't have a floating layer neither, so if you open multiwindow programs, like Gimp, you'll be probably srcewed until you know how to manage it. My recomendation for gimp is using Xnest and open gimp in a suboptimal wm. Another option is to use ratpoison's tmpwm command, that executes a wm temporally, and when you exit it, you're at your ratpoison home, with your session intact.

Basic usage of ratpoison is the same as GNU screen (click here for a chat-tutorial I did some years ago. Sorry for the bad formatting), but changing c-a for c-t (obviously, you can configure it). So ctrl-t c will open a new terminal, c-t n will show next window in the current frame.... just see 'man ratpoison', or type c-t :help, or info ratpoison.

Configuration
Configuring ratpoison is really easy (well, depending on your estimation for 'really easy').
You can fill your ~/.ratpoisonrc with as many commands as you want, in the same way you'd type them in the ratpoison prompt (when you press c-t : ).

One really nice thing is that you can send commands to ratpoison through the command line.

For example, when you're on it, open a terminal, and just type:
ratpoison -c "split"
Then your running wm will receive the split command, and execute that.

Imagine all the nice things you can do with it :). In your favourite programming/scripting language. :D . system("ratpoison -c 'echo ratpoison rulez' ");

It has also multiscreen support (not as good as I'd like but...).

Now a screenshot of my splitted screen, (although there's really nothing to see):


Ah, and some more screenshots and configs here.
That's all for now. Next to come (in no particular order):
awesome wm, stumpwm and evilwm.

Cya.

lunes, 23 de noviembre de 2009

El listillismo

Pocas cosas me joden tanto como los seguidores del 'listillismo'.

Son aquellas personas que aceptan decir chorradas, a cambio de chorradas. Porque tu tiempo no vale un duro. Y el suyo? Bueno, ellos se dedican a esto.

Que a veces yo estoy ahí, y me siento muy bien. Como oliendo nubes, como en un globo. Un rato rajando sin conocer, y sin interestarte. Pero no me jodas. Llega un punto, que ya dices basta, y te toca enfrentarte a los listillos profesionales, o callar y "morir un poco más por dentro".

Y mientrastanto buscas miradas cómplices en un vagón del metro. Eres como una letra A en la sopa. Buscando otras letras que se apunten a formar una palabra. Ya veremos cual, pero que jueguen. Con una B y una R, yo ya me conformo.

Aunque reconozco que no siempre apetece jugar. Que a veces se te acaban las ganas, y a mí se me han acabado, pero una y otra vez, cuando veo gente con ganas de CANT.R , o ganas de .PRENDER, o simplemente GAN.S, no me resisto. Porque un día, me ayudarán a escribir alguna palabra que ahora mismo no puedo ni pensar, pero que sería imposible sin ellas. O quizás evitaran mi suicidio, o quizas lo provocarán. Pero la cuestión es jug.r.

sábado, 21 de noviembre de 2009

Mastermind in scheme

3 Days ago I read a post on programming praxis blog about writing a mastermind
game. The author splitted the game in two parts, the first
being the setter
, so given a known solution, and a guess, returns a string
of B/W/.

The point is that when I tried to code it, I was in an internetless bar, so I
had to guess some parts of the exercise and I missunderstod some of the points
and the code didn't work as expected (but at least, I succeeded to make it work
as I thought it had to work)

When looking the solution proposed at programming praxis, I payed attention to
both the algorithm used, and the code.

The algorithm used is works calculating white pegs, and then substract black
pegs. Finally, it sorts the black and white pegs and prints the output.

I'll try to write my own version in near future, but, for the moment, I have
updated the perl Mastermind code I started some time ago, that until now, it only compared the solution to the given combination, and returned a good/bad value. Now it uses that algo to tell how accurated is your guess. It's still far from functional, (it only plays random (with or without repetitions (using a cache))), but I have little time to hack on those projects.

I will have to take a look at the programming praxis "standard prelude", where the author shows some generic functions that are used over his solutions.

Btw, Programming Praxis has been one of my last findings on the intertubez. A great find IMHO.

viernes, 20 de noviembre de 2009

Implement a scheme intepreter in X

It might be just a strange coincidence, but lately, every week I discover a new book/tutorial that guides you through writing a scheme interpreter in whatever language I look.

Theres's SICP , implementing scheme in scheme

Theres PLAI , implementing a variant of scheme in a variant of scheme

Also, there's "Exploring programming language architecture in Perl". A book that covers the implementation of a scheme interpreter in perl.

And now here's a new kid in the block I just discovered. Implementing a simple scheme interpreter in haskell. I'll leave it here, and see if I have some time in the near future to read it (I doubt I implement it as I know nearly no haskell)

So many good books to read and so little time and attention span....well, there's still hope on SICP and EPLAiP.

lunes, 16 de noviembre de 2009

Implementing list functions in scheme

I've been messing a bit with scheme lately, and one thing I want to get well is list mangling. As you know, lists are the most basic and pure datastructure in scheme (and I think they are the only true datastructure in scheme).

This is why I want to get them right, and I'm rewriting some basic functions related to lists.

First of all, a little explanation of lisp lists in general.

Lists are based on a more simple structure called "cons". A cons is just a pair. The only thing that can contain a cons in the first (car) or the second (cdr) cell are:
  • string
  • number
  • symbol
  • cons
Yeah, pretty simple, right? The funny thing is that with cons containing conses, we can write all kind of datastructures.

First we'll see two axioms that must always be true related to conses.

(= x (car (cons x y)))
(= y (cdr (cons x y)))

Everything that guarantees this is a cons. Well, at least at this level...

a cons is represented by (x . y) , and a cons with another cons in the cdr would be (x . ( y . z))

A list is a special kind of cons with a determined structure.

( x . (y . (z . nil))) . A way to visually simplify this is ( x y z ) . That means that in a list of n elements, there are n conses linked through cdr's, with the last cdr pointing to nil. If you had to build (1 2 3) with conses, you could do it with (cons 1 (cons 2 (cons 3 nil))) .

Here I show the few scheme functions I wrote along with some explanations that davazp kindly gave me at #emacs-es and #lisp-es.

Theese are my first versions of some functions.




Here we see build-list can be abstracted to a more general (and easier to write) procedure called build-range, and I just call it with a start point = 1.

On the reverse function, we can use a different "happy idea".



Enough for today. Thanks to davazp and other #emacs-es -ers for their help and motivation.

sábado, 14 de noviembre de 2009

VL 6.0 KDE Classic Review

Vectorlinux team has released another version of this beautiful distro.

This release is a kind of tribute to kde 3.* , as it's the last vl with kde 3 bundled in it. Next versions (6.0 SOHO is already in beta) will come with kde 4, so this one is for those who want rock stable and well known kde 3.5.10.

Installing Vectorlinux
As this version still uses the "old" text installer (a new one is in the oven atm), I could boot and install the iso without having to burn a CD using vinstall-iso

sh ./vinstall-iso VL6.0-KDE-Classic.iso

And let the fun start!

The process went flawlessly. I was surprised how few options I had to install extra packages. Well, sensible defaults are ok for me.

To manage usb and CD units user can choose between the resource hog (but well tested and known worldwide) HAL and quick (and VL idiosyncratic) VL-HOT. The default is HAL, but I changed it to VL-HOT.

Since running the iso till I restarted to my new VL-kde only passed 9 minutes. Yes, only nine minutes. In the first boot, I was asked some other questions and a new reboot was required. Then I already booted to a full KDM screen.

After the first tests, everything worked fine: Sound, graphics (I installed propietary ati drivers from their page, and I already have my dualscreen setup), and all the basic things I could test.

Software selection


Vectorlinux has always come with a sensible selection of software, and most of it is already configured to "just work". For example, firefox(3.5.3) comes with flash plugin, pdf plugin, java plugin, etc... Konqueror is also installed (it's a kde distro, remember?)

For IM we have pidgin and Kopete, and KSirc to irc.

Koffice with a whole lotta apps is there, from creating spreadsheets to flowcharts. Lots of apps.

It comes with lots of dev tools by default (g++, gcc, make) and interpreters like perl (5.10.0), python (2.5) and even ruby (1.8.6).

Performance

That's the main reason I like/use Vectorlinux. It's among the fastest linux distros. And it's pretty easy to install. Here's a screenshot of vl running kde, with a couple of terms and ksirc. Click the image for a larger sample.


More Software

Although the VL team selected very good apps to go into VL-kde, I *want* my desired apps NOW!. No problem at all.

I just had to edit (as root) /etc/slapt-get/slapt-getrc and uncomment the testing line from

#DISABLED=....
to
SOURCE=.....

After that, "slapt-get --update" and then, installing all my favourite software was trivial:

"slapt-get -i zsh screen vim-gvim emacs ...."

In no more than 30 minutes, I CAN HAS a workin environment with KDE 3.5.10.


Conclusion


In so little time, I can hardly make a conclusion about it, but knowing the average quality of Vectorlinux releases, and having tested it a bit, I think I can recommend it to people with a little linux knowledge (installer is in text mode, but it's really easy to follow) who want a fast distro to be used in browsing / office or, on the other side, as a developement platform I'd recommend to people who do not want to mess too much with the inners of linux
(it's not arch) but want to learn in a standard platform, that does not hides anything about pure slackware (so pure GNU/linux), and want to learn little by little (it's not ubuntu).

Personally, being a more minimalistic person, I'll stay with vl-std and vl-light, but this release is one I'd recomend to my non-so-techy friends.

There's only a way to see if it fits you. Try it and see. Make (good) use of vl community in case of trouble. It'll positively surprise you.

viernes, 13 de noviembre de 2009

Self modifying bash script

Last month, my ten years old lappy said enough. Well, it can boot, but it doesn't get the plug correctly, so it has to stay pretty static. It came with windows 98 installed, and I've done most of my uni tasks there, as well as installing tenths of linux distros (until vectolinux).

While moving files from its HD to a safer place, I found a bash script (works on zsh too) I did about 5 years ago, which emulated a 'mute' function, and could be called through a shell (or through xbindkeys / keylaunch / ratpoison binds).

The funny thing about it is that it modifies itself to remember the last volume that was set, to restore it afterwards.

I know it could be done using a file to store the previous volume value (and in fact, I use a trick of the same kind), but well, I liked to see that trick again. It uses sed to substitute a variable that is later tested if it's 0. Pretty easy stuff.

It makes me remember my first questions about self modifying code. Now, with lisp and smalltalk, living in a life environment, everything is clearer (sure?).

Comments and improvements are obviously welcome. Enlighten me!

miércoles, 11 de noviembre de 2009

using Vim regexes everywhere

I'm at class atm, and 5 minutes ago I had to download some exams from past years.

There are quite a lot of them, and I just thought downloading them all by hand would be too much work for a Lazy man like me.

Then I used vim to help me :)

I just got the code where there were the links I wanted. It looked more or less like this:


<a href="2006t-c-40-lc.pdf">g40</a>,
<a href="2006t-c-40-lc-s-test.pdf"> solució del test</a>;
<a href="2006t-c-50-dc-test+problema.pdf">g50</a>,
<a href="2006t-c-50-dc-test_resuelto.pdf"> solució del test</a>,


Just open vim, paste the code and let the magic begin.


:%s:href=":http\://studies.ac.upc.edu/FIB/XC/:
:%s:.*http:http:
:%s:".*::
:%s:^:wget :
:w /tmp/downThemAll.sh


Now you just have to execute the script, and enjoy :)


Btw, yeah, I know about downThemAll, but I like using my own tools (and I dislike bloat).

domingo, 8 de noviembre de 2009

Mi carro

Aveces voy por la calle y veo un zapato solo, tirado. Yo siempre me pregunto por la historia que tendrá el zapato, lo que habrá recorrido, los años que llevará viajando, y en qué situación alguien puede "perder" un solo zapato.

Qué habrá sido del otro? Corrió mejor suerte?

Pues bien, ayer, volviendo a casa (4:00 AM), andando de noche a buscar mi coche, cuando veo en la calle un zapato. Me lo quedé mirando con descaro, a medida que lo iba alcanzando, y mientras lo adelantaba, pues lo mismo: "¿quien cojones pierde un zapato, con el frio que hace...?".

Cuando ya no podia torcer más el cuello, miro al frente, y a lo lejos, en la acera por la que andaba yo, en la escena estática de la calle a las 4 de la madrugada, veo que hay algo en el suelo. Parece un chaqueta. A medida que me voy acercando, la voy mirando fijamente, examinandola con la vista, haciendole un tercer grado, queriendo descubrir detalles de sus tiempos pasados. Al llegar al bulto, le dí una patada para levantarla del suelo, y entonces vi que eran unos pantalones. Los pantalones se quedaron otra vez en el suelo, muertos, y me los miro otra vez fijamente, parado yo a su lado. Ostia, unos pantalones... los sigo mirando, buscando detalles en ellos, y cada vez que me fijaba, habia algo que los hacia familiares. Cuando ví que estaban rotos de una rodilla dije "mierda, son mios".

Los agarré con la mano, y efectivamente vi que eran los mios. Miro al frente, y veo más ropa en el suelo, y otra pieza más un poco más adelante. Entonces me viene instantaneamente a la cabeza mi coche. ¿Estará donde lo dejé? , ¿Cuantos cristales estarán rotos? ¿Tenia cosas de valor?. Pues resulta que llego al coche, y esta todo revuelto, pero no se hab llevado nada.

Ni la luna rota, ni nada. Mu profesionales. Bueno, pues claro, ordeno el coche otra vez, encuentro teletac, papeles, monedas... No sé qué pretendían encontrar en un coche de 15 años pero creo que no lo encontraron. Entonces me viene a la cabeza el zapato. Sería mío? Voy a ver, y efectivamente, el zapato es mio. Ya conozco su historia. Comprado en Tenerife hace 2 años. La conocía desde el primer momento.

El otro zapato no apareció, o sea que ahora mismo, hay un zapato huérfano, despertando curiosidades de otros peatones. Y és mio. O lo era.

jueves, 5 de noviembre de 2009

practical Perl 5 match operator

Here I am again, with some reminders about a few practical things I (and maybe you) should have in mind when doing pattern matching in perl. I'll mainly talk about retrieving results in matches, and the context things.

So I won't talk about the pattern part.

The match operator is called with the m/OHAI/ pattern, or just /OHAI/ . if you don't specify something to match against, perl will use our good friend $_ , so when you iterate through a file, you are probably ok with this convention:


my $yay;
while(<>){
$yay = $_ if /say/ ;
}
print $yay;



Sometimes we don't want to match against $_, and we'd like to parse another var. That's ok, we use the =~ operator, which tells 'm' the variable to do the match with. But there is where I get somewhat puzzled sometimes, because if I want to assign the match to a var, you have to chain it

$match = $string =~ /yay/;

And that doesn't do what we usually want.

I've written this little test script to help me remember how to do proper matchings, and get the info I want from them.

martes, 3 de noviembre de 2009

Test

Cuando una noche te pasa tan rapido, que pierdes la nocion del tiempo, y a las 6 te gustaría volver a empezarla:


a) Has bebido como un cosaco.
b) Te has puesto como un chamán.
c) Te has reído como nunca.
d) Has compartido momentos únicos.
e) Todas las anteriores son correctas.

lunes, 2 de noviembre de 2009

Eficient implementation of Tail recursion in Perl 5



I'm getting more and more interested in fringe programming languages (some of them are use the functional paradigm).

I'm no pro by any means, but little by little, I think I'm starting to grasp what's all that about, and I understand small new tricks every now and then.

In the YAPC::EU::2009, there was a loooooong discussion while we were having dinner about tail recursion, the minimizing of stack space and so.

Until this week, in perl 5, you could emulate tail recursion optimization by implementing it manually in the place where you want the optimisation. An explanation of "HOW" can be found in chapter 13 of "Exploring Programming Language Architecture in Perl" (EPLAiP from now on) , when the author explains how you could implement a sort of CPS in perl.

Well, last week,
Yuval Kogman (a great perl hacker with *LOTS* of useful modules) released Sub::Call::Tail , a Perl 5 module that allows you to call a function and make perl optimize the stack usage. For a brief usage howto, you can visit Yuval's post.

Today, I see in another of his blog posts he just created Sub::Call::Recur , a kind of curried version of Sub::Call::Tail, that just loops over the current sub. As he sais, it's a kind of redo but for functions instead of blocks. The resulting code is quite optimized (nearly as fast as plain iteration), so we can say perl5 has now tail recursion optimization. nothingmuch++;

Byez!

UPDATE:
Seeing http://ezrakilty.net/research/2009/11/function_calls_are_not_stack_frames.html I think I might review the post.... sorry for my ignorance :(

domingo, 1 de noviembre de 2009

DrScheme halloween easter egg

Yesterday I was about to try some scheme code from HtDP, and when I ran drscheme, I was presented a different splash screen from the one I used to:

Well, that's all for now. In a few days I'll post about what I was trying (if I find the time)

Happy halloween hacking.