Tuesday, December 15, 2009

Getting the auto increment id from SQL insert in Java

Often you need the id or autoincremented values of a row you have inserted into the database. To get this in Java do the following:
String sql = "INSERT INTO table (column1, column2) values(?, ?)";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);

The key here is the Statement.RETURN_GENERATED_KEYS. Now you can get the auto incremented keys by doing the following:
rs= stmt.getGeneratedKeys();
auto_id = rs.getInt(1);

It's also possible to do this with regular statements (not prepareStatements) like this:
stmt = conn.createStatement();
stmt.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS);

Solution source: http://stackoverflow.com/questions/1376218/is-ther-a-way-to-retrieve-the-autoincrement-id-from-a-prepared-statement

Yearweek function in SQL

A neat function in SQL which gives you the year and the week of the date it is presented with:
SELECT YEARWEEK('2009-12-23')
returns 200951, that is the 51 week of 2009.

SELECT YEARWEEK('2010-01-02')
returns 200952, the last week in 2009. As one can see the year here is different from the input value, this is because January 2nd 2010 is a Saturday and therefore belongs to the last week in 2009. First week of 2010 begins on Sunday 3rd or Monday 4th depending on how it is defined in your country.

Solution source: http://www.java2s.com/Tutorial/MySQL/0280__Date-Time-Functions/YEARWEEKdateYEARWEEKdatemodereturnsyearandweekforadate.htm

Wednesday, December 9, 2009

Bare LFs in SMTP, escaping newlines in mail

You might have received the page http://cr.yp.to/docs/smtplf.html when trying to send mail using the PHP mail function. The reason is that linebreaks must be escaped in emails.

Usually a linebreak is a \n (or LF, line feed), however when sending mails the standard says this LF must be escaped with a \r (or CR, carriage return). so \n shuold be \r\n

Escaping the email text like the following will do the trick:
$escapedString = str_replace("\r\r\n", "\r\n", str_replace("\n", "\r\n", $unescapedString));

Dynamically add POST form in PHP and javascript

Sometimes you want to send data as POST to a page based on a button clicked. A possibility is to generate this form on the fly using javascript:

<script type="text/javascript">
//Create form to send values as post to the update status page.
var form = document.createElement("form");

form.setAttribute("method", "post");
form.setAttribute("action", "computationpage.php");

var hiddenField = document.createElement("input");
hiddenField.setAttribute("name", "inputValue1");
hiddenField.setAttribute("value", 999);

var hiddenField = document.createElement("input");
hiddenField.setAttribute("name", "inputValue2");
hiddenField.setAttribute("value", "this is a string");

//Create hidden div to contain the form.
var div = document.createElement("div");
div.setAttribute("style", "visibility:hidden");


This code would when call, create a form, add it to a hidden div at the bottom of the page and submit the form.

EDIT: added HTML, BODY, and SCRIPT tags. This is all that should be needed for this script to work standalone (its not valid XHTML 1.0 Strict though :)).

Tuesday, December 8, 2009

Open link in new window

To open a link or result of a form in a new window the target attribute can be used:
<a href="test.html" target="_blank">test</a>
or for forms:
<form target="_blank" ...></form>

Solution source: http://stackoverflow.com/questions/178964/javascript-post-on-form-submit-open-a-new-window

Reloading page using javascript

Two ways to reload a page using javascript:
window.location.href = window.opener.href;

both will send GET parameters. The former will also send POST parameters (usually you get a pop-up box asking if you would like to re-send post parameters or not do the page reload at all (which can be annoying)).

To set what GET parameters should be used use among other things the split() function on the string window.location.href:
splitArray = window.location.href.split("?");
window.location.href = splitArray[0];

and get parameters by splitting the second part of the splitArray on the &.

Adding opener after window will address the reload to the window which opened the current page:

Solution sources: http://bytes.com/topic/javascript/answers/648770-problems-reloading-same-page-new-parameters

Table cellspacing and cellpadding using CSS

Setting cellspacing and cellpadding through CSS is done using the following attributes:
* padding → cellpadding
* border-spacing → cellspacing
* border-collapse → no HTML equivalent

Solution source: http://stackoverflow.com/questions/339146/why-are-cellspacing-and-cellpadding-not-css-styles

Friday, November 20, 2009

Character sets UTF-8 and ISO-8859-1 in HTML and PHP

Character sets can bring much agony to programming for the web. Here are some useful functions and ideas about handling charsets.

There are two main charsets: UTF-8(Unicode) and ISO-8859-1. UTF-8 lets one handle more characters than ISO-8859-1 (such as arabic and chinese characters).

HTML files that should handle unicode characters must have this set in the header:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

Here one could also use 'iso-8859-1' instead.

If you need to convert between ISO-8859-1 and UTF-8 in PHP the functions utf8_encode and utf8_decode are useful. utf8_encode will convert from ISO-8859-1 to UTF-8 and utf8_decode from UTF-8 to ISO-8859-1.
The use of the functions is:
$utf8string = utf8_encode( $iso-8859-1string );
$iso-8859-1string = utf8_decode( $utf8string );

In addition to UTF-8 there are two other Unicode standards UTF-16 and UTF-32. The difference is how many bytes are used to store a character and thus how many different characters can be stored. UTF-32 is in little use, and so is UTF-16, but UTF-16 is used in more places.

To convert between these Unicode charsets use iconv. It is used like this:
$utf16string = iconv("utf-8", "utf-16", $utf8str);
$utf8string = iconv("utf-16", "utf-8", $utf16str);

incov can also be used to convert from other character sets such as ISO-8859-1 like this:
$utf16string = iconv("iso-8859-1", "utf-16", $iso-8859-1string);

Solutions found at: http://www.php.net/manual/en/function.utf8-decode.php, http://php.net/manual/en/function.utf8-encode.php, http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_21916597.html, and http://www.php.net/manual/en/function.iconv.php.

Wednesday, November 11, 2009

Time comparison in SQL

Time on the form 2009-12-31 22:12:34 can be hard to compare exactly. Therefore it is useful to have some ways of simplifying this.

Using DATE_FORMAT is useful.
SELECT * FROM table WHERE DATE_FORMAT(column, '%Y%m%d') = '20091231'
SELECT * FROM table WHERE DATE_FORMAT(column, '%Y-%m-%d') = '2009-12-31'
will give you rows with column value of that day.

The following can also be used apparantly:
WHERE DateDiff(dd, OrderDate, '01/01/2006') = 0
WHERE Convert(varchar(20), OrderDate, 101) = '01/01/2006'
WHERE Year(OrderDate) = 2006 AND Month(OrderDate) = 1 and Day(OrderDate)=1
WHERE OrderDate LIKE '01/01/2006%'
WHERE OrderDate >= '01/01/2006' AND OrderDate < '01/02/2006'


WHERE OrderDate BETWEEN '01/01/2006' AND '01/02/2006'

In addition, getting values where date is less than or larger than a given difference from now or a given time. On can use INTERVAL:
will give rows where createdate is before 3 days ago.

Solutions found at http://www.w3schools.com/SQL/func_date_format.asp and http://demiliani.com/blog/archive/2006/01/19/3384.aspx

Monday, November 2, 2009

Time functions in PHP

Getting time in the right format can be a challenge. The default format is unix timestamp (a number giving the number of seconds since January 1 1970 00:00:00 UTC). However one often want to extract the date in a certain format for display purposes or for use in databases.

There are some functions that are useful for doing this. They are date(),strtotime(), mktime().

mktime will return the unix timestamp from the arguments passed into it, e.g. one can give it minutes, hours, days,months, years:
mktime(0,0,0,3,20,2004) which is "20/03/2004 00:00:00" will be 1079737200.

date will return a string formatted according to the given format. Several arguments can be given, including "Y" for 2009 while "y" gives 09 etc. Examples:
$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm
$today = date("m.d.y"); // 03.10.01
$today = date("j, n, Y"); // 10, 3, 2001
$today = date("Ymd"); // 20010310

date("d, m, Y", mktime(0,0,0,3,20,2004)) // 20, 03, 2004
date("d, m, Y", strtotime("now")) // 03, 11, 2009 )

currentWeek = date("W", strtotime("now")) //45 for 03.11.2009

strtotime will take a string and try to convert it into a unix timestamp. An example is "now" which will give the time right now in unix timestamp. Other examples are strtotime("10 September 2000") and strtotime("+1 day").

Sources: http://php.net/manual/en/function.date.php, http://php.net/manual/en/function.strtotime.php, http://php.net/manual/en/function.mktime.php

Thursday, August 20, 2009

Setting up environment for J2ME programming in Ubuntu

To program for JAVA J2ME using Eclipse under Ubuntu following the guides in the following links should help with any problems encountered. This assumes you have already installed Eclipse. (can't remember the exact problems I encountered, but you have to edit a settings file somewhere or making a symlink (Se the ProGuard links))


Too many text messages on Nokia e51

I recently found that I had to many text messages in my sent folder on my nokia e51 phone. This caused the cellphone to not display new messages as it didn't want to show them unless there were fewer messages in the sent folder than the limit. Each time the phone was turned off and on again this was done and the text messages arrived, but this was to much work to do.

There are 2 fixes for this:

Increse the limit on how many text messages you can have in the sent folder:
open Messaging
select Options
select Settings
select Other
select No. of saved msgs.
enter the maximum: 999

If you have reached 999 messages the limit cannot be increased anymore therefore the messages in the sent folder needs to be deleted or moved. If you don't want to delete the messages do the following:
open Messaging
select My folders
select options
select New folder
go back to Messaging
select Sent
select Options
select Mark/Unmark and Mark all
select Options again
select Move to folder and select the folder you created.

Thus you archive your messages and leave space in the sent folder.

Friday, July 31, 2009

Creating a symlink in Ubuntu

Linking to a directory is a great way to access files and even trick programs to access files that are placed in a totally different place than it expects. What one is doing is creating a link which will list the content of a different directory when accessed.

So if I want a folder in my home area to point the my external harddrive mount point I could create a symbolic link, a symlink, to the external harddrive and its content would be shown when I accessed my symlink as a directory. The original location would also still be available.

To create a symlink one uses the program ln. In a console window, navigate to the directory where you want to create a symlink directory and type the following:
ln -s 'location to link to' 'name of symlink'

For example:
ln -s /media/ExternDrive moreFilesLink

Solution found at http://www.linuxforums.org/forum/linux-newbie/65415-creating-symlink.html

Update: To update/change where a symlink is pointing, use the flags sfn instead of just s:
ln -sfn 'location to link to' 'name of symlink'

For example:
ln -sfn /media/ExternDrive2 moreFilesLink

Solution: http://www.programmersparadox.com/2010/10/09/updating-a-symlink/

Changing the Blogger icon

In most cases the Blogger icon ruins some of the effect you are trying to create from your blog, thus changing the icon would be great addition. Heres how:

Create an image 20x20 pixels with your wanted logo. Check out some tutorials on making icons as an image shrunk to this size may look quite different than one intended. Save the image as a png file.

Upload the icon file to somewhere it is available online at all times, such as your homepage service (your ISP, geocities, etc.)

Go to Blogger Layout and select Edit Html. Add the following line to between the <title> and the <b:skin>:
<link href='URL to your image' rel='shortcut icon' type='image/vnd.microsoft.icon'/>

It will for example look like this:
<link href='http://www.somewhere.com/myicon.png' rel='shortcut icon' type='image/vnd.microsoft.icon'/>

This solution was found at http://isaacyassar.blogspot.com/2008/12/changing-blogger-tab-icon.html

Saturday, June 20, 2009

Error "identifier "__builtin_va_arg_pack" is undefined" when compiling CUDA

For some installations of CUDA on Ubuntu 8.10 and earlier one will get the error:
/usr/include/bits/stdio2.h(35): error: identifier "__builtin_va_arg_pack" is undefined

/usr/include/bits/stdio2.h(66): error: identifier "__builtin_va_arg_pack" is undefined

/usr/include/bits/stdio2.h(99): error: identifier "__builtin_va_arg_pack" is undefined

/usr/include/bits/stdio2.h(105): error: identifier "__builtin_va_arg_pack" is undefined

/usr/include/bits/stdio2.h(159): error: identifier "__builtin_va_arg_pack" is undefined

/usr/include/bits/stdio2.h(167): error: identifier "__builtin_va_arg_pack" is undefined

/usr/include/bits/stdio2.h(174): error: identifier "__builtin_va_arg_pack" is undefined

/usr/include/bits/stdio2.h(182): error: identifier "__builtin_va_arg_pack" is undefined

This apparently a problem with GCC 4.3. There seems to be several ways to fix this:

Upgrade to Ubuntu 9.04 Jaunty or newer. This should fix the problem.

add the following after line 28 of /usr/include/bits/stdio2.h:
int __builtin_va_arg_pack();

This should remove the above errors, but a new one might appear:
could not find -lXmu

To fix this, install libxmu-dev package:
sudo apt-get install libxmu-dev

Remove the -O3 flag from the COMMONFLAGS section of NVIDA_CUDA_SDK/common/common.mk file and do not use the flag when compiling other code either.

However, this will disable optimization which can make CPU code much slower.

Downgrade to GCC 4.2 or 4.1:
sudo apt-get install gcc-4.2
sudo apt-get install g++-4.2

After installation:
sudo rm -d /usr/bin/gcc
sudo ln -s /usr/bin/gcc-4.2 /usr/bin/gcc

This way your system will keep the gcc-4.3 but use by default gcc-4.2.

If you need to go back to 4.3 :
sudo rm -d /usr/bin/gcc
sudo ln -s /usr/bin/gcc-4.3 /usr/bin/gcc

Solution source: http://progjournal.blogspot.com/2008/05/install-cuda-on-ubuntu-710.html

Thursday, June 11, 2009

Mounting remote folder using SSH in Ubuntu 9.04 Jaunty

To mount a directory, for example your home directoyr, from a different linux computer is easily done using SSHFS, SSH Filesystem.

First you need to make sure you can connect to the remote computer using ssh, the remote computer needs to be running sshd. Try connecting to it using the command below, if you are able to connect, you are running sshd:
ssh <your username on the remove computer>@<remote computer name or ip>

Next we need to install sshfs, ssh file system, on the local computer:
sudo apt-get install sshfs

Note: Make sure you use sudo since this will give you root/administrator rights, if you are not allowed to do this you need to be added to the admin group. Someone already a member must then write:
sudo adduser <your username> admin
Alternatively log in with a user that is a member of this group.

Fuse, Filesystem in Userspace, makes it possible for non-root users to handle filesystems, in this case let sshfs mount a remote directory. You need to make sure the fuse is loaded:
sudo modprobe fuse

Then you need to become part of the fuse group, the group of non-root users who are allowed to handle filesystems:
sudo adduser <your username> fuse

The following commands will set up permissions to access the fuse utilities:
sudo chown root:fuse /dev/fuse
sudo chmod +x /dev/fuse

Since you added yourself to a new group, you need to log out of Ubuntu for this to take effect. Do so now.

Now you can finally mount the remote folder. You will need a folder to mount the remote folder into:
mkdir <foldername>

Then all you need to do is tell sshfs to mount the remote folder:
sshfs <remote computer username>@<remote computer name or ip>:<path to folder on the remote computer> <folder on local computer>

That's it!

Now, to unmount the folder type the follwing:
fusermount -u <path to local folder>

Below is an example of what this could look like. Here the local user is "tom", the remote user is "fred" and the remote computer is "fredsComputer":

sudo apt-get install sshfs
sudo modprobe fuse
sudo adduser tom fuse
sudo chown root:fuse /dev/fuse
sudo chmod +x /dev/fuse
mkdir fredsHomeDirectory
sshfs fred@fredsComputer:/home/fred fredsHomeDirectory

To unmount:
fusermount -u fredsHomeDirectory

Solution found at: http://www.howtogeek.com/howto/ubuntu/how-to-mount-a-remote-folder-using-ssh-on-ubuntu/

Wednesday, June 10, 2009

You are not smart enough to debug this!

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."

--Brian Kernighan

Monday, June 8, 2009

CUDA errors propagate

Sometimes if a kernel or a cudaMemcpy fails it will take CUDA some time to recover, this often causes kernels or memcpys that follow the failing one to also fail, or at least not execute.

It is therefore important to always include error checking after of all CUDA calls (as mentioned before here: http://www.herikstad.net/2009/05/cuda-kernel-errors.html)or alternatively use CUDA Utility Library. Also if you get several failures in a row, fix the first error first, since the others might just be because of the first call failing.

To use cutil you need to include the cutil_inline.h file located in /NVIDIA_CUDA_SDK/common/inc in your home directory. After doing so, you can enclose all your communication with the CUDA device with different inline functions that will catch errors. The functions are:
cutilExit(argc, argv)

To use, simply do the following for a kernel:
kernelCall<<>>(d_Data, dataSize);
cutilCheckMsg("kernelCall failed");

Or for a memcpy:
cutilSafeCall( cudaMemcpy(h_Data, d_Data, dataSize, cudaMemcpyDeviceToHost) );

Note: The CUDA Utility Library is a "wrapper" that makes it easier to utilize functions such as __cudaSafeCall()

Tuesday, May 5, 2009

CUDA and double precision floating point numbers

If you are in any way using CUDA to computations involving doubles, you need to perform a few adjustments to have it work. By default CUDA has double support disabled, this entails that all doubles are silently converted into floats inside kernels and any double precision calculations computed are incorrect.

To enable the use of doubles inside CUDA kernels you first need to make sure you have a CUDA Compute 1.3-capable card. These are the newer versions of the nVidia CUDA cards such as the GTX 260, GTX 280, Quadro FX 5800, and Tesla S1070 and C1060.
Thereby you have to add a command line options to the nvcc compiler: --gpu-architecture sm_13 .

Note: you can use sm_11 and sm_12 to enable functionality added in CUDA 1.1 and CUDA 1.2 respectively.

Source: https://www.cs.virginia.edu/~csadmin/wiki/index.php/CUDA_Support/Enabling_double-precision and http://forums.nvidia.com/index.php?showtopic=84999&pid=481809&mode=threaded&start=#entry481809

Sunday, May 3, 2009

Robots.txt blocking blogger blogs?

Google Wemaster Tools reports for example: http://www.herikstad.net/search/label/clean%20cron is blocked by robots.txt

No worries however, according to the FAQ and http://www.google.com/support/forum/p/Webmasters/thread?tid=33c2e6597951a702&hl=en, this is just to remove results from the blog search tool included on the page (the URL contains "search" directory). Including the results would give duplicate sites in Google search and give incorrect visiting stats etc.

If you don't have "search" in your URL error, check out the link above.

Friday, May 1, 2009

CUDA and SSE2 intrinsics

Using SSE2 intrinsic calls may speed up your program execution substantially. However, nvcc seems to be unable to compile SSE2 code. For example including emmintrin.h or equivalent will give errors like this:

/usr/lib/gcc/x86_64-linux-gnu/4.1.2/include/mmintrin.h(48): error: identifier "__builtin_ia32_emms" is undefined
/usr/lib/gcc/x86_64-linux-gnu/4.1.2/include/mmintrin.h(61): error: identifier "__builtin_ia32_vec_init_v2si" is undefined
/usr/lib/gcc/x86_64-linux-gnu/4.1.2/include/mmintrin.h(90): error: identifier "__builtin_ia32_vec_ext_v2si" is undefined
/usr/lib/gcc/x86_64-linux-gnu/4.1.2/include/mmintrin.h(114): error: identifier "__builtin_ia32_packsswb" is undefined
/usr/lib/gcc/x86_64-linux-gnu/4.1.2/include/mmintrin.h(129): error: identifier "__builtin_ia32_packssdw" is undefined
/usr/lib/gcc/x86_64-linux-gnu/4.1.2/include/mmintrin.h(144): error: identifier "__builtin_ia32_packuswb" is undefined
/usr/lib/gcc/x86_64-linux-gnu/4.1.2/include/mmintrin.h(158): error: identifier "__builtin_ia32_punpckhbw" is undefined
/usr/lib/gcc/x86_64-linux-gnu/4.1.2/include/mmintrin.h(172): error: identifier "__builtin_ia32_punpckhwd" is undefined
/usr/lib/gcc/x86_64-linux-gnu/4.1.2/include/mmintrin.h(186): error: identifier "__builtin_ia32_punpckhdq" is undefined
Error limit reached.
100 errors detected in the compilation of "/tmp/tmpxft_000010b9_00000000-4_template.cpp1.ii".
Compilation terminated.
make: *** [obj/release/template.cu_o] error 255

To come around this problem, you need to compile the code using SSE2 using gcc and your CUDA code using nvcc and then link them together afterwards.

So create a separate .c and .h file where you create a function that execute the SSE2 intrinsic calls. Include the emmintrin.h file in the .c file, since doing so in the .h will get you the same result as above because nvcc will read the .h file.

To use the SSE2 intrinsic function from your .cu file, you need to include the new .h, but in extern brackets like this:

extern "C" {
#include "yourfile.h"

Finally, you need to compile the files separately using nvcc and gcc and then link them together:

gcc cpuCode.c -o cpuCode.o
nvcc cudaCode.cu -o cudaCode.o
gcc cudaCode.o cpuCode.o -o progExe

Note: This is just an illustration, these 3 lines won't work by themselves, you need to include libaries etc.

CUDA "unspecified launch failure"

The error "unspecified launch failure" usually means the same as "segment fault" for host code. Check that your code does not try to access any areas outside the arrays being used. A common mistake is using 'the whole idx' instead of just the thread id to access shared memory. Here's an example:

int idx = blockIdx.x * blockDim.x + threadIdx.x;
shared[idx] = input[idx];

will give you an error and should look like this:

int idx = blockIdx.x * blockDim.x + threadIdx.x;
int tid = threadIdx.x;
shared[tid] = input[idx];

CUDA kernel errors

To print any errors that may be returned when you execute a kernel in a human readable way (you get the errors defined in the programming guide), add the following lines after your kernel call:

err = cudaGetLastError();
if (err != cudaSuccess) printf("%s\n", cudaGetErrorString( err ) );

Thursday, April 30, 2009

Posting code in blogger

To post HTML, code or other text with syntax that may be interpreted as code in blogger, you need to use the HTML equivalent characters. So for example '<' becomes '& l t ;' (without the spaces).

A good site that converts special characters in text to postable code is Postable.

Source: http://scrapur.com/index/displaying-html-code-in-between-blog-post/

Meta tags in blogger

If you want to put meta tags in your blog for example the description tag that shows up in some search engines, you need to tweak it a little bit. the tag needs to end with '"/>' not just '">'.

So go to the Layout tab, select edit html, find your <title> tag, right beneath it enter for example:

<meta name="description" content="Solutions to technical problems that I come across. Usually for general use of Ubuntu and writing code for the NVIDIA CUDA architecture."/>

Solution source: http://www.sitepoint.com/forums/showthread.php?t=517353

Tuesday, April 28, 2009

cron popularity-contest

Ever wonder what the script popularity-contest that can be found in /etc/cron.weekly/ is?

Well it is a script that periodically anonymously sends applications use statistics to Ubuntu so that they can decide what programs are most useful and should be included on the Ubuntu CD or be automatically installed.

It is not enabled by default, but if you want to help out; go to System->Administration->Software Sources and select the statistics tab, here you can check or uncheck for submitting statistical information.

Source: http://ubuntuforums.org/showthread.php?t=535067

Slow Ubuntu startup because of tracker and updatedb

The applications tracker and updatedb (which is used for locate) seem to run at startup every day on some machines. This causes the machine to be much slower until they have finished, which is annoying.

Disabling Tracker

You can disable tracker if you don't use it. Open a console window and navigate to /etc/xdg/autostart/ and edit the file trackerd.desktop as root (using sudo). Add the line 


to the end of the file. do the same with the file tracker-applet.desktop.

This will disable the tracker for all users on the machine. To disable the tracker for a specific user only follow the guide on https://wiki.ubuntu.com/Tracker, which is where I found this solution too.

Cleaning up updatedb

updatedb is used to keep track of all files one your harddrive so that you can search them using locate. However there are on some machines installed several scripts that will run this program every time it boots and thus slow it down. Having this database updated every day seems like overkill to me, weekly should be sufficient.
Open a console window and navigate to /etc/cron.daily/, list the files there. If you find the files find.notslocate or find.notslocate.dpkg-new remove them using

sudo rm find.notslocate
sudo rm find.notslocate.dpkg-new

Check to see if you have both mlocate and slocate files you only need one of them. mlocate is the prefered locate by Ubuntu so lets remove slocate. Type:

sudo apt-get purge slocate

to remove it. It might say that slocate is  already uninstalled, in that case remove the slocate script by typing

sudo rm slocate

Finally lets move all the scripts that run updatedb to cron.weekly (which make them run weekly instead of daily). From the cron.daily folder type:

sudo mv mlocate ../cron.weekly/.
sudo mv find ../cron.weekly/.

To learn more about mlocate versus slocate check out http://shallowsky.com/blog/tags/boot/, which is where I found the solution to this problem.

Monday, April 27, 2009


Seems to be an excellent tool. It gives you a 2GB folder online that synchronizes automatically with a folder on your local machine. The program is available for Linux, Windows and Mac.

In Ubuntu simply type sudo aptitude install nautilus-dropbox to install. Sign up through the application and voila 2GB available from everywhere.

Cleaning up Ubuntu

I've been going through my ubuntu install and trying to free up some diskspace. Came across quite a few neat tools to clean up the Ubuntu install, especially unused packages installed using aptitude.

The following have easy to follow instructions:


I haven't tried to remove orphaned packages because I read that this could mess up your system, so use at your own risk.

Also try xdiskusage, its available through aptitude and gives you a good overview over what folders take up the most space.

Setting up a CUDA environment in Ubuntu Jaunty

To write code for CUDA devices you need to set up your system properly. The following explanation is taken from Life of a Programmer Geek. First of all make sure you have a CUDA enabled graphics device, Wikipedia has a list of supported devices.

Install the build tools we need
Open a console window and type the following:
sudo apt-get install build-essential libglut3-dev

Install the NVIDIA drivers
Go to the CUDA ZONE download page and download the CUDA driver. (The Ubuntu 8.04 will work for Ubuntu 9.04 Jaunty).
Press CTRL+ALT+F1 to go to a terminal, log in with your username and password.

Navigate to the folder that you placed the driver file in and type the following:
chmod +x NVIDIA-Linux-x86_64-180.22-pkg2.run
This will first make the driver installer runnable. We then need to stop Xwindows (remember to save any open files). (if you are using KDE use kdm instead of gdm (which is for gnome)):
sudo /etc/init.d/gdm stop
Next we run the driver installation (Usually selecting yes to all questions is ok):
sudo ./NVIDIA-Linux-x86_64-180.22-pkg2.run
Finally we restart the Xwindows session.
sudo /etc/init.d/gdm start

A new error for Ubuntu Jaunty is that upon reboot you might get a message similar to:
(EE)Failed to load module "type1" (module does not exist,0)
(EE)Failed to load module "freetype" (module does not exist,0)
(EE) NVIDIA(0) Failed to load the NVIDIA Kernel Module
(EE) NVIDIA ***Aborting***
(EE) Screen(s) found, but none have a usable configuration.

To fix this problem edit the file /etc/modprobe.d/lrm-video and comment out the line install nvidia /sbin/lrm-video nvidia $CMDLINE_OPTS by putting a # in front of it.
Solution found from: http://ubuntuforums.org/showthread.php?t=950777

Install the CUDA Toolkit
Go to the CUDA ZONE download page again and download the CUDA Toolkit. Open a console window and navigate to the directory containing the file, type the following:
chmod +x cudatoolkit_2.1_linux64_rhel5.2.run
sudo ./cudatoolkit_2.1_linux64_rhel5.2.run

Use the default options suggested by the installer (press enter).

Note: The following steps need to be taken by all users

Add environment variables
This is very important step.
Open a console window to your home directory and edit the file .bashrc, this is the settings file for your console window. Add the following lines to the bottom of the file:
export PATH

These settings will not take effect before you open a new window so remember to do that.

Install the CUDA SDK
download the CUDA SDK from the CUDA ZONE download page. As with the Toolkit, open a console window, navigate to the directory with the files and type the following:
chmod +x cuda-sdk-linux-2.10.1215.2015-3233425.run

Accept the default options. The installer will create a folder called NVIDIA_CUDA_SDK in your home directory.

Compile and run an example
Open a console window, navigate to the NVIDIA_CUDA_SDK folder in your home directory, type:

This should open a window with a fluid dynamics simulation.

Writing code for CUDA devices
When writing code for CUDA GPUs its is useful to begin from the examples included in the SDK, the source code can be found in ~/NVIDIA_CUDA_SDK/projects/ (the directory in your home directory). Copy one of the directories and start editing the files in it. To compile the program type make.

If you want to put the files in a different directory or rename or add files to your project, you need to edit the Makefile file in your project directory and possibly also the common.mk file located in ~/NVIDIA_CUDA_SDK/common/ folder.

Dosbox and Ubuntu 9.04 Jaunty

I've been having problems with my DOSBox after upgrading to Jaunty. Here's problems and the fix for one of them at least:

1. The arrow keys are not responding. (actually they are mapped to totally different keys)
For Ubuntu Jaunty the 'usescancodes' option for SDL must be disabled. To do this you edit the DOSBox config file (dosbox.conf or .dosboxrc), go to the [sdl] section and edit the line to say:


This should do the trick.

The following sites are where I found the solution:

If you haven't got a dosbox.conf or .dosboxrc file in your home directory you can create it by doing the following:

  • Open DOSBox
  • Type 'config -writeconf dosbox.conf'
  • The file dosbox.conf will be created in your home directory
  • Rename the file to .dosboxrc if you want it to be hidden 

2. The sound is either totally gone or stuttering.

UPDATE: Use export SDL_AUDIODRIVER=esd instead, you will also need to have the package libsdl1.2debian-esd installed. See comments, thanks to mgedmin and Alex for the solution.

I haven't found the solution to this problem yet, noone seems to have (So if you have please tell me). But one can try the following: The problem is apparently caused by the change from ALSA sound server to PulseAudio.
Download the PulseAudio plugin, libsdl1.2debian-pulseaudio using synaptic or by typing:

sudo aptitude install libsdl1.2debian-pulseaudio

You will be asked to uninstall libsdl1.2debian-alsa. alternatively you can install libsdl1.2debian-all if you want to keep the ALSA plugin.
Now you need to tell SDL (which is what DOSBox is built on) to use PulseAudio, type export SDL_AUDIODRIVER=pulse in a console window, then start dosbox from the same window by typing dosbox

You might also be getting errors like

ALSA:Can't subscribe to MIDI port (65:0) nor (17:0)
MIDI:Opened device:oss

then go to the dosbox.conf file, find the MIDI section and change the settings in there to:


Hope some of this is of any help to you.