Greg's Blog

helping me remember what I figure out

Locate

| Comments

I used to rely on whereis and find to locate programs and files on my debian box, but these weren’t being very helpful when I tried to find a file I new existed on the system. I stumbled across the utility locate after a quick google search. And it did locate that elusive file for me. But only once I had updated it’s database (which it kindly informed was 8 days out of date). To update the locate database, simply log on as root and type: [code]udpatedb[/code]

UPDATE

If you are trying to do something similar on your Mac, the command can be found here (so you might to use the full path): [code]/usr/libexec/locate.updatedb[/code]

Stopping a Page Refresh

| Comments

I found myself having to trap a user attempting to refresh a page for one of our web apps. After a little bit of digging I stumbled across this solution: [code] [/code] To use it simply embed or include it into your template Eventhough the article says this is a IE specific event/feature it also works in FireFox. You should be aware that whenever the user leaves the page, they will be prompted about their impeding data loss, which can get a little tedious while developing. Again this became a handy feature for our AJAX apps as most of the processing is done in the background without the page reload, a user could accidentally hit the back button and loose where they were at.

LIKE and Oracle

| Comments

I never spotted this before but the LIKE operator is case sensitive! Which was skewing my search results quite severely. The work around is to put everything into upper case, both the values in the column you are performing the search against as well as the value of the varibale you are searching for. [code]SELECT col1, col2, col3 FROM table WHERE UPPER(col4) LIKE ‘%UPPER(yourValue)%’[/code]

Checking Your Free Memory

| Comments

Here is a handy little script that I stumbled across a while back (probably on a mailing list), sorry I can’t remember who posted it, but for posterity here it is: [code] rt = createObject(“Java”, “java.lang.Runtime”); freemem=rt.getruntime().freeMemory(); maxmem=rt.getruntime().maxMemory(); usepercent=freemem/maxmem;
Free memory #numberformat(freemem)#
Max memory #numberformat(maxmem)#
Percent use: #numberformat(usepercent * 100)# [/code]

UPDATE

It was from Pete Freitag’s site that I gleaned this tid bit of information and Niklas over at Primsix was kind enough to also point out that he put together a graphical version.

Cfeclipse - Local History Saves the Day

| Comments

I remember reading about this somewhere, but for the life of me I could not find the link for it again (I did find a reference to it here). So once again for my own sanity (and saving me a few minutes of fumbling around): here is how you can recover from changes made to your templates, when your undo history doesn’t quite stretch far enough back.
  • In your navigator view, right click on the file in question.
  • From the context menu select Compare with > Local history
  • The pop up that you are now presented with now displays you current state in the bottom left pane and in the right hand bottom pane you can see a historical view of the file in question.
  • The top pane displays the known history of the file, so simply step through the history until you find that line of elusive code you had accidentally “lost”
You can also increase the number of days (defaults to 7 [or 50 entries per file]) to keep in history from Window > Preferences > General > Workspace > Local History.

XSLT Conditional Statements

| Comments

One of the other completely new aspects of my job has been working with xmlHTTPRequest and XML/XSL transformation. And here are a few things that I learned during my last project: you can use conditional statements. W3schools proved very helpful in getting to grips with this. You can do if like statements: [xml] Do something [/xml] And if/else statements: [xml] Do something Do something else [/xml] The test expressions can be made up of: “=”, “and”, “<”, “& amp;gt;” and probably a whole lot more, but I haven’t come across any other ones yet.

SOUNDEX

| Comments

Ever wondered how Google does it’s little “did you mean this…” when you carry out a search? Well we just put together something similar (though I am sure not quite as clever as the folks over at Google). From some of my previous posts you may have gleaned that I am currently working for company that deals with postcodes, local authorities and properties. The mach-ii application I mentioned in my previous post makes use of this feature as quite frequently users mistype the information. So in order to help them we use two functions to guide them along their way. [sql] SELECT DISTINCT StreetName,CONVERT(INT, ourdB.dbo.LEVENSHTEIN(StreetName, ‘the road you are looking for’)) FROM ourPropertyTable WHERE soundex(StreetName) = soundex(‘the road you are looking for’) GROUP BY StreetName ORDER BY 2 [/sql] SOUNDEX is a built in MS SQL function that allows you to do sound matching for strings, which returns a list of similar sounding words to the one you were looking for. LEVENSHTEIN is an third party function that further enhances this search giving the returned set a numeric weighting to determine the accuracy of the match. With these two functions and this query you can in the event of a no results found make some suggestions as to what the end user may have been looking for.

Getting the QueryString Using JavaScript

| Comments

Here is a little script that parses the query strings of your URL so that you can use them in your JavaScript code: [js]// gvs - 19/7/2005 - retrieve values from URL to be appended to the link var hasQueryString = document.URL.indexOf(‘?’); var additionalQueryString = “”; var targetUrl = “http://www.someURL.com/?with=queryString”; if (hasQueryString != -1) { // Create variable from ? in the url to the end of the string additionalQueryString = document.URL.substring(hasQueryString+1, document.URL.length); targetUrl = targetUrl + “&” + additionalQueryString; }[/js] In case you are wondering what I used this for: to help debug some our AJAX UIs. Every single time a request is sent to the server, we use JavaScript to create a clickable link for us that mimics the remoting call that we can use to view the XML that is sent back to the browser (or any other problems that might occur).

Du

| Comments

I stumbled across the following command while reading this article: du --max-depth=1 --human-readable --total This gives you an estimated indication of your file space usage by folder. Here is some sample output: 12K ./lost+found 2.5M ./bin 84K ./dev 3.3M ./etc 187M ./home 7.6M ./lib 1.0K ./mnt 1.0K ./opt 65M ./proc 65K ./root 2.3M ./sbin 3.0K ./tmp There are plenty of other useful scripts and tidbits in the article.

Conditional Compilation

| Comments

What with the buzz going on around xmlHttpRequest, I decided to have a little play with the technology (yes I know very me too of me). One tutorial/example site I stumbled across ”Guide to Using XMLHttpRequest (with Baby Steps)” used some interesting JavaScript: Conditional Compilation. Here is an example: [js] /*@cc_on @*/ /*@if (@_jscript_version >= 4) alert(“JScript version 4 or better”); @else @*/ alert(“You need a more recent script engine.”); /*@end @*/ [/js] From the looks of it, it’s an IE only thing, but I wonder what the advantages are of using this code over a regular browser check? Is this a more reliable way than using window.ActiveXObject and, if you are specifically playing around with xmlHttpRequest, based on that condition making the correct create object call?