matt-helps

insight on all things techie

Facebook Easter Egg

Well I’m not sure what facebook are doing with this but if you follow the following commands you get a lens flare (a visual effect) on the screen:

1. Log into facebook
2. Click on the background (the white bit)
3. Press: up, up, down, down, left, right, left, right
4. Press: b, a, enter
5. Click on the screen

Thanks facebook - I guess their code monkeys have got time to kill !?

How to spend $4000 from the commandline!

I have used Amazon Elastic Cloud (EC2) for my dedicated hosting needs for nearly 6 months now. They’ve just released a new “bulk-buy” service that enables you to buy 1 or 3 years’ of as many instances as you want in advance. I’ve just bought 3 years of the smallest instance at $500 plus $0.03 per hour - saving just over half of my server costs over the course of the 3 years: $500 + (24*365.25*3*0.03) = $1288.94 for 3 years, verses the current cost of $0.1 per hour which is 24*365.25*3*0.1 = $2629.80 for 3 years. Both prices are ex-vat and don’t include bandwidth costs or storage costs, obviously, though those costs are themselves VERY competitive ($0.17/GB outgoing and $0.10/GB incoming). But as you can see it is a good deal for me to bulk buy in advance.

So how do you bulk buy? Amazon’s new service is called reserved instance and you bulk buy simply by typing in a command in your terminal or dos cmd prompt (ec2-purchase-reserved-instance-offering) and hey presto you’ve just bulk bought in advance. For me that was $500, but it is possible to buy the biggest instance they have for $4000! All just by issuing a single call from the commandline. That is such a scary prospect I went into my history and deleted it so that I wouldn’t accidentally call the command again by accident. Actually there was no need to delete it from my history as in order to buy a reservation you need to ask Amazon to “offer” you one (ec2-describe-reserved-instance-offering) and then use the offering id that they specify for the instance type & region you need. Once that offering id has been used it can’t be used again - but I wasn’t about to test that their code worked…
[Read the rest of this entry...]

How to stop Spotify on Linux audio skipping

Spotify is a great application that lets you listen to any music they have (there’s an incredible amount on there) with the odd, almost unnoticable, advert thrown in to pay for the service. It works on windows or mac, but there is no native binaries for linux. Thankfully spotify for windows works under wine just fine - hooray.

However I found that the audio wasn’t great - for me it would skip like a CD skips every few seconds - if it was a CD I would just clean it and throw it in the bin. The reason for this behaviour is found in wine’s audio config - I won’t go into the real reason why, but it is to do with the driver and daemon, etc. Other people have had problems with distortion or just no audio at all.

The solution if you have this problem is to start all your wine commands with padsp and make sure the OSS audio driver is selected. First start winecfg like this:

padsp winecfg

Then go to Audio, find the OSS driver and select that (and unselect anything else selected), hit OK, etc.. Now start your wine apps (inc spotify) like this:

padsp wine "C:\Program Files\Spotify\spotify.exe"

And now my spotify is working just fine!

Recursive Find and Replace in Multiple Files

Just had to make a few changes to a website I own that means changing the same text in lots of files. Linux has lots of powerful tools to enable you to make this kind of change over lots of files over many directories very easily. The command is:

find . -type f | xargs sed -i 's/string1/string2/g'

This is basically two commands. Find will find a list of actual files (-type f, rather than symlinks or directories, etc) in this directory (.) - you could specify particular filenames by adding -iname “filename.ext” before the pipe (|).

Find outputs a list of relative filenames on each line. These are then piped (|) into xargs. xargs is a progam that runs the command that follows it (sed) once for each line of text that it receives, in this case from the pipe, it will run sed once for every filename it receives and place the filename at the end of the sed command.

The sed command is incredibly powerful and well worth learning how to use. sed stands for “Stream Editor” and edits a stream of text as instructed. xargs passes a filename for sed to operate on, then it makes a change inplace (-i), which means it changes the file rather than just outputting the change wherever you ask it to, and then carries out the actual command (’s/string1/string2/g’).

’s/string1/string2/g’ is in quotes to keep the scope clear, s is a command meaning substitute and the s command takes the form s/oldstring/newstring/ which means it finds the text oldstring (can be a regular expression) and replaces it with the newstring text. For each line it finds it carries it out as many times as it finds the oldstring because we’ve set the global option (g), without which it would just change the first instance of oldstring.

Hope someone finds that helpful!

How to temporarily disable the touchpad while typing

In linux if you have a laptop with a trackpad just below the keyboard sometimes you can be typing away and then suddenly you touch the trackpad/touchpad and find your cursor appears elsewhere so you have to stop typing and put the cursor back in the right place. Its a bit of a pain if you’re doing a fair bit of typing especially considering how sensitive these pads can be.

The easiest solution is to temporarily disable the touchpad automatically whenever you type for 1 second. This is easily achievable with the following command in terminal:

syndaemon -d -t -i 1

The number 1 means 1 second and can be adjusted to any integer.

Of course the best thing to do is to make it a task executed at start up so go into preferences | sessions and then add an entry there. The name and description can be anything you want and the command is the command above.