Archive for the ‘software’ Category

Slax

Monday, September 28th, 2009

My work laptop is a little bit on the heavy side. It works well as a desktop replacement which is how I use it these days. I hardly ever use it without an external monitor mouse and keyboard. I’m actually considering buying either one of those mini notebooks or perhaps a macbook at some point in the future – a machine that I could actually drag around with me everywhere. But that will have to wait since I just got my gaming monster PC recently.

Besides, most of the time when I need to use a computer one is readily available for me. For example, when I’m at school I have a PC on the desk in the adjunct office. And since I tend to keep most of my school related files synced with Dropbox they are available to me via the web interface. That said, it is nice to work in a familiar environment using the software you like without worrying about key loggers that other adjuncts doubtlessly installed on the shared office computer. Yeah, I do usually carry a Knoppix CD in my book bag but that doesn’t really cut it. What I’d really like is my own comfy, lived-in environment – not a pristine Live CD boot. You know what I mean?

So lately I decided to do something new. Believe it or not, but in all my years with Linux I have never created a bootable USB type thing. I used countless live CD’s in the past, but it actually never occurred to me to try something more persistent. So I dug out my old 2GB stick and installed Slax.

Why Slax you ask? Oh, I don’t know. It’s small, clean, easy to use and actually designed to work off a USB drive. It’s a minimalistic OS and yet it runs a lightweight version of KDE making me feel like home. I have tried many different desktop environments but KDE was always the one that just felt right. So I’m naturally inclined towards systems that use it.

Not to mention that the installation itself is almost laughably easy. You download a tarball, extract it to your USB stick and then just run an included shell script to overwrite the devices MBR. It literally takes 5 minutes, including the download time (well, depends on your bandwidth, but you know what I mean).

The USB version of Slax is persistent – it will actually write changes to the disk, and allow you to set up your environment the way you like it and keep it that way. If you mess up, you can even reset it to a default state at boot time. It boots around 10 times faster than a Live CD and is quite responsive.

I particularly like how Slax resolved the whole package management conundrum. For example, you can “temporarily” install software with one click of a button. You just go here find your module and click “Activate”. This will download an install the package, but only for the duration of the current session. Once you reboot the package will be gone. Of course you can download the package and permanently install it as well – it’s just that the temporary option is kinda neat.

Of course, it is mostly a toy operating system. I wouldn’t recommend using it for mission critical stuff. I wouldn’t make it your primary OS. But if you want to carry your own customized environment and software in your pocket, it is perfect. Just plug it in, boot the machine and enjoy. I highly recommend setting one up for yourself if you know you will need to use some public/shared machine somewhere. Naturally competent admins of shared machines will probably disable all the bootable devices other than the HD and password protect the BIOS. Thankfully, competent admins are quite rare.

So yeah. Give it a whirl if you are in the market for USB based distribution.

Vim – Add Line Numbers

Tuesday, September 8th, 2009

Have I mentioned that I love Vim? It is such a useful little tool. Let me give you an example. The other day someone gave me a messy list – a dump of email addresses from some database as a comma separated file. Here is a sample of how it looked like – note that instead of actual emails I’m using names of vegetables, fruits and other stuff (like Rupert, or poo for example):

test, poop, boob, apple, carrot, mango, kiwi, apricot, banana, apple, tomato, prune, cranberry, raspberry, orange, lemon, potato, pudding, lemonade, pants, spoon, flax, dogmeat, poison, pee, hamburger, rupert, apple, mango, sunflower, bee, pumpernickel, puddle

Of course the actual list had over a thousand emails and did not include Rupert (or his poo for that matter). It was equally messy, full of duplicate emails and basically looking like a wall of text. Someone requested it expecting a sorted, itemized list that they could print out and look at for reference. What they got was a text blob.

So I grabbed the file and opened it in the trusty old Vim and issued three commands. The first one was:

:%s/, /\r/g

Of course this is a single regexp. I’m replacing every occurrence of a comma followed by a space with a carriage return. This sort of unrolled my csv into a file with a single item on each line:

test
poop
boob
apple
carrot
mango
kiwi
apricot
banana
apple
tomato
prune
cranberry
raspberry
orange
lemon
potato
pudding
lemonade
pants
spoon
flax
dogmeat
poison
pee
hamburger
rupert
apple
mango
sunflower
bee
pumpernickel
puddle

To sort it, I simply did:

:%sort u

This sorted my list and removed the duplicates (the ‘u’ stands for unique list):

apple
apricot
banana
bee
boob
carrot
cranberry
dogmeat
flax
hamburger
kiwi
lemon
lemonade
mango
orange
pants
pee
poison
poop
potato
prune
pudding
puddle
pumpernickel
raspberry
rupert
spoon
sunflower
test
tomato

Last touch was to add line numbers to every single line. Yes, I know – I could print the file with line numbers enabled but the person who would be using this file was barely capable of using notepad. So the lines had to be hard coded. This is actually a new trick that I just learned and it goes like this:

:%s/^/\=line('.').". "/

The \=line('.') bit does the actual line numbering, while the .". " bit simply appends a dot and a space to each number so they nicely stand out from the actual items. The end result looks like this:

1. apple
2. apricot
3. banana
4. bee
5. boob
6. carrot
7. cranberry
8. dogmeat
9. flax
10. hamburger
11. kiwi
12. lemon
13. lemonade
14. mango
15. orange
16. pants
17. pee
18. poison
19. poop
20. potato
21. prune
22. pudding
23. puddle
24. pumpernickel
25. raspberry
26. rupert
27. spoon
28. sunflower
29. test
30. tomato

I’m putting this here as a useful tip – more for myself than anyone else. Chances are I will forget the line numbering trick in a few weeks and will need to look it up again. Hopefully some of you may find it useful as well.

To summarize: Vim is awesome. It is like a Swiss Army Knife for text files. Use it, learn it, love it!

Textarea Cache

Tuesday, September 1st, 2009

Have you ever typed a long, insightful blog post or comment and immediately lost it because you accidentally hit the wrong button? I do that all the time! I can’t tell you how often have I lost a good hour of work just because of hitting the wrong button at the wrong time. That’s the problem with writing inside of a browser – you can’t always undo your mistakes, and you can’t always save your work.

It used to be much worse in the past. These days there are many fail-safes that can often prevent you from losing your work. Firefox for example will restore your text area contents if you accidentally close the browser window and/or tab. This is great but of course won’t help you in all circumstances. There are quite a few things you can do to foil this feature and still lose your meticulously typed text. Let me count the ways to fuck yourself over in Firefox:

  1. Hitting refresh
  2. Hitting the back button
  3. Accidentally clicking on some link
  4. Hitting backspace when textarea is not in focus (works like back button)
  5. Closing the browser while having it set to purge session data on close

Web application developers know this and they have started building their own counter measures to prevent it from happening. For example, Wordpress will automagically save your posts as you type them. Unless of course you leave it unattended for a little while.

This actually happened to me recently – I was typing up a post, and had to leave my desk for a bit. I forgot to hit the save button but that wasn’t a grievous mistake because the auto save feature kicked in anyway. When I came back, I finished the post, proof read it, corrected mistakes, rephrased couple of sentences and finally hit the save button… Only to have Wordpress notify me that I need to log back in.

Some applications try to save the data from a previous POST request as you log in. Wordpress does not do that. When I got back to my post draft, I realized that the last copy was the auto save from about an hour ago.

This annoyed the shit out of me. I mean, seriously – we know that stuff like that happens all the time. Why can’t we just cache the textarea contents somewhere as you type? Yes, saving everything you type would be a privacy concern but you could make it an optional feature that has to be enabled, and set the browser to purge anything that has not been touched in say two days of active browser use.

In fact, I’m using Firefox. There should be a plugin for something like that for fucks’ sake!

So on the off chance I typed “textarea cache plugin firefox” into Google and voilĂ : there is one.

It does exactly what you would think – it caches everything you type into a textarea fields and purges old entries on some sort of schedule. It puts a tiny button into the status bar, and pressing it will open the currently active cache and a list of other saved buffers. You can purge any and all of them at will using that very same interface.

I had no clue this thing existed, but now I don’t know how can this not be a part of the core browser. I highly recommend checking it out.