Saturday, 27 April 2013

Blogging at school

Today, My eldest daughter showed me her school blog. At eight she's learning how to blog. The school  has subscribed to a bolgging site for schools. In this day and age of the internet, shouldn't the school have it's own Wordpress site? Installation literally takes minutes. Keeping it internal would make it safer and give the school full control over the site.

I've set up a few Wordpress sites now and it's so easy. I installed Wordpress on a hosted Centos machine using this fantastic tutorial Wordpresss installation 

Wednesday, 4 May 2011

Google Analytics easy-peasy-lemon-squeezy

Clever chaps & chapesses at Google. I've just put a website live for an Accountancy Outsourcing Company www.henryjamesoutsourcing.co.uk and added Google Analytics to the site.

Google Analytics is one of a number of tools Google provide for web developers. Essentially it captures statistics for pages on your web site. You have to have a Google account to use it so you have to sign up there first. Then you add Analytics to your suit of Google tools (sign up for an email address whilst you're at it and you can receive your stats reports pushed via email to the google email address)

Once you've signed up you'll get a little text window with some Java script in that'll look a bit like this

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._trackPageview();
} catch(err) {}
</script>

Copy this and paste it into your static web pages eg index.html … before the tag (keeps things tidy) and that's it hit your site a few times and check your Analytics pages a bit later (takes a while for the stats to filter through) I hit the verify

Now for some techie stuff: This is downloading some javascript code from google that actually does the monitoring. It uses cross site scripting to do this but adding the javascript dynamically

document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

gets round the browser security issues (see my earlier posts on cross site scripting and Ajax) Activity is reported back to google in most cases. One thing to watch out for is that any activity from China won't be reported on in full because of Chinese Government security limitations on internet information. Not that that's a problem for Henry James Outsourcing, maybe for when we're a little nearer world domination.

Monday, 18 January 2010

SEO - The Dark Art

Search Engine Optimisation - a strange and dark world occupied by people with street cred. games consoles and skateboards. I was contacted recently by a company I did some work for because searching for their name and one of their customer's brought up all the usual sites in google and my CV (woops!)

The CV was a pdf, and listed companies I had done work for although there was no direct link in the wording my CV obviously listed my client but also their customer mentioning no link or relationship.

I took the CV down for the sake of a quiet life, but it got me thinking why didn't my company website show up in the same search? http://www.cwebster-consulting.co.uk/. This in turn started me thinking about SEO (Search Engine Optimisation), something I'd not done for a long time. It dawned on me that the last time I did anything along those lines was way back when, all you had to do was drop in the key words in the meta tag and send a cheque off to your favourite search provider!

Now though, it seems things have changed. I'm reliably informed there are “White Hat” strategies that can get you to the top of the list. There are “Black Hat” strategies that can also get you there but can also get you barred from search engines altogether. You're best going to an SEO specialist Dave Chung is one SEO Guru who can help you to get your site a more appropriate audience.

So what strategy did I use to get my CV up there in the rankings? Well, none what so ever. It was a pdf, so there was no code. There were no links (I'm not that great at creating pdf's) it was just a CV exported from Word to pdf format. It did for some reason though, satisfy whatever criteria Google use to rank web pages. I can only assume that this is simply what's in the text.

I did a little more digging and came up with Google’s rules on getting good page ranking. Some interesting things come up. For example, every web page has a reputation. Websites with a good reputation linking to other well behaved websites improve their page rankings. So don't link to iffy websites and do link to legit, nice websites and let them link to you. One of the “Black Hat” strategies is to set up a company and charge people for links to bump up their ranking. Be careful, though, if discovered this can get you banned from some sites including Google.

Nice sites that show meaningful error messages (401, 403, 404, 500 errors) instead of the default pages churned out from standard web servers rank higher. So customise your error messages and give links back to the main pages in your site from the error pages.

Only three things matter on websites, content, content, content. For your site to bump up its rankings you need to publish articles that are relevant to your business. Use Title text as though it were key word searchable. Google like to use titles as guides to what's on the site. So for example if you’re a plumber you should add an article every month on Plumbing, Plumbing techniques, Plumbing products, maybe review some equipment. This will aid the search engines indexing of your site for relevant key words in the search criteria.

Finally update regularly, most search engines throw relevance into the mix by returning sites that are regularly updated and maintained. This shows a site on the move and being kept up to date. All of which adds to relevance.

Wednesday, 16 December 2009

MySQL Communications Link Failure

I'm building a MySQL Driven web app using MySQL JPA Hibernate JConnector. I've hit an exception:

HTTP Status 500 - exception
javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: could not load an entity: [net.bmo.model.BmoCalendar#2]

The root cause of this error is:

root cause:java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.

Basically this means that the DB connection times out and when the app. went back to the DB to retrieve some data the connection had been lost.

Solution? Add connection pooling. Something I'd been meaning to get round to but hadn't had a chance. So I added C3P0 Connection pooling. I'm using Hibernate so I added the following dependency to the pom.xml:

  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-c3p0</artifactId>
    <version>3.3.2.GA</version>
  </dependency>

This drops in the required jar(s) hibernate-core-3.3.8.GA.jar and c3p0-0.9.1.jar add them to the class path if you don't already have them.

Next I added the c3p0 properties to the persistence.xml file. The amendments are highlighted in blue.

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
  <persistence-unit name="myPersistence"
      transaction-type="RESOURCE_LOCAL">
   <provider>org.hibernate.ejb.HibernatePersistence
   <properties>
     <property name = "hibernate.connection.driver_class"
          value = "com.mysql.jdbc.Driver"/>
     <property name = "hibernate.connection.url"
          value = "jdbc:mysql://localhost:3306/myDB"/>
     <property name = "hibernate.connection.username" value = "uid"/>
     <property name = "hibernate.connection.password" value = "pwd"/>
     <property name = "hibernate.hbm2ddl.auto" value = "validate"/>

     <property name="hibernate.connection.provider_class"
          value="org.hibernate.connection.C3P0ConnectionProvider" />
     <property name="hibernate.c3p0.max_size" value="100" />
     <property name="hibernate.c3p0.min_size" value="0" />
     <property name="hibernate.c3p0.acquire_increment" value="1" />
     <property name="hibernate.c3p0.idle_test_period" value="300" />
     <property name="hibernate.c3p0.max_statements" value="0" />
     <property name="hibernate.c3p0.timeout" value="100" />

   </properties>
  </persistence-unit>
</persistence>



The effect of the lines above is to force the test of the connections in the pool at regular intervals and refresh the connection if required. This prevented the above error for my deployment. I did this without making any changes in the MySQL Database configuration

Tuesday, 6 October 2009

...I know a bloke who does a bit of that....

I met a guy the other day who was having a bit of difficulty with his company's IT infrastructure. If I had a pound for every time I have this conversation.

"We've got xxx application running on a server in our office and it's broken/not doing what we want any more. Can you fix it?"

Well, yes, probably. But how do companies with no IT expertise end up with huge systems flogged to them by some bloke they knew then he left/went bust/went elsewhere and now we're high and dry with no IT resources.

Also, why does someone recommend MS Small Business Server and MS Exchange to an organisation that clearly don't have the resources to maintain it? At some point the underlying SQL Server will run out of space/run into problems emails will get inevitably get lost and the whole thing will fall apart. It happens at big companies (I've seen it!) and can cause all sorts of issues, but it can cripple a small organisation.

These are the same organisations that don't get a consultancy in to give them a realistic breakdown of the the options and costs. I'd want to see 3 or 4 different options and cost/benefits for each and make my mind up from there. There's no doubt that there are a lot of clever systems out there with lots of features but they all come at a price and maintenance is no small part of that price.

I'm not saying that consultancy is a solution in itself, far from it. In the UK Business Link can be a good source of advice as well as numerous other organisations. There's a range of issues to consider when buying an IT system. Hardware failure support, software training support, procurement, installation & deployment, maintenance & disposal. Having seen a few RFP's (Request For Proposal) usually issued by very large companies to invite bids from suppliers. This seems a good way for small businesses to think too. If nothing else it forces the purchaser to consider the requirements as a whole rather then just as buying a shiny sparkly new computer that looked great in the add. A little bit of light research will show up RFP examples and guidance

This company I spoke to could have achieved all they wanted (email, shared docs & calendars, holiday forms linked to storage and basic work flow) from Google Apps for example or any number of other systems and it wouldn't have cost him the best part of 6k GBP and he wouldn't be high and dry when it went wrong.

In this case SAAS(Software As A Service) services (or ASP - Application Service Provision - as it used to be known) could have a real benefit. YOU don't have to have a DBA and a Sys Admin on your books. There's plenty of time and scope to bring that in house as and when you're big enough. But please don't "get a bloke you know" to do it for you unless he's prepared to enter into an SLA(Service Level Agreement) and can provide you with a DR strategy for when he gets hit by a bus.

Thursday, 20 August 2009

OutOfMemoryError: PermGen space in Tomcat 6. The Solution:

I'm blogging this as much for my own use as help for other's.

Every time I set up a new Tomcat server I forget these options! Once you find them keep them safe.

set JAVA_OPTS=-Xms256m -Xmx1024m -Xss96k -XX:MaxPermSize=512m -server -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled

It's the CMSClassUnloadingEnabled that prevents the OOM error. The memory options depend on your hardware.

To set these options for the Sand Box Server in eclipse goto window -> preferences. In the left hand view select servers click on the tomcat server and add the above to the startup options. I'd post a screen shot but I'm using MyEclipse which is a bit niche for most developers.

Thursday, 30 July 2009

Cross Domain AJAX Support with JSON-P

I was asked to get an online payment system working recenlty but the site was hosted away from the customer's site. Payment confirmation was on the customer's site and payments were run from WOLRDPAY. So my problem was how do you get the page to not accept payment twice for the same invoice? Answer a payment check service using ajax returning a simple paid/not paid response to the invoice id in the request. But in AJAX you can't do that because you're stepping off your domain.

Eventually I found JSON-P according to the browser implementation of XMLHTTPRequest the URL needs to be relative ie /ajax/CheckInvoice?invId=12345
I wanted http://some3rdpartysite/CheckInvoice?invId=12345

JSON is a way of encoding the XML request into key-value pairs but JSON-P adds a call back function that is created locally the AJAX request then looks at the local call, the local call wraps a function that calls the remote site. The Browser is not then aware of the cross domain aspect of the call and doesn't throw an exception. Job done, customer happy.

I'm not, though. Unfortunately there is some disagreement around whether or not this is a legit process. Many developers think that because JSON-P takes advantage of the fact that <script> tags are not evaluated, this is in fact a security flaw and should be plugged. So will my solution be broken by a future browser release? There is another school of thought that this is, in fact a legitimate process - certainly in this case, that should be handled appropriately and that until browser technology catches up JSON-P is a legit solution.

I agree with the latter. In my case the sites are all legitimate and it is simply a case of integrating two SAAS (Software As A Service) Services and that's becoming ever more important. The fact that they haven't been built to provide these services formally is more to do with the implementation rather than the principle.