Dos2Unix type conversion on Mac OS

August 23, 2009

As simple as:

tr '\r' '\n' < file-with-dos-newline.txt > file-with-mac-newline.txt


Getting longtitude and latitude coordinates from the centre of a google map

August 20, 2009

Googles long/lat is degrees only and a fractional component.

This script
javascript:coord = [gApplication.getMap().getCenter().lat(),gApplication.getMap().getCenter().lng()];
output = '';
for (x in [0,1]) {
neg = (coord[x] < 0);
if (neg) coord[x] *= -1;
deg = Math.floor(coord[x]);
minr = (coord[x] - deg) * 60;
min = Math.floor(minr);
sec = Math.floor((minr - min) * 60 * 100000)/100000;
output += (x==0?'Lat':', Long') + ': ' + deg + "° " + (min < 10?'0':'') + min + "' " + (sec < 10?'0':'') + sec + '" ' + (x==0?(neg?'S':'N'):(neg?'W':'E'));
};
void(prompt('', output));

decomposed that into degrees, minutes and seconds. The output was like the bellow.

Lat: 51° 40' 23.49798" N, Long: 8° 30' 06.43386" W

I wanted it to output degrees, minutes, and then a fractional component like the below, as was required by my Garmin mapping software (I was pulling location coordinates from google maps and inserting them as waypoints/route-vias in my Garmin app for uploading to my GPS device).

N51 40.39163302364358 W8 30.10723114013672

I tweaked it to return same.

I created a bookmark on the Bookmark Toolbar of my browser, and set the code below as the target/URL.

To use it I simply click the bookmark button for it when looking at a google map, and the coordinates for the location at map centre are given in a pop-up box.

Here is my ammended version of script.

javascript:coord=[gApplication.getMap().getCenter().lat(),gApplication.getMap().getCenter().lng()];
output='';
for(x in [0,1]){
neg=(coord[x]<0);
coord[x]=Math.abs(coord[x]);
deg=Math.floor(coord[x]);
minr=(coord[x]-deg)*60;
//min=Math.floor(minr);
//sec=Math.floor((minr - min)*60*100000)/100000;
min = minr;
output+=(x==0?(neg?'S':'N'):(neg?'W':'E'))+deg+" "+(min<10?'0':'')+min+" ";
};
void(prompt('Coordinates',output));

Update: http://netsharc.wordpress.com/2007/06/11/google-maps-latitude-and-longitude/ has the original and a few tweaks.


Mac : Open Terminal/iTerm here

August 19, 2009

Using Mac OS X and browsing the file system with ‘Finder’, I often want to open Terminal or iTerm and have the default path set to the current Finder folder.

Firstly Terminal. I found a script called ‘Open Terminal Here’ at http://jo.irisson.free.fr/?p=59

This seems to suffer from an issue where two windows are opened if Terminal was not already running.

Then I started using iTerm, it has a few more/different options than Terminal. For it I found a script ‘Open iTerm Here’ at http://snippets.dzone.com/posts/show/961

This seems to suffer from a similiar issue to above, where two tabs in a new iTerm window are opened if iTerm was not already running. I tried to modify it (my first apple script attempt) but managed only to get two windows open instead of a single window with two tabs.

Then I found an update to the Open iTerm Here script at http://www.danns.co.uk/node/226

This version successfully solves the issue of the two tabs. If you are a Terminal user, I imagine it should be easy to apply the patch to the Terminal Here script, or just use this script and have it invoke Terminal instead of iTerm.

Finally, to use the script  you then need to save it as an executable app. This is fairly straightforward:

  1. Open the Script Editor application
  2. Past in the source
  3. Save it
  4. Then chose save as
  5. Selected File Format of “Application”
  6. Save it again

You can now use QuickSilver or Silverlight to invoke the script.

However, I wanted to find out if I could add a button to Finder that could be clicked to run it. I eventually found out how to do this and here is how. You can simply drag the script .app file onto the top of the Finder application, and a button is created for it there.

So, when looking at a folder, just click the new button you created and a new iTerm is opened at the current path.

Lastly, I wanted to change the icon from the default. I wanted to use the iTerm icon. To do this, follow these steps to copy and paste the icon from the iTerm application:

  1. Go to Applications
  2. Navigate to iTerm
  3. Select the More Info… button
  4. Find your iTermHere.app and do the same
  5. Click the small icon at the top of the iTerm more info window and click cmd-c (apple-c, the shortcut to copy text)
  6. Click the small icon at the top of the iTermHere.app more info window and paste! (apple-v)

That’s it, you now have the script as an app, with a button in the Finder windows, and a nice iTerm icon.

Many thanks to all the folks involved in creating and refining these scripts I found, as linked to above.

Enjoy.


Clearing the MySql Logs

August 19, 2009

mysql> show master logs;

+------------------+------------+
| Log_name         | File_size  |
+------------------+------------+
| mysql-bin.000023 | 1074039776 |
| mysql-bin.000024 | 1023334365 |
| mysql-bin.000025 | 1073742100 |
| mysql-bin.000026 | 4254255    |
| mysql-bin.000027 | 117        |
| mysql-bin.000028 | 98         |
+------------------+------------+
6 rows in set (0.00 sec)

mysql> purge master logs to 'mysql-bin.000028';
Query OK, 0 rows affected (10.35 sec)

mysql> show master logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000028 | 98        |
+------------------+-----------+
1 row in set (0.00 sec)

mysql>


On demand “Tailing” of a database log table: select the last x records

August 19, 2009

Recently I had to monitor some data being output to a log table while an application was running.

The log table was quite large, and being written to constantly and also by portions of that system I wasn’t interested in.

So I only wanted to see the 10 or 20 most recent rows / records written.

There are quite a few ways to do this, but this is what I threw together. It assumes the ordering is based on an incrementing unique record id.

select count(*) into @rowcount from prodlog; select id, source_id, created_on, message from prodlog where id > (@rowcount-20) order by id;

I put the latest count of records in the table into a temporary variable. I then use that figure, minus the number of rows I want to see, to offset into the data.

Note that if the count of rows and row ids don’t match (e.g. because you used truncate) the above method will fail.

In this case you may use:

select id into @last_id from prodlog order by id desc limit 1; select id, source_id, created_on, message from prodlog where id > (@last_id-20) order by id;

This is still potential issues with this, for instance you may get less than you expected if there are gaps in the id sequence.

But it sufficed for my needs at the time :)


Hash/Pound/# character and links that don’t change the URL

August 18, 2009

An interesting alternative to href="#thisgoesnowhere", which causes the insertion of the “#” character and any following characters (“thisgoesnowhere” in this silly example) to the end of the URL, is to use a null javascript link target.

href="javascript:void(0);"

In this case, your onclick or other events are treated as before, but your page URL hasn’t needlessly changed.


VNC server : Fatal server error: could not open default font ‘fixed’

August 18, 2009

Trying to run vnc-server recently on a debian system, I ran into the following issue:

cat .vnc/debian-dev\:1.log
14/08/09 14:40:01 Xvnc version 3.3.7 - built Dec 30 2006 12:50:35
14/08/09 14:40:01 Copyright (C) 2002-2003 RealVNC Ltd.
14/08/09 14:40:01 Copyright (C) 1994-2000 AT&T Laboratories Cambridge.
14/08/09 14:40:01 All Rights Reserved.
14/08/09 14:40:01 See http://www.realvnc.com for information on VNC
14/08/09 14:40:01 Desktop name 'X' (debian-dev:1)
14/08/09 14:40:01 Protocol version supported 3.3
14/08/09 14:40:01 Listening for VNC connections on TCP port 5901
Font directory '/usr/share/fonts/truetype/' not found - ignoring

Fatal server error:
could not open default font 'fixed'

I solved the issue with some apt-get for dependancies as per below

apt-get install xutils xbase-clients xfonts-base xfonts-75dpi xfonts-100dpi

Ref:  http://www.debianhelp.org/node/5720


Spoofing your Browser

March 31, 2008

Web servers sometimes behave differently for different browsers, for compatibility reasons usually, but not neccessarily.

If you want to test how a system or site behaves for different browsers, plugins for firefox such as the ‘User Agent Switcher‘ can help. With it you can enter any data for the User Agent string.

The User Agent String is essentially a text string that your browser sends with each request to tell the server what browser, operating system, extensions/plugins, etc you are using.

I didn’t initially find the format or usage of this plugin to be very intuitive, but thankfully there are importable files online with settings for many of the more common combinations of browser/os etc. One such list I have used is at http://qainsight.net. Check for updates to the version of the script. Right now the site is offline, but the latest (March 2008, from internet caches) appears to be here.

Last I read it does not properly cater for the different User Agent String formats of other browsers, for instance the IE and Firefox string are quite different in both content and organisation. So while it will usually work, it may sometimes fail, and will probably not hide the fact of what browser you are actually using from those who might really want to know…


Ericsson HM230dp ADSL Router

November 13, 2007

I have the above router at home and am using it as a backup device.

I never got any firmware upgrades for it, and finding nothing on-line or at any of the ericsson sites, I decided to e-mail them.

A very nice chap responded with the below in a matter of hours :

“The HM230 has reached end of support, you can find the latest firmware and documetation via the link below:
ftp://ftp.cpeps.ericsson.net/HM230/

I have downloaded all the files and will try the update later.

If you find the site unavailable, drop me a note, I may have them on backup for a time.

The are :

Index of ftp://ftp.cpeps.ericsson.net/HM230/


Up to higher level directory
hm230d_userguide_r3.pdf 10294 KB 19/04/2007 00:00:00
hm230di FW 4.28p3.zip 2154 KB 19/04/2007 00:00:00
hm230dp_FW 4.28p3.zip 2144 KB 19/04/2007 00:00:00

WordPress Security : User account details at risk

October 5, 2007

The wordpress.com login mechanism is not secure!

[Update, it has been addressed, pity there was no announcement, and no warning with details of how to login securly]

Even when you go to it via secure-http, at https://www.wordpress.com, the login is done insecurely.

Why ? Because the login information is still posting to a non-secure http:// location !

What does this mean ? Consider :

  1. your login name and password are sent in plain text, not encrypted.
  2. there is the potential that anybody on your lan, at the internet-cafe, at school, work, in the airport etc can get your password. They don’t even need to be a technical genius.

Closer analysis of the website @ https://www.wordpress.com reveals the form is set as follows :

<form name="loginform" id="loginform" action="http://wordpress.com/wp-login.php" method="post">

Shouldn’t the action be to https://wordpress.com/wp-login.php ??

Thankfully, firefox alerts me to this with a message, so at least with that browser I may be aware something is not quite right.

Although this page is encrypted, the information you have entered is to be sent over an unencrypted connection and could easily be read by a third party.” is the message, as per the image below.

unsecure press

Image Link

I find this very suprising, don’t you ?

For instance, here [http://wordpress.com/blog/2006/03/08/secure-blogging/] is a blog entry touting the security of WordPressfrom 2006, yet today the login is very far from secure.