Zero_Dogg

Random comments on geeky things

wwine 0.2 released

I’ve just released wwine 0.2. It adds support for the new Crossover 11.0 release, which changes some of the paths and needs a bit of additional magic to use. It also has some improvements to the wrapper scripts it generates, primarily through a new and more robust metadata header.

The most interesting new feature however, is the addition of the --env and --tricks parameters. --env causes wwine to set the WINE and WINEPREFIX variables to the syntax used by vanilla wine, this allows various wine scripts that use those to be able to run using wwine’s bottles, as well as with crossover. The most interesting use of this is the ability to use winetricks with Crossover. This effectively lets you use Crossover as any other wine release, while still using Crossover’s bottles. So if you have winetricks and Crossover installed, you need only run wwine -w cx -b BOTTLE --tricks ACTION to use winetricks with Crossover.

Blog migrated to octopress

I have finally gotten around to migrating my blog from wordpress to octopress.

Octopress is “A blogging framework for hackers”. It’s based on jekyll, a ruby framework for generating static websites. What sold me on it is the ability to use the best blog-writing client available, a normal shell along with vim. Blog posts are written in markdown (by default), the source is in git, and it comes with rake targets for creating new posts, building it and deploying it.

As this should make it a lot easier to write posts, I’m hoping that it just might make me post more often.

jqsimple-class 0.1.1

Last week I released version 0.1.1 of jQsimple-class. The main addition in this version is support for using jQsimple-class in CommonJS environments, such as node.js. All one has to do is place the CommonJS build of jqsimple-class somewhere in the include path and then do:

var jClass = require('jqsimple-class').jClass;

From there on out the API is the same as the browser one. The CommonJS build also has the same testsuite as the normal build, and passes all of the tests.

Outside of that, the standalone build has been stripped down to the bare necessities, shrinking the minified standalone build of jQsimple-class from 10KiB to 3KiB (the version that uses jQuery is just 1.5KiB).

jQsimple-class released

Today I’ve released the first version of jQsimple-class, a small JavaScript class-declaration library. The reason I wrote it is that the usual way of building classes in JavaScript is frankly quite ugly, and inheritance is equally ugly. With jQsimple-class I’ve tried to make it as simple and intuitive as possible to write classes in JavaScript. The library itself is very small, and the syntax is simple. It’s meant to let you quickly declare a class, and easily extend others, and then get completely out of your way. It only exports a single variable/function, named jClass (Class is a reserved word in JavaScript, so I went for the next best thing). Using jClass, and methods on it, it is possible to build classes, virtual classes and extend classes.

jClass() takes a single parameter, a JavaScript hash, where keys are method or attribute names, and the values are any valid JavaScript type. jClass.extend() lets you build a class that extends one or more existing classes. jClass.virtual() lets you construct a “virtual” class. That is to say, a class that can not be instantiated, but that can be extended by others.

Internally jQsimple-class uses some jQuery methods, but it does not depend upon jQuery to be used, a standalone version that bundles the parts it needs (not all of jQuery, and without exposing them to the public namespace) is available for applications that do not use jQuery. I have written an extensive testsuite for jQsimple-class to make sure that things work as they should, and it works across all modern browsers.

For more examples and the full API, see the jQsimple-class documentation. jQsimple-class version 0.1 is available for download now. Minified it is only 1.5K (or 9K for the standalone version). Any feedback is welcome, feel free to do so in the comments, or, if you find a bug, on the bugtracker.

A very simple one-liner REPL for perl

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

SWEC 0.4

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.

Fixing PHP documentation woes

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

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

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:

Vote for the Socialist Left Party on the 14th of September

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.