Monday, 8 June 2009

Quick tips for Ubuntu 9.04

One of the beauties of starting your OS afresh is, well, you get a new and better OS. Ubuntu 9.4 (or 'jaunty jackalope') is a slick version of my previous Ubuntu 8.04 ('hardy heron'). So far, I've ascertained that it looks better, it has better support for hardware, and it boots really fast.

One of the pains of starting your OS afresh is having to reinstall all your software and set your preferences. I thought I'd put a little 'as I do it' guide which may take some of the pain away. This list has a few of the 'biggies' and maybe a couple of items more suited to my personal taste, but what the hey!

1. configure the firewall
sudo apt-get install gufw

2. install wine (windows emulator, for those windows programs you cant live without - an ever decreasing number horray!)
sudo apt-get install wine

3. This one is crucial if you want to run java - it takes ages, and at the end when it installs java, you need to be able to use the tab and 'pg dwn' keys to get to the end of the license agreement
sudo apt-get install ubuntu-restricted-extras

4. VLC is still the best media player around
sudo apt-get install vlc

5. skype -
sudo wget http://www.medibuntu.org/sources.list.d/jaunty.list -O /etc/apt/sources.list.d/medibuntu.list

wget -q http://packages.medibuntu.org/medibuntu-key.gpg -O- | sudo apt-key add - && sudo apt-get update

sudo aptitude install skype

6. Google Earth (version 5) - install the binary from here. Right click - Properties - Permissions - make executable. Then double click, and it will install - easy! It will create a desktop icon which, by default, you cannot see because you do not have permission. In the terminal type (here, replace 'daniel' with your username):

cd ./Desktop
sudo chown daniel:daniel Google-googlearth.desktop

7. Expand the capabilities of nautilus file browser

sudo apt-get install nautilus-actions nautilus-gksu nautilus-image-converter nautilus-open-terminal nautilus-script-audio-convert nautilus-script-collection-svn nautilus-script-manager nautilus-sendto nautilus-share nautilus-wallpaper

8. Adobe AIR

wget http://airdownload.adobe.com/air/lin/download/latest/AdobeAIRInstaller.bin
chmod +x ./AdobeAIRInstaller.bin
./AdobeAIRInstaller.bin

9. Adobe acrobat reader

sudo gedit /etc/apt/sources.list

Add the below line in sources.list

deb http://archive.canonical.com/ubuntu jaunty partner

sudo apt-get update
sudo apt-get install acroread

G'night!

Sunday, 7 June 2009

Never do this

 sudo mv filename.file /bin/sh  


Just don't mess with your bin/sh, and secondly don't attempt to restart your computer after you mess with your /bin/sh (which is the symbolic link to /bin/dash - low level crazy stuff which ordinarily you shouldnt ever know or care about, but which ensures your computer can do some vital things, like initialise).

This I discovered to my cost, and now I'm having to spend my weekend recovering all my files

This is a worrying and heartbreaking exercise, as I'm sure you'll understand - my computer is my livelihood and most of my hobbies, and I havent backed stuff up for ages, and recently I've been doing some cool stuff which exists only on the computer which now needs a complete OS overhaul!!

I'm writing this for instruction and warning rather than pity, you understand. You can't reboot, not even in any safe mode. I did a bit of internet forum research, and there was little guidance (mostly, instructions for windows users to use Ubuntu to recover their files, but not Ubuntu users to recover their files)

It turns out it's thankfully simple.

1. download an Ubuntu distro iso, and burn it to CD (instructions here and here)
2. place in optical drive of bummed out computer, and use BIOS to instruct it to boot from disk
3. select option to 'try Ubuntu without installing it on your computer' (or whatever the exact wording is - should be the first option in most versions)
4. then wait for it to boot - the OS running from the CD can recognise your hard-drive, but won't let you automatically access it. Open a terminal and type the following (assuming you want to access drive sda1 - you may want sdb1 or something):

 sudo mkdir /media/ubuntu  
sudo mount -t ext3 /dev/sda1 /media/ubuntu


for ease of copying and later access, change the permissions to all directories so anyone can have read/write privileges:

 sudo su  
chmod 777 -R /media/ubuntu


this will take a while if you have a lot of files and directories, but when it's done you're ready to plug in a large external hard drive, and save your precious files away - exactly what I'm doing now! The next step will be to reinstall ubuntu (I'm going to go for the latest - 9.04) and spend weeks reinstalling all my software and getting it to my specification - weeks I really don't have!

Friday, 5 June 2009

Flower Bed

Recently I investigated Apollonian gaskets (a type of space-filling fractal composed of ever-repeating circles) for use as 'pore-space fillers' in a model I am creating for synthetic sediment beds. I came across a most excellent script here:

http://www.mathworks.com/matlabcentral/fileexchange/15987

In my Friday afternoon boredom, I have just modified some aspects of the program to create a function which simulates a pretty flower bed Some example outputs below - enjoy! Right, now back to work ...






Thursday, 16 April 2009

Frequency Transforms on Images

As part of my work, I have to do a lot of spectral analysis with images. Traditionally I have used MATLAB to do this - it is exceptionally easy and powerful, and works just fine. As a simple example, if I want a power-spectrum of an image, treated as a 2D matrix of 8-bit numbers, the sequence of commands is this:

 %------------------- MATLAB  

% read image in, convert to greyscale and double-precision
image=double(rgb2gray(imread('myimage.jpg')));
% crop to smallest dimension
[m,n]=size(im);
im=im(1:min(m,n),1:min(m,n));
% find image mean
imMean=mean(im(:));
% and subtract mean from the image
demean=im-imMean;
% find the 2D fourier transform
ft=fft2(demean);
% power spectrum is the element-by-element square of the fourier transform
spectrum=abs(ft).^2;


Seven lines of commands. Couldn't be simpler. That's the beauty of MATLAB. The snag is that it costs several hundreds to thousands of dollars for the program, which makes it difficult to share your code with other people. So recently I've thought about coding up some things I want to share with other people in Python.

Python is a cross-platform, open-source programming language and environment. It is not too dissimilar to MATLAB in many respects, especially when you install the right libraries. In order to do the same in Python as above, as easy as possible, I needed to install Python Imaging Library (PIL),  NumPy and SciPy. Then the sequence of operations is as follows:


 # ----------------PYTHON  

#-----------------------
# declare libraries to use
import Image
import scipy.fftpack
from pylab import*
import cmath
from numpy import*
# load image, convert to greyscale
im=Image.open('myimage.jpg').convert("L")
# crop to smallest dimension
box=(0,0,im.ny,im.nx)
region=im.crop(box)
# find mean
imMean=mean(asarray(region))
# 2D fourier transform of demeaned image
ft=fft2(region-imMean)
# power spectrum
spectrum=pow(abs(ft),2)


Same answer. Not bad - not harder, just different. And completely free. Oh, and this'll work on UNIX, Linux, Mac, and PC when Python is installed (with a couple of extra libraries). Great! 

Hmm, I thought, I wonder if it is possible to do the same in a piece of non-numerical software. I tried ImageMagick because its free and ubiquitous on Linux and Mac, and also available for PC, and it has a massive user-community. It is incredibly powerful as a command-line graphics package - even more powerful than PhotoShop and Illustrator, and like all UNIX-based applications, infinitely flexible. It turns out it is a little more tricky to calculate the power spectrum in ImageMagick, but here's how.

First, you need the right tools - ImageMagick is usually already present on most Linux distributions - if not, if a debian/Ubuntu user use sudo apt-get install imagemagick, or download from the webiste hyperlinked above. Then you'll need an open-source C-program for calculation of FFTs: this is provided by FTW - download fftw-3.2.1.tar.gz, untar, cd to that directory, then install the binary by issuing the usual commands:

 ./configure  

sudo make && make install


This C-program is no good on its own, so the last ingredient is a wrapper for ImageMagick. Fortunately - nay, crucially, this has been provided by Sean Burke and Fred Weinhaus - introducing IMFFT! The program can be downloaded and installed from here. And here is an in-depth tutorial of how to use it (I'm only just getting to grips with it myself). For some reason the compiled program is called 'demo'. I move it to my /bin directory so my computer can see it wherever I am working, and in the process change the name to something more suitable - fft:

 cp demo ./fft && sudo mv ./fft /bin  



Right, it's a little bit more involved, but here is the bash shell script for the power spectrum in ImageMagick:

 #----------------------------- IMAGEMAGICK  

#-------------------------------------------------
#!/bin/bash
# read image and convert to greyscale
convert myimage.tif -colorspace gray input_grey.tiff
# find min dimension for cropping
min=`convert input_grey.tiff -format "%[fx: min(w,h)]" info:`
# crop image
convert input_grey.tiff -background white -gravity center -extent ${min}x${min} input_grey_crop.tiff
# de-mean image
# get data
data=`convert input_grey_crop.tiff -verbose info:`
# find mean as proportion
mean=`echo "$data" | sed -n '/^.*[Mm]ean:.*[(]\([0-9.]*\).*$/{ s//\1/; p; q; }'`
# convert mean to percent
m=`echo "scale=1; $mean *100 / 1" | bc`
# de-mean image
convert input_grey_crop.tiff -evaluate subtract ${m}% ggc_dm.tiff
# pad to power of 2
p2=`convert ggc_dm.tiff -format "%[fx:2^(ceil(log(max(w,h))/log(2)))]" info:`
convert ggc_dm.tiff -background white -gravity center -extent ${p2}x${p2} ggc_dm_pad.tiff
# forward fast fourier transform
fft f ggc_dm_pad.tiff
# creates ggc_dm_F_Q16.tiff, on which get spectrum
convert ggc_dm_F_Q16.tiff -contrast-stretch 0% -gamma .5 -fill "rgb(1,1,1)" -opaque black ggc_dm_F_Q16_spec.tiff


Voila! The spectrum is the image 'ggc_dm_F_Q16_spec.tiff'. I haven't yet worked out how to keep all the data inside the program, to eliminate the need (and cumulative errors associated with) writing the outputs at every stage to file, and eading them back in again. This means I can't use the spectrum for any scientific application. But in theory it should be possible. Any suggestions welcome!

Saturday, 28 February 2009

Shannon's Box

Claude Shannon, father of information theory, apparently once invented a box whose sole purpose was to, when switched on, turn itself off again. Recently I've got into scripting with CHDK (Canon Hackers Development Kit) - a firmware enhancement for Canon cameras. It allows you to turn your cheap point-and-shoot camera into something better, for free. Long exposures, very rapid shots, motion detection - you name it. I can tell I'm at the start of a beautiful friendship ... look at this!

You can write and upload scripts to automate processes. The language is uBASIC - really intuitive and easy. My first script is pretty basic - it has been to tell the camera to, when switched on, automatically take 3 photos and then turn itself off! I therefore called it Shannon's Box:

 rem Author Daniel Buscombe  
@title Shannon's Box
@param a Shoot Count
@default a 3
shoot full
for n=2 to a
shoot full
if n=a then goto "shutdown"
next n
end
:shutdown
shut_down


More, I'm sure, on CHDK in the following months.

Wednesday, 25 February 2009

Ubuntu Beautification

Tip #1:

It's amazing really - most fonts contain within them “hints” laid down by their designer about how they should look on-screen. Artistic meta-data! However, Ubuntu ignores them and uses a system called 'autohinting'.

It works well, but you might also want to try bytecode hinting. This uses the hinting built into the fonts. To activate bytecode hinting, open a terminal window and type:

$ sudo dpkg-reconfigure fontconfig-config

Using the cursor keys, select Native from the menu and then hit Enter.

On the next screen you’ll be asked if you want to activate subpixel rendering. This is good for TFT screens, so make the choice (or just select Automatic). Next you’ll be asked if you want to activate bitmap fonts, which are non-true type fonts good for use at low point levels. There’s no harm in using them, so select yes. The program will quit when it’s finished. Once that’s happened, type the following to write the changes to the system and update files:

$ sudo dpkg-reconfigure fontconfig
$ sudo dpkg-reconfigure defoma

System - Quit - Logout, and then log back in again. Letters will appear more rounded and the antialiasing will appear better.

Tip #2:

465 fonts of Brian Kent (http://www.aenigmafonts.com) are available to Ubuntu users. To install the fonts, you’ll need to add a new software repository:

System - Administration - Software Sources
- Third-Party Software tab - Add

type the following into the dialog box that appears:

deb http://ppa.launchpad.net/corenominal/ubuntu hardy main

Click 'Add Sources', then Close and, when prompted, agree to reload the package lists. Then use Synaptic to search for and install the 'ttf-aenigma' package. Once installed the fonts will be available for use straight away in all applications.

Enjoy your beautified Ubuntu!

How to get on youtube, twitter and myspace quicker

Well, the easiest way is save time when you boot your computer!

Whenever Ubuntu boots it runs several scripts that start necessary background services. By default these are set to run one-by-one but if you have a processor with more than one core, such as Intel’s CoreDuo series or AMD’s Athlon X2, you can configure Ubuntu to run the scripts
in parallel. This way all the cores are utilized and quite a bit of time can be saved at each boot. To make the change, type the following to open the necessary configuration file in Gedit:

$ gksu gedit /etc/init.d/rc

Look for the line that reads CONCURRENCY=none and change it so it reads CONCURRENCY=shell.

Then save the file and reboot your computer. This should save you several seconds of time every time you boot up, and you can go on being a handsome speedy devil

Every pixel tells a story

Recently the Daily Daniel ran a story (hark at me! I'm not The Times!) with a single photograph - a mosaic - each 'pixel' containing a separate photo. I've finally got round to explaining how it is done, if only to show that I didn't arrange the pictures manually - she is beautiful, admittedly, but I gotta work to eat!

Right, the Linux program is called 'metapixel' and is downloaded from here. If you've enough photographs, you can produce some incredible results

You need to issue 2 commands - one prepares the photos, then the other makes a mosaic out of them. Create a folder somewhere to store the prepared photos called, say, 'recast'

$ metapixel-preparee -r /directory/where/photos/are /directory/recast --width=40 --height=40

The larger the width and height, the longer it takes. Be sure to get the aspect ratio of the photos right - it doesnt check or automatically correct. Choose a single photo that you want to make a mosaic out of (e.g. /directory/in.png), then (be warned, this may/will take several hours for a big photo!):

$ metapixel /directory/in.png --library /directory/recast --scale=5 --distance=5

The scale tells it how big you want the output (i.e. here 5 x size of input image), and the distance tells it how far to look for matches - it matches by colour so its a really good idea to scale by the range of inputs. It will give you an error if the distance parameter is too large. The results can be mixed, but once you hone the inputs and parameters down, and you have a LOT of patience, you can get some really great mosaics!

Friday, 13 February 2009

Tweetdeck on ubuntu 64-bit

Right, the whole world's into twitter. The website is a little difficult to manage when you have a lot of people to follow. The software solution (isn't there always one!) is TweetDeck - unfortunately it runs under Adobe Air, which (surprise, surprise) is available for Linux but 64-bit architectures. So your computer requires a little bit of persuading ...

... you need a few libraries - issue the following commands at the terminal:
$ sudo apt-get lib32asound2 lib32gcc1 lib32ncurses5 lib32stdc++6 lib32z1 libc6 libc6-i386
$ sudo getlibs -l libnss3.so.1d
$ sudo getlibs -l libnssutil3.so.1d
$ sudo getlibs -l libsmime3.so.1d
$ sudo getlibs -l libssl3.so.1d
$ sudo getlibs -l libnspr4.so.0d
$ sudo getlibs -l libplc4.so.0d
$ sudo getlibs -l libplds4.so.0d
$ sudo getlibs -l libgnome-keyring.so
$ sudo getlibs -l libgnome-keyring.so.0
$ sudo getlibs -l libgnome-keyring.so.0.1.1
$ sudo ldconfig

Then install Adobe Air from here

download, then move to your home directory,

right click - properties - make executable

and type

$ chmod +x AdobeAIRInstaller.bin
$ sudo ./AdobeAIRInstaller.bin

Then grab the 'air' file from here, and install using Adobe Air

Happy tweeting!

Monday, 9 February 2009

Miscellaneous stuff of use

The documentation on the use of 'wget' is a little sketchy on one of its most powerful uses - automatically downloading loads of files from internet servers. Let's say you need the 1000 tiff files sitting at http://www.server.com/hypothetical_directory

Apparently wildcards are out, such as:

$ wget http://www.server.com/hypothetical_directory/*.tiff

because html does not support 'globbing'. So here's the solution:

$ wget -r -1l --no-parent -A.tiff http://www.server.com/hypothetical_directory

%----------------------------------
Another thing I've needed to do recently is get ALL the metadata from an image file - you wouldn't believe how much information is recorded - channel statistics, histogram of shades, date/time, camera make, resolution - you name it, its recorded. It's a wonderful thing about using images for your research as well - you can keep track of all your metadata in the data files! Right, well I discovered that no amount of 'right-clicking' on the image - in any operating system - will tell you everything you need to know. The suitable command is:

$ identify -verbose myimage.jpg

%------------------------------------
Finally, for now, a couple of sites that will help you if you need to make a purchase of hardware for your linux machine:

This one keeps a database of usb-devices which are known to be linux-friendly, and the following two help you out when choosing a compatible printer and scanner: here and here.

Keep on truckin'

Friday, 16 January 2009

How to read and search your blog page with the imaginative use of the 'regexp' in matlab

Just a quickie - there may be some application for this (?)

You start with your blog url:

>> url='http://thezestyblogfarmer.blogspot.com/';

read it in, then you can start searching through its contents:

>> text=urlread(url);

for example, I can list all the unix commands I have mentioned - its easy because they all start with a dollar sign

>> text_linux=regexp(text,'>\$[^<\r\n]*<','match')' which gives me the output:

'>$ sudo apt-get update<' '>$ sudo apt-get upgrade<' '>$ sudo apt-get clean<' '>$ sudo apt-get autoclean<' '>$ sudo apt-get -f install<' '>$ sudo badblocks -v /dev/sda1<' '>$ sudo aptitude install debsums<' '>$ debsums <' '>$ sudo apt-get install firestarter<' '>$ sudo apt-get install youtube-dl<' '>$ youtube-dl http://uk.youtube.com/watch?v=r9OjoPskf_c<' '>$ ffmpeg -i r9OjoPskf_c.flv people_everyday.avi<' [1x97 char] '>$ sudo su | sudo apt-get install skype<' '>$ sudo jhas -jh 837afm$^&qeiuhn>>KOUUIG4n we8f-&hcjku8hujbn ok?<' '>$ sudo su | python setup.py install<' [1x75 char] '>$ sudo dpkg -i skysentials_1.0.1-1_all.deb<' '>$ konsole<' or maybe the matlab commands which all start with 2 > signs:

>> text_matlab=regexp(text,'>\>>[^<\r\n]*<','match')'

'>>> cf=0; %current frame<' '>> for k=10:50 % identity matrix from [10,10] to [50,50]<' '>> clf;<' '>> plot(fft(eye(k))) %plot<' '>> axis equal; axis off; axis([-1 1 -1 1]); % sort out axes<' '>> pause(0.01) %take a break<' '>> cf=cf+1; %update current frame<' [1x87 char] '>> end<' [1x94 char] '>>KOUUIG4n we8f-&hcjku8hujbn ok?<' '>>> convert my_image.jpg -resize 200% my_new_image.jpg<' '>>> direc=dir([pwd,filesep,'*.','jpeg']);<' '>>> filenames={};<' '>>> [filenames{1:length(direc),1}] = deal(direc.name);<' '>>> filenames=sortrows(char(filenames{:}));<' '>>> mkdir([pwd,filesep,'james_and_the_giant_peach'])<' '>>> mkdir([pwd,filesep,'thumblina'])<' '>>> for i=1:size(filenames,1)<' '>>> system(['convert ',deblank(filenames(i,:))...<' '>>> system(['convert ',deblank(filenames(i,:))...<' '>>> end<' '>>> url='http://www.mathworks.com/moler/ncm.tar.gz';<' '>>> gunzip(url,'ncm')<' '>>> untar('ncm/ncm.tar','ncm')<' '>>> cd([pwd,filesep,'ncm'])<' '>>> [U,G]=surfer('http://www.thedailydanielblog.blogspot.com',200);<' '>>> fid=fopen('dansweb.txt','wt');<' '>>> for i=1:size(char(U),1), fprintf(fid,'%s\n',char(U(i,:))); end<' '>>> fclose(fid)<' '>>> pagerank(U,G)<' and finally how to list the websites you refer to - I can't post the code into my blog because it involves html code which blogger doesn't like - replace '>\>>' with '< [the first letter of the alphabet] href'


enjoy!

The big clean

One of the beauties of a Linux system is that it is so easy to keep current. The software's free, and it tells you automatically if there are upgrades available. I probably upgrade my ubuntu hardy heron (8.04) OS every couple of days!

It's just as easy to clean, so there isn't loads of junk lying about everywhere - a problem which just kills windows machines after a while. I've had this OS since it came out (on the 4th month of 2008, hence 8.04) so I thought it was high time to have a bit of, well considering the decent run of weather we've been having here, a spring clean

First, how to upgrade and clean up the software packages. This is a crucial step for someone like me who spends a lot of time downloading and checking out new software

$ sudo apt-get update

$ sudo apt-get upgrade (the only thing I installed was 'replacement guidance-backends' - whatever they are!)

$ sudo apt-get clean - this removes cached packages, to free up disk space

$ sudo apt-get autoclean - this deletes partially downloaded packages and various bits of computer detritus

$ sudo apt-get -f install - this does a check for packages which might have broken whilst you tried to install them

This next bit takes much longer - it checks for 'bad blocks' on your hard drive - its like the 'disk defragmenter' tool in newer versions of Windows. Basically, it checks your disk (mine is /dev/sda1 but yours might be something else - run 'fdisk' to find out) for physical defects

$ sudo badblocks -v /dev/sda1

Now I don't know about you but I have some software which crashes a lot, or just doesn't seem to work at all. Run these commands if you're worried about malicious software or corrupt pacakges

$ sudo aptitude install debsums - this will install the necessary package 'debsums'

$ debsums - this will run the check (warning - if your computer is as full as mine, this will also take a very long time - allow an hour or so)

Linux doesn't suffer heavily from internet viruses and malware/spyware, but it is known for even linux machines to become infected and it is becoming more common. So here's how to install a firewall (on ubuntu):

$ sudo apt-get install firestarter - firestarter is a fancy interface to the more general linux 'iptables' program. To see whether your firewall is configured type sudo iptables -L into a shell. If the output doesn't have a list of rows starting with 'ACCEPT', it is not configured.

Then go to System>Administration>Firestarter - follow the options easy peasy! Make sure when it first starts to select the option, under 'Preferences', 'minimise to tray on close'

The firewall will run in the background and monitor and do what it does when you're surfing the web. To activate the firewall, type 'firestarter' into a shell before you browse

Ok - cleaned, defragmented, firewalled. And drought over! Man, that was rather professional!

Wednesday, 26 November 2008

Youtube karaoke

Ok - here's how to do karaoke to your favourite video track, and publish the results on your blog

First, you need to get the video. Youtube will have it, guaranteed. There's a neat little linux package you can install to download youtube videos:

$ sudo apt-get install youtube-dl

Then go to youtube, and find the url. I chose 'people everyday' by arrested development - an oldy, but a classic, and its something I knew the words to. Then get it:

$ youtube-dl http://uk.youtube.com/watch?v=r9OjoPskf_c

It will download a 'flv' (flash) format video called the last part of the url - in this case 'r9OjoPskf_c.flv'

This next part isn't strictly necessary, but for ease of future access you may want to rename it, and also get it into some format understood by pretty much everything, e.g:

$ ffmpeg -i r9OjoPskf_c.flv people_everyday.avi

Then you need to record your soundtrack. I found the easiest way to do this was to use a linux tool called 'sound recorder'. Applications - Sound/Video - Sound Recorder. just open a new file and press record - simple!

Oh, but its a good idea to open your video exactly when you press 'record' - to get background and timings

Then when you finish press 'stop'. save it - e.g. 'people_everyday.mp3'

Then use mencoder to mux the mp3 and avi file together, like so:

$ mencoder people_everyday.avi -o output.avi -ovc copy -oac copy -audiofile people_everyday.mp3

Your output file 'output.avi' is ready to go onto your blog - like so!

Happy thanksgiving!

Sunday, 23 November 2008

Fourier transform of an identity matrix

... and how to get your matlab plots into animated gifs, and into your blog!

I noted the other day that the fast fourier transform of an identity matrix can look really cool when plotted, and that stringing matrices of increasing size along in an animation looked really cool.

So when it came to sharing it this morning I came across a little fault in blogger which means that you can't directly load animated .gif files into your blog posts. The solution is to upload your image onto the web, get the html for the link, and embed that into your blog post. I used Tinypic - uploaded the image, and embedded the html code here:

Image and video hosting by TinyPic


Here's the matlab code for the animation

>> cf=0; %current frame
>> for k=10:50 % identity matrix from [10,10] to [50,50]
>> clf;
>> plot(fft(eye(k))) %plot
>> axis equal; axis off; axis([-1 1 -1 1]); % sort out axes
>> pause(0.01) %take a break
>> cf=cf+1; %update current frame
>> saveas(gcf, sprintf('frame%d', 1000+cf), 'jpg') %save the current frame as a jpg
>> end

This next bit of code tells the operating system (the bang command, !) to use the unix program 'convert' to make an animated gif out of all of those frames (i've set it to compress and downsize by half to save on file space)

>> !convert -antialias -loop 1000 -delay 5 -geometry 50% -compress LZW frame10* ffteye.gif

Gif creation is my new favourite toy - watch out Daily Daniel!

Saturday, 15 November 2008

Welcome

Welcome to my new site, the Zesty Blogisty. It is a companion site to my main blog, The Daily Daniel

Zesty is intended for my ramblings on operating systems, computer programming, and other geeky stuff that takes my fancy. It's designed not to clog up the 'Daniel with rubbish I want to get off my chest but no-one wants to read!

So I've moved some posts from the 'Daniel to the Zesty and, like joey ramone once said, hey ho, let's go!

The ups and downs of skyping with Linux

Originally posted in The Daily Daniel
----------------------------------------

Having recently moved to the USA, my need to communicate cheaply with people back home has meant that I have subscribed to Skype which allows me to call people through computers for free, or to landline or mobile phones at discounted rate.

I use linux because my computer is my toy and, in many respects, my livelihood. Linux is a much more fun and much more powerful operating system because it grants you, at least in principle, more control over the operation of your computer (which is usually unseen and unreachable on windows systems) through commands made in a terminal. Scientific computing is easier and much wider in scope if you know a few basic linux commands. Almost everything in linux is obfuscating, but learning its ways is enormously satisfying. All linux computing is completely free, as it should be.

Being a linux user, however, means that new software like skype are either generally unavailable because they are proprietary, or because the software developers don't choose to make them available to linux users because they represent a small fraction of computer users. Not only was I very glad to hear, then, that skype was available for linux, but that it even dealt with my 64-bit architecture (which has given me all sorts of problems installing drivers and other software, but I won't go into that ...). So I installed skype with no problems:

$ sudo su | sudo apt-get install skype

And it worked fine. So the next thing I did was buy a webcam. I had one delivered through amazon. None of the cheap ones said they were linux compatible, but i through caution to the wind, and got myself one for 31 dollars.

Of course, it came with a cd with windows drivers, and nothing else. After a couple of hours trawling through the web I sort-of semi installed the drivers for it, using the usual linux user forums. Initially, I couldn't get anything to work properly with it - I tried numerous programs (cheese, camorama, XawTV, MoviePlayer, VLC ...). Eventually I got VLC and camorama do work with it. Don't even ask me how now - i remember just applying my usual tenacity to it, and slamming my monkey fists into the keyboard until i hit the right combination of letters and symbols which would tell the program I had a camera, where it was, and what drivers it needed. It probably looked a little something like this (or equally as hideous)

$ sudo jhas -jh 837afm$^&qeiuhn>>KOUUIG4n we8f-&hcjku8hujbn ok?

Right, so after I wiped the blood of the monitor I turned to skype. Crap - skype for linux ''currently doesn't support webcams'' -aaaargh!!! Ok, fine, I can still call and I can text message? No. Skype for linux "currently doesn't support sms messaging". Great - so I can't even txt message. All windows and mac skype users can txt message. Macs run on a LINUX KERNEL and they can txt message!!! The skype developers obviously just cant be bothered to write the code necessary. Or maybe they think that all linux users only have nerdy friends, who are all messaging each other over the internet because thats where they spent 99% of their lives. Erm, no comment

There's nothing quite like skype thats free and open source. So, I went back to the forums, going on the assumption that it must be possible, and that some wonderful person would have either figured a way to crack into the program and unlock the functionality to txt message, or written a new program to interface with skype and allow it to be able to send text messages.

Unlikely as it sounds, and the reason why I make this post, is because not only someone has, but it works. IT WORKS!!! Ha ha ha ha ha in your face! I know this is sad but I'm so happy with this result - i feel like the little orphan boy born with no opportunities and no hopes, who happens to stray across a wadge of bank notes, unsighted, in the dirty street. They have fallen out of a passing carriage. There's a massive grin across my grubby little urchin face. IThere's another eason for my post - to sing the praises of those geeks who toil for hours writing these impenetrable programs, and upload them onto the web for everyone to use.

Next time you see a computer nerd, give him a little squeeze for me.

Don't get me wrong, the solution isnt perfect. Its a little clunky and temperamental, but its all we have and i found it and it works! Ok, so this is what you do: there are two things to download and install. The first is a program language written in python which allows links to skype to be made, and interfacing from the command line. You download it from here. Downlaod the tarball named 'Skype4Py-1.0.29.0.tar.gz', untar it into a directory somewhere (like your desktop), then in the terminal make that directory your working directory and type:

$ sudo su | python setup.py install

It basically allows you to, within python, talk to the skype program and, if your clever enough, get it to do things for you. I tried to write a couple of rudimentary python scripts to do stuff with it, but it would have basically meant learning a new coding language, which I'm not really prepared to do just to send a few txt messages! Turns out I dont have to because someone called Rafael Laboissiere has already done it. As explained here, you install the 'skysentials' program easily:

$ wget http://alioth.debian.org/~rafael/skype/skysentials_1.0.1-1_all.deb
$ sudo dpkg -i skysentials_1.0.1-1_all.deb

Then, open a konsole (if you havent got konsole type # sudo apt-get update, then #sudo apt-get install konsole) by typing

$ konsole

Then open 2 windows. As superuser, type # skype in one - skype appears, and you sign in as per usual. In the other window, type #skysentials. A gui appears which allows you to send texts via skype, working out the cost automatically. Brilliant!

to skype software developers - is this capability latent within skype for linux, and if so why hasnt it been unlocked for users?

to rafael and the developers of skype4Py - you really are clever and unsung, thank you

and to everyone else, goodnight and happy texting, whatever OS you use ...

in 5 minutes, for free (or 'balanced restored')

Originally posted in The Daily Daniel
--------------------------------------

People have said to me words along the lines of "why do you both with linux? it seems as though all it ever gives you is problems blah blah blah ..." - i don't know, I never listen to the rest. Yes, I do moan about linux a lot, and even in these pages ... well here's just 1 example of some routine thing I wanted to do where linux came to the rescue. I did it in 5 minutes

I had a folder full of pictures, and I wanted to make 2 copies of each - one a fraction of the size (for a thumbnail gallery), and one loads bigger - the images were smaller than the CCD used to capture them, so I knew I couldnt alias them. Right, well there's a linux command which does the job called 'convert'. Quick, really simple to use, e.g.:

>> convert my_image.jpg -resize 200% my_new_image.jpg

Does exactly what it says on the quick drying woodstain. But how to do the whole folder in one go? My old friend matlab comes to the rescue, and my personal favourite command 'system' - this bit of code will read in a folder of images, create 2 new folders, copy and resize each image, save it in the correct folder and append the file name with the operation done to it. All in the time it takes you to sneeze.

% find all the jpegs in the folder
>> direc=dir([pwd,filesep,'*.','jpeg']);

% create an empty cell to stick them in
>> filenames={};

% deal inputs into outputs
>> [filenames{1:length(direc),1}] = deal(direc.name);

% sort them and turn them into character arrays
>> filenames=sortrows(char(filenames{:}));

% make 2 directories - one called 'james_and_the_giant_peach' and one called 'thumblina'
>> mkdir([pwd,filesep,'james_and_the_giant_peach'])
>> mkdir([pwd,filesep,'thumblina'])

% simple loop
>> for i=1:size(filenames,1)

% giant images (500% size)
>> system(['convert ',deblank(filenames(i,:))...
,' -resize 500% ./james_and_the_giant_peach/',deblank(filenames(i,:)),'_giant.jpeg'])

% thumbnail images (20% size)
>> system(['convert ',deblank(filenames(i,:))...
,' -resize 20% ./thumblina/',deblank(filenames(i,:)),'_thumb.jpeg'])

>> end

Another example where matlab and linux combine beautifully. Matlab would have done it on its own (using imresize and imwrite commands), but it would have taken considerably longer.

Today is Boomtime. Good night

Dollars and Pounds

Originally posted in The Daily Daniel
-----------------------------------


just for interest

LaTeX equations in Blogger posts

Originally posted in The Daily Daniel
___________________________


Well, I know you are burning to know this one (!) Fetch the code directly from CodeCogs site and use in your website following this link

It uses beautiful

typesetting to create an image, which you embed in your blog posting. For example, the continuity equation for water waves:



Voila! Hope that's clear

CodeCogs - An Open Source Numerical Library

A tour through home 'pageranking' - try it yerself!

Originally posted in The Daily Daniel
_____________________________

Now I live in the foothills of silicon valley, I thought I'd write a piece on one of its most famous and useful and revolutionary spawns, Google, and specifically it's PageRank algorithm. This is the piece of code which Google Search engines use to find webpages that are most relevant to your enquiry, and rank them so the most relevant are near the top. Its a bloody marvel, as we all know (remember the bad old days using old lycos and yahoo searches etc - pah!)

Instead of writing stuff on it, which has been done elsewhere numerous times, I thought I would show you how to do it using Matlab

First, you need to get the code. Cleve Moler at Mathworks has written a library which contains a primitive attempt at the proprietary algorithm. You need to get it, unzip it and untar it. This can all be done within Matlab, like so:

>> url='http://www.mathworks.com/moler/ncm.tar.gz';
>> gunzip(url,'ncm')
>> untar('ncm/ncm.tar','ncm')

Next, cd to where you unzipped it to, which is probably -

>> cd([pwd,filesep,'ncm'])

Then run the surfer algorithm on a website of your choosing, this one for example, and tell it to search for n nodes (in this case, 200 - warning, it takes a while)

>> [U,G]=surfer('http://www.thedailydanielblog.blogspot.com',200);

U is a list of websites connected to yours, arranged in matrix G. My website surfer matrix looks a little like this:




I was interested in what these sites were so I wrote a bit of code to print them to a text file:

>> fid=fopen('dansweb.txt','wt');
>> for i=1:size(char(U),1), fprintf(fid,'%s\n',char(U(i,:))); end
>> fclose(fid)

dansweb.txt then contains a list of 200 websites

The pagerank algorithm was then applied to U and G to find

>> pagerank(U,G)

The results are unsurprising - it charts links i have made, blogspot pages associated with my labels, and widgets i have used. There is even a bar chart output:
which looks slightly better if you add the websites to it

page-rank in out url
190 0.0432 9 2 http://www.usgs.gov
191 0.0383 4 2 http://www.usgs.gov/ask
192 0.0383 4 2 http://search.usgs.gov
72 0.0137 21 0 http://www.blogger.com
79 0.0131 40 0 http://purl.org/syndication/thread/1.0
71 0.0129 20 0 http://www.blogger.com/profile/
184 0.0098 5 0 http://planet.ubuntu.com
5 0.0092 60 6 http://www.blogger.com/profile/02981038739002302942
189 0.0092 1 0 http://wiki.octave.org
193 0.0091 6 5 http://marine.usgs.gov
10 0.0087 61 0 http://ims.ucsc.edu
3 0.0086 59 117 http://thedailydanielblog.blogspot.com/feeds/posts/default
4 0.0085 58 118 http://www.blogger.com/feeds/1936258002310927863/posts/default
8 0.0082 57 1 http://www.gnu.org/software/octave
11 0.0082 57 0 http://twitter.com
12 0.0082 57 0 http://hypem.com
63 0.0082 57 7 http://www.ourblogtemplates.com
21 0.0081 56 54 http://thedailydanielblog.blogspot.com/search/label/photos
24 0.0081 56 50 http://thedailydanielblog.blogspot.com/search/label/santa%20cruz
23 0.0081 56 49 http://thedailydanielblog.blogspot.com/search/label/san%20francisco
26 0.0081 56 46 http://thedailydanielblog.blogspot.com/search/label/travel
22 0.0081 56 43 http://thedailydanielblog.blogspot.com/search/label/preparations
25 0.0081 56 42 http://thedailydanielblog.blogspot.com/search/label/santa%20news
14 0.0080 56 36 http://thedailydanielblog.blogspot.com/search/label/internet
15 0.0080 56 36 http://thedailydanielblog.blogspot.com/search/label/job
17 0.0080 56 36 http://thedailydanielblog.blogspot.com/search/label/map
18 0.0080 56 36 http://thedailydanielblog.blogspot.com/search/label/matlab
20 0.0080 56 35 http://thedailydanielblog.blogspot.com/search/label/musings
16 0.0080 56 34 http://thedailydanielblog.blogspot.com/search/label/linux
27 0.0080 56 34 http://thedailydanielblog.blogspot.com/search/label/work
19 0.0080 56 33 http://thedailydanielblog.blogspot.com/search/label/move
6 0.0078 21 0 http://www.blogger.com/openid-server.g
67 0.0069 20 0 http://www.blogger.com/openid-server.g\42 /\76\n
196 0.0057 3 4 http://walrus.wr.usgs.gov/infobank
197 0.0057 3 2 http://mrib.usgs.gov
183 0.0053 4 1 http://fridge.ubuntu.com
194 0.0052 3 0 http://vineyard.er.usgs.gov/query.html
66 0.0052 17 0 http://www.blogger.com/profile/02981038739002302942\42 /\76\n

So, I have a pagerank of 0 (more or less) which is the lowest possible. The highest is 10, so this isn't a great example, admittedly, but I'll let interested readers have a play.

I discovered that facebook has a 9 and plymouth.ac.uk has a 7. Now, before you comment, i know that there are already loads of web-based pagerank checkers out there, but this is more fun, and here you get a breakdown of what sites contribute to each other's scores, OK?

Said in a Neil Buchanon from Art Attack (ITV since the 1990s) - 'try it yerself'!!

>> clear, clc, exit

homer.m

Originally posted on The Daily Daniel
___________________________

For you matlabbers out there, I've just found a homer simpson quote generator (similar to 'why')

homer.m

enjoy!

Geeky things i found

Originally posted on 'The DailyDaniel'
------------------------------------------

Linux is 17 years old. In May 2008, 1.95% of the OS market was shared by Linux distributions (compared to 91.11% Windows). This depresses me.

Check out Ubuntu at http://www.ubuntu.com/. It's just a great operating system.

%%%%%%%%%%%%%%%%%%%
Did you know that the Matlab logo (the first eigenfunction of the L-shaped membrane) is on a “sponsor a highway” sign on Route 9 in Natick,Massachusetts. Cleve Moler, creator of Matlab, likened its shape to "a beach towel blowing in the wind, constrained by a picnic basket on one-fourth of the towel".
%%%%%%%%%%%%%%%%%%

A map of the internet!!! Now this IS cool

http://www.touchgraph.com/TGGoogleBrowser.php?start=digg.com

%%%%%%%%%%%%

and finally a very funny and clever map from the makers of the Onion

http://www.theonion.com/content/atlas/


Good night!