ColdFusion Leap Year bug still there
So just got ColdFusion 9 Beta 2 up and running and my old leap year bug is still there. I’ve posted a public bug, #78713 now the tracker has been launched. It effects 7, 8 & 9 so hopefully it’ll get fixed!
So just got ColdFusion 9 Beta 2 up and running and my old leap year bug is still there. I’ve posted a public bug, #78713 now the tracker has been launched. It effects 7, 8 & 9 so hopefully it’ll get fixed!
A few new releases for you to catch up on. Firstly WordPress 2.8.1 – essentially a bug fix and security release by the look of it but worth doing anyway, quick note that if you get stuck with a maintenance page check in your web root for a file called .maintenance, just rename that and the site will come back.
Next up two public beta’s from Adobe. ColdFusion 9 boasting some new useful and some not so useful/utterly pointless changes and the ColdFusion Builder which can either be standalone or as a plugin to Eclipse.
Sphinx allows you to create a multi-value attribute index which is great for document tags or categories. By default if you search across these the search is an OR match. If you want to run an AND match you must specify multiple filters rather than passing an array of values.
In ColdFusion using the Java API requires a little tweak as you can’t pass a normal ColdFusion array to sphinx, you have to use a basic java type array. Tim Blair has a good article on how to create them but here’s an example of calling the API.
This example will search for document tagged with either 100 or 200. Note the array creation method.
<cfset variables.sphinx = createobject("java", "org.sphx.api.SphinxClient").init()>
<cfset variables.sphinx.SetLimits(0, 10)>
<cfset variables.arrObj = createobject("java", "java.lang.reflect.Array")>
<cfset variables.jClass = createobject("java", "java.lang.Integer").TYPE>
<cfset variables.jArr = variables.arrObj.newInstance(variables.jClass, 2)>
<cfset variables.arrObj.setInt(variables.jArr, 0, 100)>
<cfset variables.arrObj.setInt(variables.jArr, 1, 200)>
<cfset variables.sphinx.SetFilter("tag", variables.jArr, FALSE)>
If you want to search for 100 AND 200 you’d do it like this:
<cfset variables.sphinx = createobject("java", "org.sphx.api.SphinxClient").init()>
<cfset variables.sphinx.SetLimits(0, 10)>
<cfset variables.sphinx.SetFilter("tag", 100, FALSE)>
<cfset variables.sphinx.SetFilter("tag", 200, FALSE)>
More geocoding fun today, this time done with perl. For what I want to do, convert OS Grid easting and northing into latitude and longitude using an API, like Yahoo! was going to take ages due to throttling. Turns out that in perl using the handy Geography-NationalGrid-1.6 CPAN package it’s a lot easier and gives for most cases a result very close together.
Here’s a quick example:
#!/usr/bin/perl
use Geography::NationalGrid;
my $point1 = new Geography::NationalGrid( 'GB',
Easting => '385600',
Northing => '801900'
);
print "Latitude " . $point1->latitude . " Longitude " . $point1->longitude . "\n";
You can also give it a grid reference like TH 1234 1234 or a latitude and longitude.
Over the past few days I’ve been looking into a new search engine for an application. The chosen search daemon is sphinx and it’ll be called via the Java API (that comes with sphinx) from ColdFusion. Getting the basic searching going was pretty easy, creating an index, do a basic search, set some filters, done. The next step was to look into geodist matching, calcuating how far apart two latitude / longitude’s are, slightly more tricky. In CF you can do it with some crazy curvature of the earth calculations but in sphinx it’s real easy – when you know what it wants. The key there is radians.
You’ll find plenty of tidbits on the web about this but no real end to end examples so hopefully this will help!
If you need to geocode some postcode or zip values I can highly recommend tinygeocoder.com. It’s basic and gives you a straight lat / long value which is perfect. If you want something with a bit more information you’ll need to check out the Yahoo! YDN geocode API or Google’s HTTP API. I’ve got the YDN working with ColdFusion (I’ll post about that later).
First up you’ll need some data, I’ve created a basic DB table called sphinx_test.sql which you can download. It’s been written for MySQL. Quick note on the float values, if you don’t specific float 10,6 (or something similar) your lat/longs will automatically be chopped to only 4 decimal places.
The SQL contains 3 locations in England. The British Airways London Eye (51.502893,-0.118811), Millennium Dome (51.501984,0.004764) and Windsor Castle (51.481971,-0.600686).
Once you’ve created your table you’re ready to create an index. I’m going to assume you’ve already installed sphinx in /opt/sphinx (this is on a CentOS platform). To get the Java API part for ColdFusion is easy as well.
[root@hosting ~]# cd /root/sphinx-0.9.9-rc2/api/java
[root@hosting ~]# make
[root@hosting ~]# cp sphinxapi.jar /opt/coldfusion8/runtime/servers/lib
[root@hosting ~]# /opt/coldfusion8/bin/coldfusion restart
This is the sphinx.conf you’ll need to get this running. Now there’s a whole load of stuff you could do in the configure file but I’ll just give you a basic one which should be enough.
Note you have two options when it comes to getting the lat/long from MySQL, you can either use RADIANS(val) or use a pre-stored the radian value of the lat / long In this case we’re going to use the latter but I’ve included a commented line for the former.
Now for the actual code that does the work. I’ve created a file called sphinx.cfm (view as text or click it to actually see it working) with comments inline. The interesting parts are:
<!--- sort order must be @geodist to allow distance matching --->
<cfset variables.sphinx.SetSortMode(variables.sphinx.SPH_SORT_EXTENDED, '@geodist desc')>
<!--- where are we starting, this will be the london eye latlong converted to radians --->
<cfset variables.sphinx.SetGeoAnchor('latitude', 'longitude', degreesToRadians(51.502893), degreesToRadians(-0.118811))>
All of the API calls are the same as the documented PHP functions so you can refer to the documentation for more information.
Thanks go out to various bloggers and Tim to get this running.
The continued, and if by continued I mean actually starting, migration of my sites over the Rackspace Cloud is moving forward again at last. I’ve nearly finished setting up the initial Cloud Servers and all the DNS. The 4th server setup this evening however shows more signs of the move from Mosso to Rackspace Cloud, the inital RDNS entry for the previous 3 had been slicehost.com addresses but this time out it’s 000-000-000-000.static.cloud-ips.com. A quick lookup shows that the domain still lives on slicehost nameservers and has a Rackspace contact but I guess it’s movement.
Some changes are present in the control panel but not a lot, maybe they’ll be more or maybe it is just a logo update.
Update:
So after some playing I’m not going anywhere. The cloud servers are great, real easy to get running but for what I’m doing and have hosted, mess around with etc a dedicated box is ideal. Currently with The Planet and have a good deal, a UK server would be nice but the cost just doesn’t make it viable right now. I might look at either a bigger TP box, more RAM or go to iWeb or ServerBeach but not sure – any recommendations or reviews of those?
I’ve finally got resin, railo and caucho playing together in a nice, no longer ripping each other’s hair, out kind of way. I have to say my biggest comment (and probably one of the more tricky things to do) is that for Railo to become a big player in trying to take away Adobe’s CF user base installers are going to be essential. That said railo does seem quicker on processing CFML (need to do more tests to verify that).
I’ve got apache 2.2.3 running on CentOS 5.3. I have railo 3.1.0.015 (not updated to 016 yet) and caucho.
My resin.conf has this addition (multiple times for the different domains):
<host id="www.domain.co.uk" root-directory="/home/domain/public_html">
<host-name>www.domain.co.uk</host-name>
<host-alias>domain.co.uk</host-alias>
<web-app id="/" document-directory="."/>
</host>
The apache virtual hosts are just normal vhosts. No extras.
My caucho.conf (in /etc/httpd/conf.d) looks like this:
LoadModule caucho_module /usr/lib64/httpd/modules/mod_caucho.so
ResinConfigServer localhost 6800
CauchoConfigCacheDirectory /tmp
CauchoStatus yes
<Location /caucho-status>
SetHandler caucho-status
</Location>
Hopefully that might help someone out. I’m going to try and do a from scratch CentOS build guide for The Rackspace Cloud sometime next week. I’ve started migrating some sites over to the cloud server and so far not hit any issues.
Some people aren’t aware that for Rackspace Cloud Servers they also offer DNS which is pretty handy. The setup however is a little odd and the interface different to any other DNS/zone editor I’ve used. There’s a number of KB entries under The Rackspace Cloud control panel as well.
A quick guide on how to enter the details to get it to work. If you login, access your server and click DNS you’ll first need to add the domain name, in these examples domain.com. Once done click on the domain and then you can add away. You can’t edit, well if you call delete and add editing then yes you can.
So, for an A record:
Name: domain.com
Content: 1.2.3.4
Priority: 10
TTL: 300
Type: A
And a CNAME record:
Name: cname.domain.com
Content: another.domain.co.uk
Priority: 10
TTL: 300
Type: CNAME
For sub-domains you have to put the full domain in rather than just the sub-domain so:
Name: sub.domain.com
Content: 1.2.3.4 (or a CNAME)
Priority: 10
TTL: 300
Type: A
For MX records they say just use your IP as the content:
Name: domain.com
Content: 1.2.3.4
Priority: 10 (increment for additional MX entries)
TTL: 300
Type: MX
I think however you can also do this:
Name: domain.com
Content: 10 mail.domain.com (assuming you have a standard A record setup with IP called mail)
Priority: 10
TTL: 300
Type: MX
That’s it.
I’ve decided to take a leap and try moving all the sites I host into the cloud. Currently I’ve got a dedicated server but it doesn’t really do a lot most of the time and the pay for usage idea appeals. I’ve got a cloud server over at Mosso (soon to be The Rackspace Cloud) running CentOS 5.3 and I’m also in the process of getting Railo server / Resin running to handle the CFML stuff. So far it’s going OK.
Few things that I needed to get resin to compile, like gcc, glibc-devel, openssl-devel, openssl but aside from that pretty easy. I’ll try and write up a step by step guide when it’s working.