Archive for the ‘Random’ Category

A very simple one-liner REPL for perl

Tuesday, 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;}}'\'''

Fixing PHP documentation woes

Wednesday, 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.

Sanity checking mason

Tuesday, 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:

Dynamically loading git bash-completion

Monday, 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:

Day Planner 0.10

Thursday, 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:

The happy travels of a postal parcel

Wednesday, 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.

Sacred: Gold announced for Linux

Wednesday, 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.

History meme

Tuesday, 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

A bunch of new stuff

Wednesday, March 19th, 2008

I’ve finally taken the time to prepare a website for all the various programs and scripts I’ve got in use here that the world might also find some use for. The address, right now, is http://random.zerodogg.org, though once I find some more imaginative name I’ll probably move it, but for now it’s random.
Everything mentioned is either GPLv3 (most of it) or GPLv2 (some of it).

I’ll write a quick word on the various new projects, and note those that I have moved from older websites to random.

New stuff:

Audio Utils
This is just a collection of scripts I’ve had in use (and had uploaded for the world to download previoulsy, but never together nor on a proper website) that assists in various audio-related tasks. These are:
aac2ogg – a quick and dirty aac to ogg converter, using mplayer, faad and oggenc
wma2ogg – the same for wma, using mplayer and oggenc
reencode – a quick and dirty bash script that lets you re-encode an mp3 file to another bitrate. Useful for clearing up space on “mp3 players”, especially if you’re into audio-books, which can often have their bitrates drastically reduced and still be in a fairly decent quality.

GRandomWallpaper
This is a wallpaper randomizer for GNOME/Nautilus. It takes a list of wallpapers (a directory) and selects a random one. This can be done on a timer, or just once. It keeps a hitlist for how many times a wallpaper has been shown, and is more likely to pick those that have not been shown as often. It also lets you ban wallpapers, which will cause it to always ignore the wallpaper in question.

LatexB
This is a quick script that assists in building LaTeX files. It can call latex or pdflatex, automatically spawn xdvi(k) or evince after building, and detect bibtex. It’s merely a utility script so that I can do “latexb file.tex” to build the LaTeX file properly in one go (it calls latex multiple times to ensure that everything is referenced properly).

MonitorGrowth
This is a simple perl program that lets you monitor how fast a file is growing, displays information similar to that of download utilities like wget.

mussort
This program sorts your music collection. It puts them into nice directories (artist/album) and renames the files, so that everything is consistent. It can also let you delete dupes. It works on MP3, and OGG Vorbis-files.

SPGal
This is my first python project. It builds a static XHTML-gallery from a set of images. It can work as a drop-in replacement of iGal and jGal.

Old stuff, new website:

MagicPO
This is a program that helps you translate PO-files from one similar language to another. Right now it can do automatic translation of for instance Norwegian Bokmål to Norwegian Nynorsk (you only have to read through them afterwards).

PDFtoPNG
This is a quick program that lets you convert PDFs into a set of PNG files. It can also build HTML-files to go with the PNGs, for easy reading in a browser.

SLX-Dict
This is a simple command-line program that lets you look up words in the Norwegian computer translation dictionary. It’s useful if you don’t want to open firefox and search for words there all the time.

SSHMan
SSHMan is a simple ssh agent helper, along the lines of keychain. It does persistant management of ssh agents, will only ever prompt you for adding keys to the agent once, does not slow down logging into X and does not start when you’re logging in via ssh.

Day Planner update

Wednesday, October 31st, 2007

Its been ages since I last wrote about Day Planner, so I figured it might be about time I did.
I think the last time I wrote about version 0.1.2 or something along those lines. A rather buggy and incomplete release. It’s now up to 0.7.2 and rather stable, if I might say so. Some major things have happened during this time.
- Day Planner now uses iCalendar as default format, import and export formats.
- It supports iCalendar recurrances
- It has a builtin calendar synchronization system
- Loads of UI-enhancements
- Now licensed under GPLv3
- Complies with the XDG configuration dir spec
- Can import data directly from various programs (such as Evolution, Gnome Calendar, Korganizer, Plan)

There are a load of other smaller refinements and fixes too, but these are the largest ones.
I’m currently working on version 0.8 which will introduce rewritten daemon and notifier programs, support for multiple iCalendar files (not locally, but for instance it will be able to add HTTP subscriptions).

A bit further into the future I want to implement support for Conduit and eventually drop the builtin calendar synchronization system. I’m also planning to investigate better integration with GNOME through the use of the evolution-data-server, that recently got a proper dbus interface. It is useful to note however that Day Planner will never require e-d-s, but should be able to use it when available to provide additional integration with the desktop environment.

As a final note, I’m looking for someone to do some simple images for the Day Planner website. If I would do them myself I think I’d be arrested for crimes against mankind, I can’t do visual art. If you have the time and want to do it, please let me know, either in the comments below or through any of the means of contacting me available on my website (IM, e-mail, IRC and so on).

The joys of Netshop.no

Wednesday, September 26th, 2007

I turned in my laptop for repairs this January (under a month after the last repair). The screen was broken. Then they informed me that the motherboard was also borked, due to moisture, so I’d have to pay for the repairing of that. Okay, that’s fair enough I guess. So I told them to go ahead and repair. Months passed, until I finally got ahold of them again in April. They then told me that there had been some kind of mistake somewhere and that they would get right to repairing it and that they would do it for free because of the excessive wait. Fair deal, though I’m getting grumpy waiting for my laptop so long, but NOW it must soon be here, as they’re on it again.

Not so, now they tell me that the spare motherboard they had in stock for the laptop was also broken, so they needed to order new ones. More waiting. Yay. Then suddenly it was vacation, so I couldn’t get ahold of them. Waiting for supplies from Denmark. Right. Well, I need a motherboard for it to work. So I wait.

Now it’s September and I have yet to see any laptop, the technician doesn’t reply to my queries, and the people in phone support are about as much help as talking to my wall. I need that laptop.

So what can I do? I can contact the idiots and probably demand that they send the laptop to me now. But what good will that do, I’ll have a laptop without a working motherboard. So that’s the same as right now, really. Complain? Right, that’s what I’m doing, they don’t seem to care much. So I’m at a loss. Just want my laptop back.

For the record the laptop is a Zepto Znote 6515WD. I believe that’s just a rebranded Compal laptop, though I have no idea which model.

BASH SSH host completion

Saturday, April 21st, 2007

I tried the bash completion stuff, and found a single thing I liked, ssh completion. Most of the other stuff just annoyed me… a lot (and was mostly useless, at least for me). I first looked at the code in the bash completion for ssh completion, but it was imho too large to stuff into my .bashrc, so I wrote a small perl one-liner that did the trick.

complete -C "/usr/bin/perl -e 'my \$match = \$ARGV[1] ? \$ARGV[1] : \".*\"; open(my \$INPUT,\"< \",\"$HOME/.ssh/config\"); foreach(> \$INPUT<) {next unless s/^\s*Host\s+//;chomp;foreach(split(/\s+/)) { print \"\$_\\n\" if(/^\$match/ and not /^\d/ and not /\*/);}}'" ssh

Stuff that into ~/.bashrc and off you go. It completes based upon hosts in ~/.ssh/config

Happy birthday, Day Planner!

Thursday, April 19th, 2007

Today, the 19th of April, it is exactly one year since the first release of Day Planner, 0.1, was released. The first release was, as expected, pretty buggy. But it has since grown into a stable and useful program and has seen major improvements since the first release. I just recently released version 0.6 which introduced the Day Planner services calendar synchronization system and a load of usability fixes, thanks to mpt in #usability on irc.gnome.org. I’m now hard at work on version 0.7, which will among other things introduce proper recurrance support for normal events.

If it’s been a while since you tried it, or if you haven’t tried it at all, go ahead and give it a download. It is available as a Mandriva Linux noarch RPM, generic .run installer and a source tarball, it also has only one single dependency except for perl and that is the gtk2 perl bindings, so it should run without having to install 20 dependencies.

Mandriva ONE usefulness dropping

Wednesday, April 18th, 2007

With 2007.0, all I really used was Mandriva ONE for installing Mandriva on boxes. It fit on one CD and didn’t install more than the required software (ie. not five different programs that do the same thing).
This time however, it seems that they have dropped localization for most of Mandriva One. There isn’t a Mandriva One GNOME with Norwegian Nynorsk on it anymore, rendering the entire idea useless, both as a live CD to allow people to try the system and as a handy installation disk. So right now I’m wondering if we’ll see a release of the good set of One disks as 2007.0 had or if that has been dropped completely.

*pokes Mandriva* I want my One CD :o

As a sidenote, I tried the Ubuntu Live CD too, and found Mandriva ONE GNOME superior to it, partly due to the localization.

Happy holidays

Sunday, December 24th, 2006

I wish you all a happy holiday.

While I do this I also want you to take a moment to think about those that don’t have one. Some celebrate it alone, some are depressed, some drugged, some fighting for their life and some just afraid. Take a moment, give them a moment – that’s all they need. I hope you’re not one of these, but if you are my thoughts, wishes and greetings go to you (and don’t hesitate to get in touch if you so desire).

Day Planner services beta test

Monday, December 4th, 2006

I’m going to start the semi-public beta test of the day planner services system now.

The day planner services system is a system for calendar synchronization. It does:
- Synchronization of calendars on multiple locations
- Availability of an html version of the calendar

It is integrated into day planner and needs testing.

If you want to join the test, please just contact me (by for instance commenting on this blog post).
The code is naturally free, but the service will be “payed for”. Plan is something like those that donate to the project will get this service for some time. Ofcourse nothing is to stop anyone from putting up their own server but the one run by me will be on a payed-basis.
Those in the beta will get it free for more time, a year or so maybe.

Need testers – contact me.

Hosting!

Tuesday, September 26th, 2006

Well, I decided on NearlyFreeSpeech.net. They offer a great service at very very good prices. I’ve registrered zerodogg.org, and it’s already up! Took 30 mins.

I’m still battling my old provider to get iamaturtle.org transferred to NearlyFreeSpeech.net, so far half-successfull (the domain is now in my name and unlocked), I just need the transfer code now. So we’ll see, maybe I get it before it expires. My old subdomains are now being forwarded to zerodogg.org (blog.iamaturtle.org -> blog.zerodogg.org and zerodog.iamaturtle.org -> zerodogg.org).

Hosting?

Monday, September 25th, 2006

My host sucks. The service they provide is great and cheap, but their support sucks. That is, I can live with slow response times, but they don’t answer me…ever.

So now I’m on the look for a new provider. I need:
- SSH access
- PHP(5)
- Multiple subdomains
- Good traffic (5+GB per month at a minimum I’d say, though I can live with less)
- Preferrably support for two domains (iamaturtle.org and another one)

Any hints? Put links in comments.

drakSimpleConf

Saturday, September 16th, 2006

I’ve been thinking of a method of creating simple configuration UIs.

Take the following config file:
RunMode = Inetd
AuthMode = Closed
Restricted = true

To create a simple configuration GUI for this I would write something like this:
filename is /etc/example.conf
setting RUNMODE can be (Inetd, Daemon)
setting AUTHMODE can be (Closed, Open)
option RunMode is RUNMODE with name "Run mode" and tooltip "Which mode to run in"
option AuthMode is AUTHMODE with name "Authentication mode" and tooltip "Which mode to use for authentication"
option Restricted is BOOLEAN with name "Enable restriction" and tooltip "Enable this if you want to enable restriction of user rights"

The initial filename option selects which file the config file is.
The first “setting” defines a type of entry in the config file that can be either of the value “Inetd” or “Daemon”. This would create a drop-down widget where you can select “Inetd” and “Daemon”.
The second setting defines the same for “Closed” and “Open”.
The first “option” defines that the option in the config file “RunMode” is of the type “RUNMODE” and the name of the option that is displayed in the GUI is “Run mode” and it has a tooltip saying “Which mode to run in”
The second is the same.
The third one defines that the option “Restricted” is of the predefined type “BOOLEAN” (which is predefined to be true/false, this creates a checkbox instead of a drop-down box).

Now begin your slaughtering. This is still just an idea. There is no code yet. What do you think of the concept of creating a whole configuration GUI for an app using a single file like this? I’m thinking it would be okay for daemons and such.
What do you think of the syntax? I just grabbed it out of my head today and thought it might work. I want the syntax to be simple and human-readable. The point is that you should be able to hack together a GUI for any program with a simple configuration file in a few minutes.

Flame me.

Code monkey like you!

Wednesday, April 19th, 2006

http://www.jonathancoulton.com/music/thingaweek/CodeMonkey.mp3

This code monkey like Lisbeth. Who do you?

Great song. For those lazy of you out there (yeah, there’s quite many lazy people that will read this blog post):

wget http://www.jonathancoulton.com/music/thingaweek/CodeMonkey.mp3 ; mplayer ./CodeMonkey.mp3