Published December 4th, 2009
Just a quick note to myself…
I’m working on a navigation system that uses CSS image replacement. To hide the text, CSS shifts it out of view by using the text-indent property and a big negative value. However, a side-effect of this is that when you click on a link, the dotted border that appears while you’re holding the mouse button down goes off the side of the page.
To get around this, I just wanted to disable it. After some searching I discovered the outline property — setting this to ‘none’ gets rid of it entirely:
a{
outline: none;
}
Of course, the above will remove it for all links, it’s up to you to decide whether you want to make it more specific.
Category: Web Development | Tags: | 2 Comments »
Published May 19th, 2009
I’m currently working on a project to convert an existing Flash map, which uses location data that’s been manually entered and maintained, to use data that comes from a database and uses latitude and longitude values. The original data is stored in an XML file so updating it dynamically is not a problem but as you’ll know if you’ve ever tried it, plotting latitude and longitude values on a map isn’t as simple as it might sound.
Briefly, the problem arises from the fact that the world is a sphere and representing it in two dimensions is not a straightforward task. There are various ‘projections’ to choose from, each of which uses a different method for mapping points — you can find out more in this Wikipedia article. The most common choice is the Mercator projection, where lines of latitude are spaced equally, and fortunately for me it’s the type of map used in the project I’m working on.
So, being somewhat mathematically inept, I decided that Google would save me from a day’s head-scratching. That turned out not to be the case, as I tried a good half-dozen different suggestions before finally stumbling across one that actually produced accurate results. To save others from the same fate I decided to reproduce here the code I ended up with, which is based heavily on code found in this newsgroup post. My implementation is PHP, but it shouldn’t be hard to convert it to another platform (see the original thread for a Javascript implementation). Apologies for the rubbish formatting, WordPress isn’t great at handling code:
function LongitudeToX( $lat, $lon, $map_zoom, $scale_value, $x_offset = 0 )
{
$offset=16777216;
$radius=$offset / pi();
return ( ( ($offset+$radius*$lon*pi()/180)>>$map_zoom ) * $scale_value ) + $x_offset;
}
function LatitudeToY( $lat, $lon, $map_zoom, $scale_value, $y_offset = 0 )
{
$offset=16777216;
$radius=$offset / pi();
return ( ( ($offset-$radius*log((1+sin($lat*pi()/180))/(1-sin($lat*pi()/180)))/2)>>$map_zoom ) * $scale_value ) + $y_offset;
}
A few notes about using these functions:
- From what I can tell, the above code is based on Google Maps and the $map_zoom relates in some way to the ‘zoom level’ of the map. I set it at 15 and it seemed to work OK.
- Because the dimensions of your own map might not exactly match the assumed dimensions of the map used in the calculation, the $scale_value parameter allows you to adjust the output to fit more precisely. I had to specify two decimal places of scaling to get an exact fit.
- Finally, the calculation assumes that the ‘origin point’ of the map (x=0, y=0) will be at the top, left-hand corner. This isn’t the case on the map I’m working on (the origin is at the centre) so I included $x_offset and $y_offset parameters so that I could adjust the output values accordingly.
In order to find the best values for the above parameters, I manually placed three widely-spaced temporary markers on the Flash map marking points whose latitude and longitude I already knew. Then I had the code render these points and adjusted the various parameters until the position of the generated points exactly matched the manually-placed markers.
I hope this code helps someone avoid wasting the sort of time I did yesterday!
Category: Uncategorized | Tags: | 2 Comments »
Published April 27th, 2009
I decided the other day that I wanted to try to install Ubuntu on my Eee PC 1000. I’d already replaced the default Xandros Linux that comes pre-installed with Windows XP (because my other half needed it) but recently I’ve become annoyed with its tendency to seize up every now and again for no apparent reason.
So I downloaded the Ubuntu Netbook Remix, and set about installing it as a dual-boot option. It was very simple, following the instructions took around 40 minutes for the entire process and it all seemed to be going fine. But when I came to reboot, there was no sign of Ubuntu.
Now, the Eee PC 1000 has a 40GB SSD (Solid State Drive) — which is in fact two drives, one of 8GB and one of 32GB. The 8GB is the ‘primary’ drive, and that’s where Windows is installed, but there wasn’t space for me to install Ubuntu alongside it so I created a small partition for it on the ’secondary’ drive.
I guessed that the problem was probably related to this fact so I had a poke around to see what could be done. Checking the Eee’s BIOS, there’s no distinction between the two drives so you can’t choose to boot from the secondary drive. I was tempted to give up at this point (I didn’t seem to be able to find any useful info on the web), but since the install process is so quick I decided to have another go and see if I could spot anything along the way that might be of use.
Sure enough, right near the end of the setup process (after creating/assigning partitions) there’s a little button labelled ‘Advanced’. Clicking on it popped up a dialog window with a drop-down list that allowed me to assign the boot loader to the primary drive (/dev/sda) instead of the secondary drive (/dev/sdb) that it had defaulted to. So I let it go ahead and install, and one reboot later there it was: a list of boot options. Success!
So, is it any good? Well, it certainly looks good and I like the ‘remixed’ desktop/interface which organises applications in a sensible and easy-to-find way. Boot time isn’t noticeably quicker than WinXP, which is disappointing but could be explained in part by the fact that it’s running on the slower secondary drive. From what I can tell after one day’s use, once started it runs very smoothly with apps launching very quickly and no unexplained ‘freezes’.
As far as compatibility is concerned the wireless, sound, touchpad, camera, display, USB and SD ports all worked out-of-the-box with no configuration required. I have my doubts that Bluetooth is working but haven’t had a chance to test it yet. The one serious gripe is the time it takes for the wireless to establish a connection — it suffers here even in comparison to Windows, which would (re)connect almost instantly where Ubuntu can take 40 seconds or more. I often use the netbook for a very short time (say, to do a quick web search) and then put it into hibernate, so a slow restart is a definite annoyance.
If you’re interested in checking out the Ubuntu Netbook Remix but don’t want to go to the trouble of installing it, then you can run it from a USB stick (1GB or bigger) without any installation. Startup is slow but once it’s going it’s fine and if you decide you do want to keep it, then you can install it from the same USB stick.
Category: General | Tags: | Be the First to Comment »
Published January 29th, 2009
I’ve been having a week where there’s a ton of stuff to be done in a short time, yet everything seems to take much longer than it should and every task seems to present multiple unforseen obstacles.
Yesterday, for example, I was working on something that had already taken several days of my time when I’d hoped to get it done in hours. The final straw came when I found myself facing what appeared to be an intractable problem: a process that needed to insert multiple rows in a table, and increment a certain column in each row to get a unique value. I couldn’t use an auto-increment value in this case (there was one already), and using a separate query caused concurrency problems (resulting in non-unique values). I should just point out that this is a system that I’ve inherited, not one that I developed myself.
I started out with a simple update, like this:
UPDATE my_table SET some_value = ( MAX( some_value ) + 1 ) WHERE id = 123;
…which in hindsight was never going to work but anyway, it gave me this error:
#1111 - Invalid use of group function
So I thought about it a bit and then struck on this:
UPDATE my_table SET some_value =
(
(
SELECT MAX( some_value )
FROM my_table
) +1
)
WHERE id = 123
…which gave me this error:
#1093 - You can't specify target table 'my_table' for update in FROM clause
…damn. I was starting to bang my head on the desk at this point, but Google came to my rescue by pointing me at this thread, which suggested using a nested sub-select. The result was the following rather ugly query:
UPDATE my_table
SET
my_value =
(
(
SELECT selected_value
FROM
(
SELECT MAX( my_value ) AS selected_value
FROM my_table
)
AS sub_selected_value
)
+ 1
)
WHERE id = 123
…which works. It’s not great from a performance point of view since it uses a temporary table, but it does what it needs to. I hope in future that I will be given time to go back and rewrite this part of the system so as to entirely remove the issue.
Category: Uncategorized | Tags: | 2 Comments »
Published January 12th, 2009
Here’s a great blog post discussing a technique to simplify and encourage commenting on a blog, in particular by quoting text snippets. I might well try to find the time to implement it here on StickBlog.
Category: Uncategorized | Tags: | 1 Comment »