matt-helps

insight on all things techie

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.

Faster internet connection with a local DNS cache

One of the things you can do to speed up browsing and general internet activity is to create a local DNS cache. A DNS is a Domain Name Server and its purpose is to convert domain names to IP addresses. Every time you type in a domain name your computer has to ask a DNS to convert it to an IP address. Occasionally a website’s IP address will change so you can’t store an IP address forever, but it is worth cacheing it locally, even just for 24 hours or so considering the number of times we hit some sites during the day.

In Ubuntu (and debian, and other flavours of linux, though this tutorial is written for ubuntu) we can install a little helper application to cache the DNS results for a time and thus speed up our internet experience in general! It is called dnsmasq and the first step is to install it:

sudo apt-get install dnsmasq

Then at the terminal we need to edit the config file:

gksudo gedit /etc/dnsmasq.conf

Then find the line that says “#listen-address” and remove the leading # (if there is one) and make it say:

listen-address=127.0.0.1

Save and exit. Now edit /etc/dhcp3/dhclient.conf:

gksudo gedit /etc/dhcp3/dhclient.conf

Edit the line that says “prepend domain-name-servers” to say:

prepend domain-name-servers 127.0.0.1;

or if you want to use OpenDNS.org’s DNS servers (which I recommend) then change that line to:

prepend domain-name-servers 127.0.0.1, 208.67.222.222, 208.67.220.220;

Now at this point if you were to get a new IP lease it would all work, but that’s a bit of hassle so lets make it work now without rebooting the hardware. Edit /etc/resolv.conf:

gksudo gedit /etc/resolv.conf

Insert the following line at the top of the nameserver list:

nameserver 127.0.0.1

Finally we need to restart our little utility to take into account the new settings:

sudo /etc/init.d/dnsmasq restart

Now it is time to test it! At the terminal type:

dig news.bbc.co.uk

…and take note of the query time. Then run the same command again and note the improvement. You should be looking at around 2ms for the 2nd time whereas the first one will be dependant upon your internet connection – for me it was about 50ms – so for me this makes the DNS query portion of browsing about 25 times quicker. Enjoy.

Using Alien to convert .rpm packages to lpia .deb

Alien is a nice little linux utility that converts .rpm software packages to .deb packages so that you can install software packaged for Red Hat on Debian and Ubuntu, etc.  Clever.  But for those of us on the lpia architecture (like the dell mini 9) we require those .deb files that Alien spits out to have their “architecture” setting to be lpia, not the i386. There is no way to change it from the command line so you’re left with a .deb package that either won’t install or can be forced to install but then won’t uninstall.  You could of course unpack, edit the control file and then repack the .deb file, but there is an easier way.

Install alien if you haven’t already:

sudo apt-get install alien

Then ask alien to generate the build tree without actually building the package itself:

alien -g filename.rpm

This creates a build tree that is turned into an lpia .deb package once we’ve made a change to the control file as before.   Edit debian/control using your favourite text editor and modify the line that specifies the architecture so that it now says:

Architecture: lpia

And then in the directory that contains the folder “debian” run:

debian/rules binary

That will create a .deb file which you can then install either through the usual GUI methods or by calling:

dpkg -i filename.deb

And of course because you’ve installed it using the right architecture you’re also able to uninstall it should you need to.  Hooray.


Follow mattparkins on Twitter