fREWdiculous!
9 Mar
Hello everyone!
Hopefully you know that today (March 9-10, starting and ending at sundown) is the holiday of Purim!
I just want to mention that the best way to celebrate Purim (we did this at school) is to read the entirety of the book of Esther out loud, cheering for Mordecai (or Esther, but not both,) and booing at Haman, and each time you cheer or boo, you take a drink. At school we used non alcoholic sangria, which I think was worse than what wine or beer would have been because of all the sugar and carbonation.
Anyway, celebrate!
9 Mar
I just posted a workflow for Git on the Rakudo Wiki. Hopefully it works well and helps people use Git and work on Rakudo. Enjoy!
7 Mar
I like to make playlists. But I also reorganize my music something like once or twice a year. Because of that my playlists get broken as they are really just lists of filenames. This past summer I wrote some code in ruby that would find files with the same basename but ignore the directory structure, and reconstruct playlists from that. It worked perfectly except every now and then I would get a live version or two. This works because I have an sqlite database of all of my music thanks to amaroK.
Well, I decided that I would update the script so that I wouldn’t have those issues with live versions. I decided that I would have an intermediate filetype, which I would basically keep around forever. Announcing the FRU media playlist filetype! Actually not that exciting. Anyway, here are a couple scripts:
m3u2fru.pl6:
fru2m3u.pl6:
But the more important part, is the Ghetto module. Currently rakudo does not have any way to get the output of a command, but it can read from files, so we can fake it:
Obviously this is slow, bad in that it could possibly overwrite files, etc. It’s ghetto. But the idea is that later when we actually can do something like this without a ghetto solution it won’t be hard to fix your code.
I also thought it was fun to do a pipe-based solution. The way I had it set up before was something like this:
1 | ./plup.rb old.m3u new.m3u |
That’s alright, but I would usually look at the output to make sure it was right. Now I do this:
1 | cat old.m3u | ./m3u2fru.pl6 | ./fru2m3u.pl6 > new.m3u |
Sure it’s longer, but I can easily see the output at any point in the process. Furthermore, since I am using zsh (maybe bash can do this too, not sure) I can do this:
1 | cat old.m3u | ./m3u2fru.pl6 >new.fru | ./fru2m3u.pl6 > new.m3u |
So I can keep the intermediate results for next time!
6 Mar
Did you do a reduce and get confused about how it got the final answer? Do you just want to see the computer write out it’s work? Check it:
1 2 3 4 5 6 7 8 9 10 11 12 | (1,2,3).reduce({ $^a / $^b }) RESULT«0.166666666666667» (1,2,3).reduce({"($^a / $^b)"}) RESULT«"((1 / 2) / 3)"» (1,2,3).reduce({ $^b / $^a }) RESULT«1.5» (1,2,3).reduce({"($^b / $^a)"}) RESULT«"((3 / 2) / 1)"» |
How cool is that?
6 Mar
You may have wondered why I had the slight delay in posts this week. I had a good reason: we switched one of our major products from IIS to Apache! In general it was a fairly painless process. The details are documented in my previous post, Migrating from IIS to Apache. There was one hitch though…
We have an autocomplete field that needs to be pretty snappy. For IIS we just installed ActivePerl and named the file autocomplete.plex and it was good. Well, mod_perl isn’t quite so easy; we had a couple major snags.
For some reason we had a lot of issues trying to get mod_perl working with ActivePerl 5.8. I initially wanted to leave it at 5.8 because of various modules that were already installed and couldn’t easily be upgraded. I eventually decided to bite the bullet and install 5.10 and update the modules.
After installing Apache (see previous post) and ActivePerl 5.10 (plus lots of modules) we had to install mod_perl, which was surprisingly easy:
1 | ppm install http://cpan.uwinnipeg.ca/PPMPackages/10xx/mod_perl.ppd |
After that I had to add to the configuration for Apache:
1 2 3 4 5 6 7 8 | LoadModule perl_module modules/mod_perl.so LoadFile "C:/Perl/bin/perl510.dll" <Location /foo/autocomplete/perl> SetHandler perl-script PerlResponseHandler ModPerl::Registry Options +ExecCGI </Location> |
Since we were only converting that one script we limited mod_perl to that single directory.
The last issue that we had was that you cannot use CGI.pm with mod_perl; fortunately for us in this file all we were using it for was to print a header, and mod_perl does that for you by default, so we just commented out those lines. At some point I’ll need to do some more research and learn the mod_perl way to get params and print headers.
In general it was pretty nice. We now have a much more stable configuration and mod_perl is extremely fast. The autocompleter went around ten times faster (60~ms total afterwards) after switching. I didn’t get a persistent DBI connection set up, but I did put all of the use directives in the BEGIN block.
If anyone has pointers on persistent DBI connections, a way to only set mod_perl for a single file extension, or whatever the mod_perl replacement is for CGI.pm, let me know!
6 Mar
Tallahassee is the album of the week. This was the first of the higher quality albums put out by The Mountain Goats. If I were to describe The Mountain Goats concisely I would probably say they are depressing, prolific, and well-read.
I think the lyrics of this band really need to be put at the front stage, so check out these samples:
From Southwood Plantation Road:
All night long you giggle and scream
Your brown eyes deeper than a dream
I am not going to lose you
We are going to stay married
In this house like a Louisiana graveyard
Where nothing stays buried
On Southwood Plantation Road
Where the dead will walk again
Put on their Sunday best
And go with unsuspecting Christian men
La la la la la
And from the classic No Children:
I hope that our few remaining friends
Give up on trying to save us
I hope we come up with a failsafe plot
To piss off the dumb few that forgave us
I hope the fences we mended
Fall down beneath their own weight
And I hope we hang on past the last exit
I hope it’s already too late
And I hope the junkyard a few blocks from here
Someday burns down
And I hope the rising black smoke carries me far away
And I never come back to this town
Again in my life
I hope I lie
And tell everyone you were a good wife
And I hope you die
I hope we both die
Notice a theme? That goes through almost all of the albums by The Mountain Goats. This album is actually entirely about “the alpha couple” but other albums have them too, except in those albums the song title starts with “Alpha.”
My favorites on this album are: Southwood Plantation Road, No Children, Peacocks, See America Right, and Oceanographer’s Choice.
Colors: Brown, Tan.
4 Mar
Ok, so when I was in school, I trained some guys on perl (and other things) over the summer via email. I decided to resurrect the tutorials so more people could use them. The idea is that they are good for programmers because they don’t explain the basics of what arrays are etc. Anyway, hope someone digs it! Perl Tutorial 1. Have fun!
3 Mar
I post on forums and mailing lists fairly often, and when I copy and paste code I tend to shift all the code to the left 6 or more characters so that the forum won’t see unnecessary indentions. Well, today I found the solution: blockwise selection. To do this in vim you will just type Ctrl-V and you are in blockwise selection mode.
You also probably want to do a :set virtualedit=block so that you can highlight characters that don’t exist.
Anyway, it’s nice because instead of highlighting lines it highlights a square, so you just start at the beginning line and all indents are removed like magic!
3 Mar
Apparently Patrick Michaud, pumpking of rakudo, read my post yesterday and he came up with an even better solition!
I’d read his post if I were you, but here was the code he got it down to (after adding the R meta op
):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | my %op_dispatch_table = { '+' => { .push(.pop + .pop) }, '-' => { .push(.pop R- .pop) }, '*' => { .push(.pop * .pop) }, '/' => { .push(.pop R/ .pop) }, 'sqrt' => { .push(.pop.sqrt) }, }; sub evaluate (%odt, $expr) { my @stack; my @tokens = $expr.split(/\s+/); for @tokens { when /\d+/ { @stack.push($_); } when ?%odt{$_} { %odt{$_}(@stack); } default { die "Unrecognized token '$_'; aborting"; } } @stack.pop; } say "Result: { evaluate(%op_dispatch_table, @*ARGS[0]) }"; |
Brilliant!
3 Mar
Jeff Atwood claims that comments are a required ingredient for a blog. How true! There have been some comments recently on my original post about an interactive perl shell. My post mostly centered around writing one liners with your regular shell.
Well, brunov replied and mentioned Devel::REPL, which is excellent! It has all kinds of great features and really does everything that you would expect a modern language shell to do. It’s a surprising hassle to get to work with ActiveState perl in windows, but in Linux it works like a charm!
G briefly mentioned perl -de0, which is alright, if you want something out of the box, but if given a choice between perl -de0 and perl -E, I’d choose the latter, as at the very least I get the latest 5.10 features that way. Unless I missed something you can’t even do things on multiple lines in perl -de0. But I’m sure plenty of people dig it.
Anyway, hope that helps someone!