|
|
|
December 23rd, 2009
 | 12:46 pm - I found a use for a stored procedure Normally I avoid store procedures as they are paths to lazy coding and you end up with spaghetti code, and I couldn't see the point. Ideally they are there to enforce/implement database rules and I couldn't come up with a database rule at all.
Nada, zip, nothing.
You might think or range checking or value limits but these are business rules not database rules. The database doesn't care about them, only your business and the code you use to implement your business. These are in the business rules layer.
Under the same ideas I eshew the use of transactions on a database.
I have, now, found a use for one!
SATAC's receipt numbers need to be sequential(mostly) and contiguous (mostly) and are created from multiple source. Normally receipt numbers are made of the operator id and a number so you simply keep a running number on each machine, but at SATAC that isn't the case. So you keep a running number on a server. Needs to be simple and easy to use and garanteed to avoid two clients getting the same receipt number even if they request it at the same time!
The solution is a stored procedure (where you can safely and correctly use transactions). You call it with a unique identifier and it starts a transaction, inserts a row into the receipt number table with the unique id and the receipt number you are using and increments the receipt number on the first or 'seed' row of the table and then commits the transaction. The result is that you have your receipt number waiting for you when you are ready for it. You read the row with your unique id and then delete the row. Simple.
If two client call it at the same time, the first one in, and there has to be one that is first as the server handles all queries sequentially, sets a lock on the table and the second one waits for that lock to clear. When the first on is finished it clears it lock and the second one starts. The second query doesn't have to wait for the first one to retrieve its receipt number, only for it to be generated. The lock turn over time is measured in micro seconds because the whole thing is pretty much done in memory as it is all on one page due to it being a small row size and the values are deleted once read.
This is pne of those simple, elegant solutions that I like so much. Current Location: Australia, Adelaide Current Mood: happy
|
December 3rd, 2009
 | 02:13 pm - Coding Just had an issue with a page on our website.
The html file was causing a string index out of range error. Symptoms are
- it worked perfectly on a windows machine
- but not on a linux box
- In one section was 4 extended characters (UTF-8)
- The object that reads in the file does it 1024 byte chunks
- The index was 1024, the string length was 1020
- ASCII characters are 1 byte long
- UTF-8 characters are 2 bytes long
The answer is obvious, but why would it work under windows and not linux?
Windows assumes a flat text file is ASCII, whereas Linux assumes UTF-8, thus when windows finds the 4 extended characters it loads them as two seperate characters, ie 8 characters. Linux, however, sees them for what they really are and loads them as one character each, ie 4 characters.
Obviously this is the first time we've had UTF-8 characters in one of our pages.
For those who are interested ASCII is one byte per character, each byte can have a value from 0 to 255, hence only 255 characters - OK for english but useless for lots of other languages. UTF-8 uses an extended character set can use one or more bytes for each character, which, rather neatly, makes it backwardly compatable with ASCII. Current Mood: dorky
|
November 27th, 2009
 | 08:23 am - Catholics The BBC is reporting that the coatholic church in Ireland is accused of abuse cover up. From the article:
Reacting to the report, the current Archbishop of Dublin Diarmuid Martin said "no words of apology would ever be sufficient" and offered "to each and every survivor, my apology, my sorrow and my shame for what happened to them".
He added that the "many good priests of the archdiocese" shared his sense of shame.
"Many good priests"? Shouldn't that be "all good priests"? Current Mood: angry
|
November 24th, 2009
 | 10:24 am - News Ltd Didn't Murdoch's face have a nose?
There are those out there of Rupert Murdoch's age that are ignorant of the web and all this computer related, but they aren't attempting to fight it in some way. Does he really think stopping Google from searching News Ltd pages will increase his revenue? Current Mood: amused
|
October 9th, 2009
 | 09:41 am - Borders Borders has a list of the 100 favourite books of all time. (Click here).
It includes Pride and Prejudice, Harry Potter and the Philosopher's Stone, Nineteen Eighty Four and others that are worth reading.
It also includes the Twilight Saga, Ice Station (described as the worst book ever written by JC), The DaVinci Code (described as arse gravy of the worst kind by SF) and others.
Borders' readers are not too concerning really. Current Location: Australia, Adelaide Current Mood: shocked
|
October 1st, 2009
 | 11:53 am - Reasons to hate Microsoft #???? I have a zip file, it's a complete backup of all our archive data and is thus 2.2GB in size. I select it to delete it (as I need to make another one). Explorer informs me that I cannot delete it as it is in use. I shutdown Explorer and and re-open - no still in use. I reboot and open Explorer - no still in use. I reboot again and open a command prompt to delete the file - it works.
It would appear that Explorer opens the zip file to check on the contents and due to it's size this takes forever. So there is no way of deleting a large zip file in Explorer. Can I suggest that zip files should only be attempted to be opened when the user wants them opened? I could but that would not be part of Microsoft's philosophy, which appears to be 'Enhance [bugs] and make [the user experience] worse' Current Mood: annoyed
|
September 28th, 2009
 | 04:18 pm Go to google and use the search word recursion.
Like this...
That's cool! Current Location: Australia, Adelaide Current Mood: amused
|
 | 07:41 am - Facebook Put the link to the trip diary up on facebook. People following it were getting a 403: Access Denied error.
I wrote the web server that feeds out the diaries and I didn't include a 403 error, only 404 errors. This means that facebook is wrapping the link in it's own rubbish for some reason and it is failing to work.
Again Facebook shows itself to be a little bit shit. Current Location: Australia, Adelaide Current Mood: annoyed
|
September 27th, 2009
September 24th, 2009
 | 10:40 am - AJAX Issue The AJAX issue has been resolved. Too many /. It doesn't make sense at the moment, but there you go. Current Mood: curious
|
September 23rd, 2009
 | 10:20 am - AJAX Issue I've written AJAX stuff before (the trip diaries all use AJAX). AJAX stands for Asynchronous JavaScript and XML. Basically you create an HTML client inside an HTML client using JavaScript. The main HTML client is FireFox or IE or Safari or whatever, they run JavaScript. You use that client to get part of the page and display it. It uses normal HTTP stuff and is straight forward (The HTML is sometimes called DHTML for Dynamic HTML, but that's just adding confusion).
I've put checks in the code at the client end to see if it is being called correctly. It is. I've put checks in the code at the server end to see if it is being called correclty. It is. I've called the server directly from the address line in Firefox and I get the correct response. Using the JavaScript I get a blank string back. The code is exactly the same as the trip diaries and they work. The server reports that is has been called correctly and it sends the correct response. The client side has been called and has the status of "OK" in the status text. The page is being updated correctly, it's just being updated with nothing.
Every step, individually, works correctly. Even combining them in various ways works, just when they are all together it fails.
Typing this up to see if it triggers a solution.....
... it didn't!
|
September 21st, 2009
 | 10:06 am - fMRI and Fish Salman in a scanner
The link above goes to an article on scanning a dead salmon with a an fMRI. The scientists showed the dead fish photos designed to invoke an emotional reactions in people. It shows brain activity in the dead fish.
The point of all this? We need to take another look at all of the fMRI data that shows various responses in living human brains as it obviously easy to get false positives. Current Location: Australia, Adelaide Current Mood: amused Current Music: clicking keyboards
|
June 1st, 2009
 | 08:45 am - Paving We had some paving done recently. It was really good, especially when you consider the slope of the ground it was laid on. After it was finished, however, we discovered we couldn't open the sheds door, it was blocked by the paving as it sloped upwards towards the house. Neither the paver, Rodney, or us noticed this problem when he had finished.
Rodney, paver extraordinaire, was back this morning to fix the problem.
I figured he would simply drop a line of pavers in front of the shed door and we'd have a bit of a step into the shed, but that's not what has happened. Rodney has cut the pavers around the door and built a sort of bowl effect across the entrance to the shed. The shed door opens to over 90 degrees, which is fine, and if he made it go any further it would have destroyed the look of the paving. It is almost art down there.
Anyone in Adelaide looking for a paver, Scott Morrison (Apparently Scott is also very good, but I'd recommend Rodney)!
Thanks to alchemy75 and pre_vet_girl for putting us on to them Current Mood: impressed
|
May 20th, 2009
 | 09:52 pm - Night at the Museum 2 Thanks to Steve (who is Fan Guest of Honour at Conjecture) B and I went to see Night at the Museum : Battle of the Smithsonian. Hank Azaria was having a bit too much fun, but apart from that it was terrible. No jokes, no real plot, some grand standing and this bint running around calling herself Amelia Earhart but having very little in common with the real Earhart, it pulled you out of the story. Then there was the NASA bods trying to launch the V2 in the Smithsonian and the the Wright Brother's plane flew for a very long time (The Simpsons can get away with it because it was funny) and that "Amelia" flies from Washington DC to New York and back inside of one hour Current Mood: bored
|
March 5th, 2009
 | 08:32 am - Watchmen Saw Watchmen last night. I went as Dr Manhattan and was accompanied by two Silk Spectres(one of each) a Comedian, a Silhouette and others.
It did not disappoint, it was very close to the comic, well acted and the characters were correctly realised. Some things were dropped from the story, but nothing significant and there was one major change to the plot which was both significant and irrelevant. It's a bit violent but the violence is there as part of the plot and not there to shock.
The credit sequence was wonderful. Current Mood: relieved
|
January 21st, 2009
December 23rd, 2008
 | 12:24 pm The 'Truly Trivial' section on the main IMDB page today has this statement:
"Somewhat ironically, Jim Carrey shares a birthday with this deceased performer."
The answer is Andy Kaufman.
Just as an observation the word you are looking for is 'coincidentally' not 'ironically'.
|
December 19th, 2008
 | 10:14 am - Java Strings are immutable my arse! The Java String object is immutable. This means that it cannot be changed at runtime (there are very good reasons for this). However Java allows for reflection, which allows you to change the String at runtime(provided the new value is the same length as the old value). This is something you would never do. Honestly. It takes too much effort. However, consider another aspect of the JVM, it caches String literals. Strings are object, which means there is computing overhead to create them. Literals refer to values that are used 'on the fly'. EG:
Expected behaviour: ------------------ String x = "Hello World!" // This is a String object (Object creation overhead here)
System.out.println(x); // This is using the String object. (There is no object creation overhead here)
System.out.println("Hello There"); // This is using literal. (Object creation overhead here) System.out.println("Hello World!"); // This is also using literal. (Object creation overhead here) ------------------
To avoid the overheads of having too many String literals that are the same value Java caches them, so effectively they exist one
Actual behaviour: ------------------ String x = "Hello World!" // This is a String object (Object creation overhead here)
System.out.println(x); // This is using the String object. (There is no object creation overhead here)
System.out.println("Hello There"); // This is using literal. (Object creation overhead here) System.out.println("Hello World!"); // This is also using literal. (No object creation overhead here as it is in the literal cache and can be used again) ------------------
"So what?" I hear you ask. Well those of you who have followed this so far anyway. Well look at this code: ------------------ static { try { java.lang.reflect.Field valueField = String.class.getDeclaredField("value"); valueField.setAccessible(true); valueField.set("Hello World!!!!!!!!", "Goodbye cruel world".toCharArray()); } catch(Exception ex) { ex.printStackTrace(); } }
public static void main(String[] args) { System.out.println("Hello World!!!!!!!!"); } ------------------
The first nine lines from static{ run first. It sets up a literal (which ends up in the literal cache) and then changes the value of that literal (Which goes against the 'Strings are immutable' rule). So when it gets to the System.out.println("Hello World!!!!!!!!") line which will print out the literal "Hello World!!!!!!!!" which is in the cache with a different value. On the surface this looks like it would print out "Hello World!!!!!!!!" but it actually prints out "Goodbye cruel world"!
Why yes I do have something to do at work but that's at 11 and I cannot get caught up in anything important before then... ...why do you ask? Current Mood: curious
|
December 15th, 2008
 | 09:26 am - Who throws a shoe? Honestly! . Apparently Random Task and Iraqi reporters do.
It was the fastest thing W. has ever done. Eight years of ducking issues and responsibilities has paid off. Current Mood: amused
|
September 2nd, 2008
 | 08:12 am - No To Age Banding Philip Pullman has been asked by his publishers to age band his books.This is ridiculous, not all children read the same and children's literature can be some of the most entertaining.
Would Harry Potter have been the success it was if it was advertised for 7 - 15 years of age? No. They released them with 'Adult' covers for smeg's sake just so 'adults' wouldn't be embarrassed at reading a children's books on the bus. If you, like all people do, think this is a stupid idea: see notoagebanding.org Current Location: home, sick Current Mood: annoyed
|
|
|