Saturday, 12 March 2011

zsh tips

Invoke 'less' smartly

One of the nice little things about Git is that if the output of a command is long, then it is displayed in less. If output of a command is short, it is just displayed (there is no interactive Git involved). One can make Mercurial suck less by emulating this behavoiur with Pager extension.

Would be it nice to have this automatic less for everything, not just hg and git? Add this one line to your .zshrc:

AL() { $* 2>&1 | less -FSRX }

Now you can call commands like AL ls /tmp/mydir and enjoy having pager only when you need it. -R option makes less not mess up colour escapes.

Have easy access to newest download

I set chrome to automatically download everything to ~/downloads folder. I often want to do something with newest downloaded file (like open it or move somewhere else).

alias -g @@NDL='~/downloads/*(.om[1])'

You can use anything that is unlikely to collide with anything else instead of @@NDL (which stands for Newest DownLoad). Now you can use it like:

acroread @@NDL
mv @@NDL .

Parenthesis after glob is qualifier. Dot stands for file, om Ordered by Modification. One is there because om[0] always matches current directory.

Wednesday, 11 November 2009

64-bit Linux + Eclipse Galileo crash - fix

A short one.

I had this problem some time ago, and today I've seen someone else on #eclipse IRC channel to have it. If you are running 64-bit Linux (esp. Gentoo) and Eclipse Galileo and your eclipse keeps crashing with XPCOM error -2147467262, then fear no more. this is what you should do:

  1. turn off all Eclipse instances
  2. delete following files:
    • WORKSPACE/.metadata
    • ~/.mozilla/eclipse
    • ~/.eclipse
  3. add -Dorg.eclipse.swt.browser.XULRunnerPath=/usr/lib64/xulrunner-1.9.1/ to the end of your eclipse.ini file (actual path to your may be different)
  4. you are done. You may use your Eclipse safely

This tip is based on comments 11 and 12 in this bug report.

Wednesday, 20 May 2009

Controlling roommate's music with ssh and dcop

This is rather old one, but I didn't publish it here before.

Both my roommates use Amarok as their music player. I'm OK with music they listen to for 90% of time, but their big, fat playlists hide some real monsters. And they both have a bad habit of leaving the room with Amaroks playing in shuffle mode.

This is why I created two little scripts to pause/change the song without leaving the comfort of my chair.

Here is one, for Paweł (username pavlo) and his widescreen laptop kuandatun (kuandatun it's supposed to mean "wide ass" in Chineese).

ssh kuandatun "/opt/kde3/bin/dcop --all-sessions --user pavlo amarok player $*"

I have kuandatun in /etc/hosts, my .ssh/config knows that it should log in as pavlo to his machine and I have my public key listed in his .ssh/authorized_keys. Now, changing shitty song on his computer is as easy as AmarokPawla next.

The less evil use of this script is getting title, lyrics or artist of currently playing song.

EDIT: this is going to be obsolete soon, when they switch to amarok2, which uses D-Bus instead of DCOP, but it's basically the same trick

Friday, 27 March 2009

Introducing Zmrok

It was neither sleep, nor science. It was pure art. Ladies and Gentleman, I present you the Zmrok colour scheme:

  • it looks good
    • well, I like it ;-)
  • it's small:
    • it's hackable
    • it's easily portable to other editors

Source can be viewed and downloaded at my mercurial repo or

Zmrok is Polish for twilight, check out TextMate's (or's) twilight colour scheme if you still wonder why it's named this way ;)

Sunday, 14 December 2008

Open source is great

I'm proud and happy to proclaim my Russian PLansliterated vimscript dead. Some nice guy have taken a look at it and developed a superior solution, so Russian PLansliterated shared a destiny of my pygments' lexer for Scala.

An interesting meta-solution emerges:
  1. Realize that you have a quite general problem
  2. Write 15-30 min hack solution to it. It may work a little crappy, but it's good if it's easy to read and extend.
  3. Open source it
  4. Wait...
  5. Next time you'll have the same problem someone has improved your solution beyond the recognition, so you can dump the old one.

It seems that improving something that exists is psychologically easier that starting from scratch. My new slides about Scala (download them, browse the source or watch them online) were made using pygments with new shiny lexer developed by someone pissed off by quality of an old one. Open Source is great, isn't it?

Saturday, 15 November 2008

Programming language idea

Well, it's an idea about programming language without a programming language.

Think about writing a script that generates assembly. It's doable. Sometimes it's even *almost* sane thing to do, eg. when working on spellchecker I've had a crazy idea about generating code that does dictionary lookup for a hardcoded word set (It's no rocket science, just compare, jump, compare, jump...). But it's so low level and not cross-platform.

I've done some C generation from Python several times (eg. to make last year's april fool's joke - it's on this blog). The problem is that C is often not flexible enough (GCC would choke on 100MB file for dictionary; TCO, call/cc and other fancy stuff is hard...). Not C, not assembly...

There is LLVM - a perfect target.

Moving on: a scripting language that would generate all this mess.

It should be very, very meta one. Like lisp, but with syntax. A pluggable one.

My idea is to write a language that would have pluggable lexer (one lexer would switch to another one when it would encounter some sequence of characters - think of reader macros on steroids), then a huge layer of macros (tons of macros. Like Nemerle). Add a lispy semantics on top of it (few orthogonal concepts that combine together nicely) and my evil plan is 10% complete.

You would be able to create literal syntax for your new, shiny DSL inside your script, then semantics that would generate optimal machine code for it and boom!

It would enable some crazy stuff. Think of all super-duper assertions library creator would be able to enforce compile time with it! You like that D enables you have optional purity control? You can add it to your script.

It wouldn't be general purpose tool (it would probably be to wired and demanding to do everyday work), but I can see applications where you have to be extremely fast (OS kernels, games) or you are very domain-specific stuff (think of all those code-generating tools like lex, bison, antlr).

More or less related things to do/blog about in future:
- DBus + gvim - a possible step towards an headless IDE
- Actor-based OS

random stuff

Beep, beep! I'm still (more or less) alive.

University takes me lots of time, which is my primary excuse for not blogging
for so long time. Projects are like gas - they fill up all available space^H^H^H^H^H time.

Interesting (for geeky enough definition of "interesting") stuff I've done recently:

  • Spellchecker. It's a quite smart one -- written in python and C, it uses trie (ternary search tree) for storing dictionary. It's super-fast to load data (there are no pointers, so loading it is just one read of binary file, and you can use it).

    Then you can use TST to quickly (it's quicker than hashmap) check if a word belongs to vocabulary or retrieve (it's still bleeding fast) a list of words that are no further (in Levenstein's (edit) distance) than misspelled one.

    Then it uses longest common subsequence algorithm to get parts that don't match and compares those parts using knowledge about typical spelling errors in Polish. It can correct "grzegrzułka", "zomp" and "fzhut". In summary: it's cool.

  • I'm preparing a talk about scala. It's work in progress. You can see some slides here. I'll give this talk on 3th December as a part of BIWAK

  • Oh, yes, BIWAK. We (BIT science club) have started a series of talks called BIWAK.

  • Oh, yes, science club. I've done some work on platform game with cool physics, but there is nothing cool to show off yet.

  • I've published some of my .rc files

  • Hooray new swimming pool! Hooray hiking! Hooray birthdays and weddings. Hooray real life.