Posts about Web

Javascript Libraries

April 29th, 2009

First I should say that I’ve been very busy lately, hence the lack of posts on my blog, but I hope to rectify that situation soon.

I’ve been working on a new Intranet site at work and for the first time I decided to try using a JavaScript Library. I may be a bit behind the times but I’ve always preferred to code things from scratch myself. This is not from any purist point of view but just because I prefer to understand exactly how a site works and using a library abstracts away a lot of the underlying workings, of course I understand that this is the whole point of using a library.

Anyway there’s many libraries to choose from but I picked jQuery, mainly because it’s fast, small and easy to implement. I’ve been very impressed so far just how easy it is to learn and will definitely use it in future projects.

I’ve also added some charts using the Flot library in combination with jQuery, again it’s easy to use and creates great looking charts in JavaScript.

Flot Chart

Google BookmarksEvernoteGoogle GmailHotmailWordPressLinkedInFacebookDeliciousShare

XMLHttp Character Encoding

March 23rd, 2009

I’ve been writing some new Intranet pages at work that include a searchable phone book that uses the XMLHttp object to return data in the background.

Many of the names in the database include Scandinavian Characters like å, ø and æ for example. IE always returned the correct results but if I searched for the Scandinavian characters using Firefox the search would return no results. It was clear that the SQL string being built in the ASP script was somehow mangling the characters so the query returned no data.

I checked the charcodes using JavaScript (using CharCode()) before the GET request was sent and IE and Firefox gave the same result. But then if I returned what the ASP script saw (using the asc function) it was clear that IE and Firefox disagreed at this point.

I assumed this was because the XMLHttp object in Firefox was using the wrong encoding so I added the following lines to force UTF-8 encoding (as used by the MS Access database phone book).

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-Type", "text/html;charset=uft-8")

Unfortunately this did nothing, but after a lot of testing and head scratching I finally discovered that my ASP script was saved in ANSI format. As soon as I converted the script to UTF-8 and saved it everything worked perfectly in Firefox.

Google BookmarksEvernoteGoogle GmailHotmailWordPressLinkedInFacebookDeliciousShare

CSS font-size in IE Tables

March 17th, 2009

I’ve had this problem in many pages where the CSS font-size is not in inherited in IE tables. It turns out the fix is very easy, just add this one declaration to the table style rule.

font-size: 1em;

I’d like to thank the site below for the solution

Reference: http://shapeshed.com/journal/css_font_size_not_inherited_in_ie_tables/

Google BookmarksEvernoteGoogle GmailHotmailWordPressLinkedInFacebookDeliciousShare

QuickProxy for Firefox

February 13th, 2009

After I wrote previously about toggling the proxy setting in Internet Explorer I looked for a similar function for Firefox.

There’s quite a few proxy extensions available, but if you just want to toggle the proxy on and off quickly I recommend QuickProxy.

Google BookmarksEvernoteGoogle GmailHotmailWordPressLinkedInFacebookDeliciousShare

WordPress 2.7 Loading Speed

December 14th, 2008

I’ve upgraded to WordPress 2.7 with it’s completely redesigned interface. I really like the new interface and once it’s opened most actions are really fast, it’s just the time it takes to load that bothers me. It could be that my host is very slow but after clicking to login it take about 10 seconds to load the new interface which is way slower than WordPress 2.6 used to be..

Google BookmarksEvernoteGoogle GmailHotmailWordPressLinkedInFacebookDeliciousShare

Display Server Time Using Javascript and ASP.NET in C#

November 20th, 2008

I’ve recently written an ASP.NET page using C# that required displaying the server time on the webpage using Javascript. To do this you need to output the Javascript code using C# and initialise the Javascript Date() object with the server time, after playing around I found this code does the job.

"server_time = new Date('" + DateTime.Now.ToString("MMMM d, yyyy HH:mm:ss") + "');"

The entire code looks like this assuming you have a label with id=’clock’ on the page. Just output the string js to the page to add the clock.

const string crlf = "\r\n";
string js = "<script type='text/javascript'>" + crlf +
"window.onload=startclock;" + crlf +
"var clock;" + crlf +
"var time_diff;" + crlf +
"function startclock(){" + crlf +
   "clock=document.getElementById('clock');" + crlf +
   "server_time = new Date('" + DateTime.Now.ToString("MMMM d, yyyy HH:mm:ss") + "');" + crlf +
   "time_diff=new Date()-server_time;" + crlf +
   "setInterval('runclock()',1000);" + crlf +
"}" + crlf +
"function runclock(){" + crlf +
   "var cDate=new Date();" + crlf +
   "cDate.setTime(cDate.getTime()-time_diff);" + crlf +
   "var curr_hours = cDate.getHours();" + crlf +
   "var curr_mins = cDate.getMinutes();" + crlf +
   "var curr_secs = cDate.getSeconds();" + crlf +
   "curr_hours=(curr_hours < 10)?'0' + curr_hours:curr_hours;" + crlf +
   "curr_mins=(curr_mins < 10)?'0' + curr_mins:curr_mins;" + crlf +
   "curr_secs=(curr_secs < 10)?'0' + curr_secs:curr_secs;" + crlf +
   "clock.innerHTML=curr_hours+':'+curr_mins+':'+curr_secs;" + crlf +
   "}" + crlf +
"</script>";

I should mention that if you’re using classic ASP and VBScript then the line becomes.

"server_time = new Date(" & DatePart("yyyy",Date) & "," & DatePart("m",Date)-1 & "," & DatePart("d",Date) & "," & DatePart("h",Now) & "," & DatePart("n",Now) & "," & DatePart("s",Now) & ");"
Google BookmarksEvernoteGoogle GmailHotmailWordPressLinkedInFacebookDeliciousShare

Host Moved My Site Without Warning (Again)

September 29th, 2008

For the second time in only a few months my site was down for god-knows-how-long. I first noticed when my main site and blog redirected to a moving page for the server that, rather ironically, returns a 404, page not found error.

It didn’t take me long to ftp to my site and look at the htaccess file to see that someone had added a line at the bottom to redirect all traffic to the page mentioned above. I removed the line and sure enough my site was still there, however after contacting support (who initially told me that they had not added the offending line!) it turns out that my server was moved to a new IP address.

This just required me to change my a records at my nameserver (I use Zoneedit and highly recommend them) and in a few minutes I could access the new server. More annoying was that I has not received any notification of the move, plus I had posted a new blog post but to the old server so I had to manually rewrite the entry since I could no no longer access the old server (Googles cache helps a lot in these situations).

I pay very little for my hosting so I cannot complain too much, however it is making me wonder if I should pay more to move hosts to a more reliable outfit (maybe Dreamhost).

Google BookmarksEvernoteGoogle GmailHotmailWordPressLinkedInFacebookDeliciousShare

Google Chrome

September 3rd, 2008

Well I guess like every other technology blogger I should give my impression of Google Chrome so as not to disappoint here goes.

Overall I’m very impressed, especially for a first beta release.

  1. It’s fast, start up speed is blazingly fast and rendering time on regular pages is good. Javascript heavy sites are very responsive with little or no delay.
  2. It’s simple, uncluttered interface is very appealing. It gets the job done with a minimum of options and fuss.
  3. If you save pages as applications shortcuts it really does blur the line between local applications on your PC and those running from the internet. A bit like the shortcuts using in some netbooks where email points directly to gmail but even more so.
  4. As far as another browser in the marketplace I think more competition can only be a good thing.
  5. Very pleased they made it open source, no doubt the new V8 Javascript virtual machine and other elements will make it into other browsers. This will raise the bar for all browser vendors.
  6. Looking at the speed improvements it leaves the other browsers way behind and makes IE7/8 seem even more bloated. If Google really push this then it I think it’s a major threat to IE, plus it really takes the wind out of the sails of the unreleased IE8 (not like there was much excitement to begin with).
  7. If people are going to use this as their main browser it will need extensions. I just can’t handle seeing adverts again!

Of course I’ve only tested this on Windows (not my OS of choice) but I’m really looking forward to running it on Linux when available.

Google BookmarksEvernoteGoogle GmailHotmailWordPressLinkedInFacebookDeliciousShare

htaccess Subdomain Redirection

August 8th, 2008

My blog is set up as a subdomain to my main site so http://bobpeers.com/blog/ should really serve the content from http://blog.bobpeers.com.

Just recently I noticed that link pointing to my blog directories but accessed through the main site were not returning 404 pages for missing pages. For example a link pointing to http://bobpeers.com/blog/page-not-here would just serve the content from http://bobpeers.com. To force requests to the blog to be server by the subdomain i just added this line to my .htaccess file.

Redirect permanent /blog http://blog.bobpeers.com

Now any request for a page under the blog subdirectory will be permanently (http code 301) redirected to http://blob.bobpeers.com, so for example:

request http://bobpeers.com/blog/2008/08/page
serves http://blog.bobpeers.com/2008/08/page
Google BookmarksEvernoteGoogle GmailHotmailWordPressLinkedInFacebookDeliciousShare

Fedora 9 No Sound on Flash Videos

August 2nd, 2008

After living with no sound on flash videos since I installed Fedora 9 ( I don’t watch many videos as you may have guessed :-) ) I decided to look for a fix tonight. It turned out to be much simpler than I imagined, I should have done it ages ago!

For reference I had all other system sounds but the controls on the playback page of the Pulse Audio Volume Control just flickered.

Just install libflashsupport as root and you’re good to go.

# yum install libflashsupport

Found on this page, http://clunixchit.blogspot.com/2007/11/firefox-no-sound-on-flash-videos.html.

Google BookmarksEvernoteGoogle GmailHotmailWordPressLinkedInFacebookDeliciousShare

Switch to our mobile site