Archive for the ‘Tech’ Category

Flickr Watch

Wednesday, September 10th, 2008

Screen shot from flickr watch

Flickr Watch is some PHP code I knocked up (using the Flickr API, via Dan Coulter’s phpFlickr class) to keep track of various users whose photos I like. It shows the last four photos from each person being tracked, along with a link to their photostream.

Everything is wired into a database for easy addition and removal of users. To keep things simple, users are added by inputting a url that points to any part of their Flickr profile.

It’s a plodding replacement for Flickr’s contacts functionality, and not a very good one at that, but i thought it would be nice to link to it here for posterity’s sake. So, here it is.

Last.fm and Google Charts: Examples

Sunday, August 24th, 2008

Further examples for the Last.fm and Google Charts class. The images on this page are dynamically generated by the class.

All-time listening share of your 15 top artists

$chart1 = new lastfmChart();
$chart1->setDataFile('http://ws.audioscrobbler.com/1.0/user/mister-brown/topartists.xml');
$chart1->setType('pie');
$chart1->setTitle('Top Artists Shares');
$chart1->doChart();

Top Artists Shares

Listening shares of this weeks top 10 artists:

$chart2 = new lastfmChart();
$chart2->setDataFile('http://ws.audioscrobbler.com/1.0/user/mister-brown/weeklyartistchart.xml');
$chart2->setType('pie');
$chart2->setDataPoints('10');
$chart2->setTitle('Weekly Artists Shares');
$chart2->setColors('0000FF');
$chart2->doChart();

Weekly Artists Shares

Total listens of the 8 top artists this week:

$chart3 = new lastfmChart();
$chart3->setDataFile('http://ws.audioscrobbler.com/1.0/user/mister-brown/weeklyartistchart.xml');
$chart3->setType('bar');
$chart3->setDataPoints('8');
$chart3->setSize('400x300');
$chart3->setTitle('Weekly Listens');
$chart3->setColors('CF0F0F');
$chart3->doChart();

Weekly Listens

Number of all-time listens for top 15 artists:

$chart4 = new lastfmChart();
$chart4->setDataFile('http://ws.audioscrobbler.com/1.0/user/mister-brown/topartists.xml');
$chart4->setType('bar');
$chart4->setSize('400x520');
$chart4->setTitle('Top Artists');
$chart4->setColors('00AF33');
$chart4->doChart();

Top Artists

Last.fm and Google Charts

Sunday, August 24th, 2008

Google let you dynamically generate charts and graphs using their Charts API. Last.fm (or more correctly Audioscrobbler) allow you to track your listening habits and then give access to the data via their web services.

Bar chart of last.fm weekly listens

This PHP class combines the two services and allows you to make charts showing your listening habits.

Usage

// include class
include 'lastfmChart.php';

// initiate a chart
$chart = new lastfmChart();

// choose a data source - there's a list at http://www.audioscrobbler.net/data/webservices/#User Profile Data
$chart->setDataFile('http://ws.audioscrobbler.com/1.0/user/mister-brown/weeklyartistchart.xml');

// set type of chart - 'pie' or 'bar' - defaults to pie
$chart->setType('pie');

// set the number of segments or bars - default is 15
$chart->setDataPoints('10');

// set the size of the output image
// defaults to 400x400 for bar, 550x200 for pie; max total number of pixels is 300,000
$chart->setSize('600x150');

// set a title for the chart
$chart->setTitle('Weekly Artist Shares');

// set a colour for the chart - defaults to yellow
$chart->setColors('0000FF');

// output the chart
$chart->doChart();

Results

Pie chart of last.fm top artist shares

Further examples

See some further examples of what is possible with this class.

Download

Download the source for this class.

You are free to take this code, use it and modify it. I’m making no guarantees about the code though, and I wont be held responsible for any consequences of the use or misuse of it. You should read, understand and evaluate what the code does before you implement it yourself. You should also stick to the Google Chart API usage policy, the Audioscrobbler licence and any other applicable terms. If you do use this code, a link back to this page would be appreciated. Have fun!

Apache error log

Wednesday, July 23rd, 2008

Where is the Apache error log?

Under Debian Etch with Apache 2, the error log was at: /var/log/apache2/error.log. You need to be root to view the file.

To view the last few lines of the log (useful – this can get to be a long file), enter:

tail /var/log/apache2/error.log

Enabling mod_rewrite

Wednesday, July 23rd, 2008

Apache’s mod_rewrite is used for changing the way a website URL maps to the underlying file system. It can be used to make URLs more human-readable, and to disguise the underlying workings of a website. For example, you might use mod_rewrite to change http://www.example.com/index.php?post_id=5 to http://www.example.com/5.

URL rewriting isn’t enabled by default if you install Apache on Debian or Ubuntu – this is how to do it.

You’ll need to navigate to /etc/apache2 and obtain root access.

First, create a symbolic link in the mods-enabled directory to the rewrite.load file in the mods-availabe directory:

ln -s mods-available/rewrite.load mods-enabled/

Next, if you are wanting to use .htaccess files to carry out URL rewriting (likely), then you’ll need to let Apache know that it can use the rules in those files. So, edit the appropriate config file:

nano sites-enabled/000-default

Look for the AllowOverride directive , and change it from “None” to “All”.

Finally, you’ll need to restart Apache to make the changes take effect:

/etc/init.d/apache2 restart

CD to FLAC to MP3

Wednesday, July 9th, 2008

I’ve started using FLAC (Free Lossless Audio Codec) when I rip my CDs. FLAC compresses the audio, but no data is lost. Converting from one lossy music format to another isn’t a good idea, but there’s no problem going from lossless to lossy. So when, in 2020, I decide I want my music in mp9 format for my new portable player, I won’t need to dig out all my CDs and rip then again. On the down side, the files are pretty big, but space is cheap these days.

Ripping CDs to FLAC

I use CDex . In the configuration dialogue, choose the Encoder tab. Choose External Encoder and browse for flac.exe in the encoder path. Enter the following in the Parameter string box:

--force-raw-format --endian=little --channels=2 --sign=signed --sample-rate=44100 --bps=16 -8 -V -A tukey(0,5) -o %2 -T "artist=%a" -T "title=%t" -T "album=%b" -T "date=%y" -T "tracknumber=%tn" -T "genre=%g" -

The bitrate option is irrelevant, the file extension is flac. Check Hide DOS box window and On-the-fly encoding. Make sure Send WAV header to stdin is not checked. On the Generic tab, set ID3 tag version to None.

Converting to MP3

FLAC is great, but I still want MP3s for my portable player.

To convert FLAC to MP3, use Frontah. Download and unzip it to a folder. Track flac.exe down and copy it into the Frontah folder. Also download lame.exe and put it into the Frontah folder.

Hat-tips

Setting up dual monitors with Ubuntu

Saturday, May 26th, 2007

Configuring a dual screen setup isn’t as easy in Ubuntu as it is in Windows, but it’s not too much harder. All you need to do is edit a text file and be willing to use a terminal.

The text file we will be editing is called xorg.conf and is the configuration file for the X server. An X server is the program that interfaces between the computer and user, providing input and output functions, so this file is used when tweaking many input and output devices.

First we need to navigate to the directory where xorg.conf can be found. At the terminal, enter:

cd /etc/X11

You can use the ls function to list all of the files in the directory, and see that xorg.conf is there.

Next, make a copy of the current version of xorg.conf. This can be restored to get things working again if things go wrong later. We are working in a protected area of the operating system and so we need to use the sudo command. Enter the following:

sudo cp xorg.conf xorg.conf.backup

Now we can start editing xorg.conf. Ubuntu’s basic graphical text editor is called gedit, so at the terminal type:

sudo gedit xorg.conf

The xorg.conf file will open in a new window.

First look for the section with heading Section "Monitor". Mine looks like this:

Section "Monitor"
Identifier "SDM-S73"
Option "DPMS"
EndSection

Copy this section and paste it just below. Change the identifiers in both sections, so that we have SDM-S73 #1 and SDM-S73 #2. This will give you something like:

Section "Monitor"
Identifier "SDM-S73 *#1*"
Option "DPMS"
EndSection

Section "Monitor"
Identifier "SDM-S73 *#2*"
Option "DPMS"
EndSection

Next, repeat with the section headed Section "Device". This represents your graphics card. Copy and paste, and change the identifiers to add #1 and #2. This time, we also need to add a couple of lines to each section. To both, we need to add the line:

BusID "PCI:1:0:0"

This tells the X server where this graphics card can be found. This is the correct entry for my system, where one NVIDIA graphics card is running both monitors, which is in the only AGP slot on the motherboard. If your setup is different from this and the above is not working, you can discover the bus locations of any of your graphics cards by typing lspci -X at a terminal. Look for those with labels that describe something like your graphics card(s).

In this section, we also need to add a Screen line. To the first copy, add Screen 0; to the second, Screen 1. You should have something along the lines of this:

Section "Device"
Identifier "NVIDIA Corporation NV36.2 [GeForce FX 5700] *#1*"
Driver "nvidia"
*BusID "PCI:1:0:0"*
*Screen 0*
EndSection

Section "Device"
Identifier "NVIDIA Corporation NV36.2 [GeForce FX 5700] *#2*"
Driver "nvidia"
*BusID "PCI:1:0:0"*
*Screen 1*
EndSection

Next, we need to change Section "Screen" part. Again, copy and paste this section. In the first one, change the identifier by adding #1 to the end. You also need to add #1 to the end of the entries for Device and Monitor. In the second copy of this section, do exactly the same, but add #2 to Identifier, Device and Monitor. This should look a little like this:

Section "Screen"
*Identifier "Default Screen #1"*
*Device "NVIDIA Corporation NV36.2 [GeForce FX 5700] #1"*
*Monitor "SDM-S73 #1"*
DefaultDepth 24
SubSection "Display"
Depth 1
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 4
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 8
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 15
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 16
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 24
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
EndSection

Section "Screen"
*Identifier "Default Screen #2"*
*Device "NVIDIA Corporation NV36.2 [GeForce FX 5700] #2"*
*Monitor "SDM-S73 #2"*
DefaultDepth 24
SubSection "Display"
Depth 1
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 4
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 8
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 15
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 16
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 24
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
EndSection

Finally, we need to edit the Section "ServerLayout" part of the file. It needs to specify the positions of the screens, and turn the xinerama option on (this manages dual screens). You need to change this section to read something like the following:

Section "ServerLayout"
Identifier "Default Layout"
*Screen "Default Screen #1"*
*Screen "Default Screen #2" RightOf "Default Screen #1"*
InputDevice "Generic Keyboard"
InputDevice "Configured Mouse"
InputDevice "stylus" "SendCoreEvents"
InputDevice "cursor" "SendCoreEvents"
InputDevice "eraser" "SendCoreEvents"
*Option "xinerama" "on"*
*Option "clone" "off"*
EndSection

When this is done, hit the save button and exit gedit.

Finally, we need to restart the X server to apply the changes. To do this, simply press ctrl+alt+backspace and wait. Hopefully things start up again and you have your desktop spread across two monitors!

What if things go wrong?

If things do go wrong (you’ll see a blue screen with an error message), don’t panic! Things are certainly not beyond repair, in fact you have two options to fix things. First of all, press return a few times to get rid of the error messages and logs and get back to a command prompt. You’ll then need to type your user name and password to log in.

If you are fairly confident using the terminal at this point, you can edit xorg.conf from here. Simply navigate to the /etc/X11 folder, and use the nano editor. This is a basic text editor that you can use to tweak your xorg.conf file. At the terminal, type the following.

sudo nano xorg.conf

Then make some changes, and use ctrl-X to save and exit.

If you’re much happier editing in a graphical interface, we can restore the backup copy of xorg.conf we made earlier. This is also useful if things are so far gone that you want to start again. At the terminal, change directory to /etc/X11. Then enter the following to restore the backup:

sudo cp xorg.conf.backup xorg.conf

When you have either finished editing or have restored the backup, you will need to start the X server up again. To do this, type startx at the terminal and hit enter.