March 2nd, 2010
Here’s a very simple one-liner REPL for perl, it’s not very advanced (like ie. re.pl) but does well in most cases:
perl -MData::Dumper -MTerm::ReadLine -e '$r = Term::ReadLine->new(1);while(defined($_ = $r->readline("code: "))){$ret=Dumper(eval($_));$err=$@;if($err ne ""){print $err;}else{print $ret;}}'
It uses Term::ReadLine, which gives a simple session history if you have a Term::ReadLine::* implementation that supports it. It will also use Data::Dumper so that you can quickly see any data structures, you can always use scalar(STATEMENT) if the return value differs in list and scalar context.
Here’s an alias that can be shoved into .bashrc :
alias 'perl-repl'='perl -MData::Dumper -MTerm::ReadLine -e '\''$r = Term::ReadLine->new(1);while(defined($_ = $r->readline("code: "))){$ret=Dumper(eval($_));$err=$@;if($err ne ""){print $err;}else{print $ret;}}'\'''
Posted in Random | No Comments »
October 15th, 2009
About two weeks back I released SWEC version 0.4. The largest new thing in this release is an updated file format for writing test definitions. Thew new format is a lot more flexible, and will also allow me to extend its syntax with more capabilities more easily later on. It can still read the old file format, and I’ll keep the compat code in there until SWEC 0.6 – so people have time to update their files (only minor changes are needed to update them to the new file format, should only take a couple of minutes).
Other than that I extended the command-line parser, so you can now say “swec example.com -s /test.html” where you would previously have had to do “swec --baseurl example.com -s /test.html“. Other than that it’s mostly a bunch of cleanups, some refactoring and a few minor bugfixes, in addition to a new test suite so the thing can be properly sanity-checked before release.
If you need to sanity check dynamic websites, give SWEC a go.
Posted in SWEC, perl | 1 Comment »
October 14th, 2009
I prefer writing in Perl or Ruby, but sometimes the choice of language has been made by someone else, a position I have found myself in lately. When using perl and ruby, there’s always perldoc and ri, so documentation is a quick command away in any of my terminals, which thanks to screen is never fewer than ten. PHP however, has no such tool, the docs are in HTML and many distros don’t even package the HTML docs. So, to avoid the pain of switching out of the safety of my terminal and into a web browser all the time, and speed up my work, I wrote an app, phpdocr. It’s quite simple, it scrapes php.net (and caches the result for quick viewing later) and displays the parsed HTML in your pager – resulting in something sort of like perldoc or ri. So if you have the same itch, grab it from http://random.zerodogg.org/phpdocr.
The app itself, of course, is not written in PHP – it’s written in ruby.
Posted in Random, Ruby | 1 Comment »
October 13th, 2009
I have found myself doing quite a bit of mason at work lately, both maintaining old legacy stuff and as the view in a catalyst app.
While doing this I found myself missing the old ‘perl -c’ to quickly sanity check code, however naturally that won’t work on Mason – as mason is essentially HTML with inline perl, not the other way around. As such I wrote a quick script that emulates ‘perl -c’ by loading the file using mason inside eval then printing any errors. The script itself is pretty simple, though it doesn’t have any support for printing useful line numbers – but at least it gives an idea of what/where the problem is. The script also declares $c and $m, as at least for Catalyst – those will be available.
You can clone the gist, or just copy+paste the code:
Posted in Random | 2 Comments »
October 12th, 2009
I have to admit, I love git. It has really made me more efficient, and I can’t honestly think of ever switching back to ie. svn.
My shell is bash, and up until now I used a very simple bash completion for git, but at times I do see myself wanting something a bit more comprehensive. However, I really don’t want bash to be slow to open (of course, the definition of “slow” is quite individual – over a second is way too much ;), which it can be if it needs to load all bash completion definitions when starting. Therefore I wrote a small bash function for my .bashrc that will dynamically load the git bash completion when it first is accessed. Bash starts fast, and I get git bash completion – problem solved (well, the first time git bash completion is used, it of course takes a tad longer than normal because it needs to load it first, but that’s completely livable). As a bonus, it will fall back to my old and simple completion if the proper one is not available.
Here’s the code snippet:
Tags: bash, bash completion, git
Posted in Random, git | 3 Comments »
September 10th, 2009
Disclaimer: This is a political post. If you’re not interested in politics (or not interested in Norwegian politics), please ignore it.
The date for the Norwegian general election is closing up fast, and I would like to urge my readers to vote for the Socialist Left Party (SV). The last chance to vote before the actual election day is, in many municipalities, tomorrow, the 11th of September. The actual election day is the 14th of September. Remember that every single vote counts!
We don’t need any dark blue experiment with our economy, healthcare or our children. We need a fairer government that works for equality, that takes the climate changes seriously and are prepared to act now rather than later, when it’s too late. We need a country where women earns the same as men, not merely 85% (avg.) of what a man makes and we need to treat everyone with the same amount of respect.
The economic crisis has shown us how bad it can get when we allow as much market freedom as we do. There are a few select people that gamble away at the stock market, keeping any earnings for themselves while socializing the problem if they experience losses. Norway has, largely thanks to SV’s socialist finance minister, managed the financial crisis very well. We need a market that is more controlled, not less! We can not allow capitalists to gamble away our jobs, nor can we allow the parties on the right to privatize our healthcare system, and by doing so throwing that into the same chaos that has caused the crisis we are now in.
If you want more information about SV’s politics, visit http://www.sv.no/ (http://sv.no/Language/English for English), or contact me directly and I will try to answer any questions you have.
For these reasons, and more (see the website), vote SV the 14th of September.
Posted in Politics | 2 Comments »
August 14th, 2009
Last week I released mussort version 0.2. This release is a huge update from version 0.1 that I released back in early 2008.
mussort is a simple command-line music sorting program. It recursively processes a directory tree, and then sorts whatever music files it finds there, renaming the files and putting them in a nice directory tree.
0.2 added a load of features designed to make mussort faster. It introduced optional caching of file tags, which has a major impact on the performance on subsequent runs on a directory tree. I optimized away an insane amount of readdir() calls that it kept doing over and over, even though nothing had actually changed since the last readdir(). It also only supported id3info and ogginfo as sources for information, which is problematic because ogginfo is very very slow at times. So in 0.2 it can use the Audio::File perl module if it is available. It provides redundancy (should Audio::File fail for an ogg file, it falls back to ogginfo, should id3info fail for an mp3 file it tries Audio::File) and a large speed increase for ogg vorbis files. It can also use id3v2 if it is available. Because of the caching however, even without Audio::File, any subsequent runs on ogg vorbis files will be a lot faster.
When it comes to actual features, the largest one is support for detection of compilation albums. It will locate an album that contains a lot of different artists and then put those into a single directory named after the album, rather than put them into separate artist/album dirs. For those that don’t want that, it is important to note that the feature is optional and must be explicitly requested (like case-insensitive sorting).
Other than that there’s a bunch of code cleanups, along with minor additions, such as selectable verbosity (–verbose, –quiet) and the option to keep all duplicate files around (–keepdupes). mussort is also now hosted on github, so if you are interested, fork the repository and let’s see what cool stuff you can come up with! Remember to prod me with a pull request so that any nice things you do get included upstream.
Posted in mussort, perl | No Comments »
April 16th, 2009
Day Planner 0.10 was released on the 25th of March! This release is, imho, a great step forward from 0.9. It fixes various minor bugs, cleans up parts of the UI, handles strange or broken iCalendar files better, enforces UTF-8 encoding on the calendar and adds a plugin system.
The largest new feature is the plugin system. Day Planner now comes with support for plugins, complete with a simple file format that allows users to easily install third party plugins. Its purpose is of course to make it easy for other people to alter the behaviour of Day Planner, or add features to it easily, without having to resort to patching the app itself, but also to make it easier for me to add optional features that perhaps not everyone wants (for instance, 0.10 comes with a tray icon plugin. It is disabled by default, but those that want to use it can do so quite easily). The API is simple, and somewhat inspired by the Gtk2-perl API, to make it feel somewhat familiar for people already used to signal-based programming.
The tarball comes with an example plugin, plugins/HelloWorld.pm that is well commented and explains how to do some of the basic things like hooking into signals, displaying simple dialog boxes and adding events to the calendar. The API itself is documented in DP::CoreModules::Plugin (access the documentation by running perldoc modules/DP-CoreModules/lib/DP/CoreModules/Plugin.pm from the base directory of the Day Planner tarball or git repo).
If you want to write a plugin, and need some help or pointers, feel free to join the Day Planner irc channel, #dayplanner on irc.freenode.net and I’ll be glad to help.
Git
As mentioned earlier, Day Planner is now using git instead of subversion. After I learned git I now greatly prefer it over subversion, and have thus moved all of my projects to it. Information on how to use the Day Planner git repo can be found at http://www.day-planner.org/index.php/development/git:
Posted in Random | No Comments »
February 18th, 2009
Last year, the 21st of December I had to send in my GF’s cellphone for repairs (bought online), incredibly enough the repairs went smoothly and fast, and on the 29th of December it was shipped back to us, using the Norwegian postal system. Little did we know that it wanted to go on a round trip around the southern part of Norway. This is its story.
29.12.08 – Sent from Drammen, Norway
29.12.08 – Arrived at a terminal in Oslo
30.12.08 – Arrived at a terminal in Stavanger
31.12.08 – Arrived at a terminal in Haugesund
02.01.09 – Beep! Still in Haugesund, and the post office realizes that we have moved and that we have bought a service to forward our mail to our new address
02.01.09 – Arrived in Stavanger. Gah! That’s the wrong way!
05.01.09 – Registered at a terminal in Bergen. Yay! It’s getting close!
06.01.09 – Arrived at our local post office in Bergen. Hurray.
…However, they never sent us any packing slip, and we didn’t have the tracking number so we didn’t know.
16.01.09 – Beep! Still in Bergen, and the post office realizes…something and decides to ship it somewhere else.
16.01.09 – Registered at a terminal in Bergen
19.01.09 – Registered at a terminal in Stavanger?!
20.01.09 – Arrived at a post office in Haugesund…again
31.01.09 – Beep! Still in Haugesund, and the post office realizes, once again that we have moved and that we STILL have purchased the service to forward it to our new address.
02.02.09 – Registered at a terminal in Stavanger…yet again
03.02.09 – Registered at a terminal in Bergen
04.02.09 – Arrived at our local post office in Bergen…again. Hurray!
…But they STILL hasn’t sent us any packing slip stating that the package has arrived and that we need to pick it up.
We contact the retailer, which contacts the repair shop, which provides the information that it is here! At our local post office!
So we go to our local post office, I present my ID and that there’s a package for me, aaand… they can’t find it. We go home and yet again mail the retailer, which contacts the repair shop which then gets hold of the tracking number.
Armed with this brand new information, we head to the post office again…
18.02.09 – We get the package.
And no, they still haven’t provided a packing slip.
This is true Norwegian efficiency.
Posted in Bugs :(, Personal, Random | No Comments »
February 13th, 2009
I’ve just written my first blog post for Linux Game Publishing on the new LGP blog.
The post is about the LGP community. You can head over to the LGP blog to read it.
Posted in GNU/Linux, Games | No Comments »
February 9th, 2009
I’ve got some plans for SWEC in the future. One of its primary limitations at the time is that it can’t really do advanced tests using things like POST or specific pattern matching. So I’m planning a simple command-based file format where you can define advanced checks for sites, to compliment the already existing fully-automated checks.
The basic syntax will be something like this (any input is welcome):
URL http://...
GET
MATCH /regex/ or STRING
RUN_CHECKS
URL http://
POST 'SOME_POSTDATA'
MATCH /regex/ or STRING
[My regex] MATCH /regex/
[String equality] MATCH STRING
RUN_CHECKS
RUN_MAIN
Here any URL statement defines a new check, where all previous data is dropped. Each section can have a POST or GET statement, and then any number of MATCH statements, as well as a RUN_CHECKS statement. If any MATCH statement fails (ie. the regex doesn’t match, or the result isn’t equal to STRING) then it will skip the remaining tests and skip ahead to the next URL or RUN_MAIN statement.
MATCH is obvious, it runs a test on the entire content to see if it matches a regex, or equals a string.
RUN_CHECKS would start the standard (SDF-based) SWEC checks on the returned data.
RUN_MAIN would start the main SWEC mode
[SOMETHING] MATCH would create a named match, so the content within [ ] would be the returned error if it doesn’t match, instead of something generic like “failed to match /regex/”.
Other commands I’ve thought of that I might or might not want to do include one to clean the cookiejar, so that tests can be performed on how a page acts when cookies are missing, and a way to add custom skip filters based upon for instance the URL.
THese are just random ideas and plans that I’ve got at the moment, I haven’t begone coding it yet, but it’s definetely something I’m going to do at some point. I’ll welcome any input if you have any.
Posted in SWEC, Web development, perl | No Comments »
February 2nd, 2009
I’ve been doing some web development lately, and the old question of testing has of course come up (and some might say, of course I had to roll my own solution).
I wanted a simple way to sanity check a site, to ensure that my article changes didn’t suddenly break comments on images (lagacy apps are strange beasts). So I ended up writing SWEC, the simple web error checker. It’s a basic app that goes through all links in a site (or “webapp”) as long as those are present in the HTML (ie. it doesn’t run any JS, so its use in JS/AJAX/AJAJ-heavy webapps can be somewhat limited). It parses all pages it downloads, looking for known errors and then reports those. For instance, if you run it on a site based on Catalyst (perl) and catalyst crashes with its standard backtrace, SWEC will return which page it happened on, which page referenced it and a quick line about what happened. Ie. if it’s an exception it’ll say “Exception in Catalyst controller”.
It uses a very simple file format for writing tests (which is well documented in SWEC’s manpage). It has several different types of tests, but the most common one looks something like this:
[SWEC_CATALYST_CONTROLLER_EXCEPTION]
type = regexs
check = Caught exception in.*Controller.*Request.*Catalyst
error = Exception in Catalyst controller
sortindex = 11
What’s between the brackets [ ] is the name of the test. All tests that are shiped with SWEC are prefixed with SWEC_.
The type defines which “type” of test it is. This one is “regexs” which is a ’smart’ regex, a standard perl regex that swec modifies during runtime to easier match HTML. The check is in this case a normal perl regex that is applied to the entire html document. As the type is regexs, swec will modify the regex to this during runtime: Caught(\\s+| |<[^>]+>)+exception(\\s+| |<[^>]+>)+in.*Request.*Catalyst
The error is the string that will be returned, and the sortindex is used for prioritizing tests, the lower the better (bundled tests will always be positive, so one only needs to give tests a negative index to ensure they will be run before bundled ones).
By default the bundled tests (default.sdf) and the user-specific rc file ~/.swecrc will be loaded. The user-specific one can disable bundled ones easily, and you can disable them on the command line on an individual basis.
SWEC supports sessions, where SWEC remembers previously checked URLs, and previous errors and can then either check pages that used to have errors before the others, or only report ‘new’ errors that did not exist before. This will also remember all settings that you set so you don’t have to type it every time (although it’ll allow you to do that as well). It has cookie support so it will run just fine as a logged-in user, though you probably don’t want to run it on a live database, but rather a test one, as it’ll click on any link it sees (with a few exceptions, it tries to avoid ‘logout’ and ‘delete’ links, additions to the exceptions list is welcome).
It’s GPLv3, so feel free to hack your own things into it. I’ll accept patches for the app itself, as well as new tests to be bundled. As long as they are either specific to a language, web server or framework, I’ll happily add more bundled checks (or fixes to existing ones), however I will try to avoid app-specific checks as that might just get a bit too much.
Happy hacking
Tags: automated testing, catalyst, html, SWEC, Web development
Posted in GNU/Linux, SWEC, Web development, perl | No Comments »
May 14th, 2008
The new Linux game turned out to be Sacred: Gold an action-RPG similar to Blizzard’s Diablo 2. The package includes the original Sacred, a free (official) expansion pack called Sacred Plus and the Sacred: Underworld expansion pack.
I for one can’t wait for this port to be released.
Tags: Games, games for linux, GNU/Linux, linux game publishing, sacred, sacred gold
Posted in Games, Random | No Comments »
May 3rd, 2008
Linux Game Publishing has announced a competition where one can win the first copy of their new unnannounced game for Linux.
The winner will be the first person to guess which game it is, based upon the slowly revealing image on http://competition.linuxgamepublishing.com/.
The chance to know what new game is coming out for Linux and the chance to win the first copy of it produced. Yay :).
If you want Linux games already released, head to TuxGames. (Yes that’s my referral link ;)
Posted in GNU/Linux, Games | No Comments »
May 3rd, 2008
Day Planner 0.9 has been released. It is available for download as a Mandriva RPM, Ubuntu deb, Debian deb, generic installer and source tarball.
The release focused primarily on fixes and cleanups. A bunch of minor bugs were fixed, and I rewrote most of the iCalendar back-end. It should be faster now and preserves files better than it used to.
This release includes a dummy maemo interface. It can currently fully display a Day Planner calendar, and has a UI quite similar to the desktop edition. However, it can not edit or add any events, and is as such not as useful as it might have been. The plan is for the maemo port to be ready for 0.11.
0.10 will (among other things) feature a new HTML exporting module (which has been in the works for quite a while), a cleaner, object-oriented version of the add/edit event windows (to simplify their use and maintainance. The current code that handles it is a bit ugly).
The major user-facing change will be the addition of a GUI for calendar subscriptions. 0.9 includes support for them (though it isn’t really announced because the feature isn’t ready), but one has to manually edit the config file.
Posted in Day Planner, Debian, GNOME, GNU/Linux, Maemo, Mandriva, Ubuntu, gtk2, perl | No Comments »
April 27th, 2008
(Re: Proprietary Webcam driver wonders).
I recently discovered a free driver for my GF’s builtin Microdia webcam. It works very nicely (better than the crappy proprietary one did when I tested the “trial”). So if you’ve got a Microdia webcam, at least the 0c45:624f one, now you can have it working properly, with good quality without paying a load of money for a one-time one-kernel one-arch license for a proprietary one.
git clone http://repo.or.cz/r/microdia.git
cd microdia
make
sudo insmod ./microdia.ko
Then just launch Cheese or your favourite webcam program and off you go.
Thanks a lot to those that took the time to develop a proper driver. If you’ve got a paypal account, I’ll donate some money for your hard work.
Update: the module is now named sn9c20x.ko, so the last line becomes sudo insmod ./sn9c20x.ko
Update 2: According to brandon in the comments, the kernel module is in the upstream kernel as of 2.6.31.6
Posted in Debian, GNOME, GNU/Linux, Mandriva, Ubuntu | 24 Comments »
April 25th, 2008
I’ve added automatic development snapshots of Day Planner to the Day Planner homepage. There are currently three different branches (trunk, next stable, current stable) being built, in two flavours (tarball and installer). The snapshots are updated twice each day and are available at http://www.day-planner.org/index.php/download/snapshot. Feel free to take them for a spin.
Posted in Day Planner, GNOME, GNU/Linux, gtk2, perl, php | No Comments »
April 23rd, 2008
An e-mail dumped into my inbox today, from the CEO of the MP3Tunes service, that I use for backing up my music collection. It stated that EMI claimed that this use was illegal and had sued MP3Tunes (this happened a while ago, I know). This isn’t even a case of so-called “piracy” that you claim is so evil, it’s me backing up my music. You’ve screwed up with all of your RIAA blunders already, one might think that you would realize that suing customers (or in this case, a company providing a useful service to your customers) is generally a bad idea.
Oh well, add me to the growing list of people boycotting you (and don’t think for a second that this is an empty statement).
Some articles on the subject: http://michaelrobertson.com/archive.php?minute_id=251, http://michaelrobertson.com/archive.php?minute_id=259, http://consumerist.com/382824/emi-says-you-cant-store-your-music-files-online and http://www.exchangemagazine.com/morningpost/2008/week13/Tuesday/032501.html. (note that I do not agree with, nor endorse all of the statements on these websites, they are provided as a source of information on the subject only).
Tags: lawsuit, mp3, mp3tunes, Music, ogg
Posted in Music, Personal, Politics | No Comments »
April 19th, 2008
Today is the second anniversary of the Day Planner project. So hurray for Day Planner, and here’s to all the great releases to come.
In other related news, I’ve just released a development snapshot of Day Planner 0.9.
It is available at http://www.day-planner.org/index.php/download/devsnapshot. It contains all of the developed features for 0.9 (including the unfinished maemo port), but is not yet stable enough to be labelled stable, so If you’ve got time and feel like it, give it a spin and report any bugs you find. The whole iCalendar back-end has been almost completely re-written for this version, which is why I want some additional testing before I release a stable version.
Please do not package this release or submit it to news sites, it’s just a svn snapshot.
Posted in Day Planner, GNOME, GNU/Linux, Maemo, perl | No Comments »
April 15th, 2008
Everyone else is doing it!
[0 zerodogg@firefly ~]$ history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
279 cd
185 vim
117 ssh
75 screen
74 svn
66 wget
64 ls
60 perldoc
59 rm
58 cget
Posted in GNU/Linux, Random | No Comments »