Posts tagged with server

Simple HTTP Server with Python

September 24th, 2009

I came across this article on Linux Journal today about using Python to run a very simple HTTP server from any directory. I tested in on a standard install on Windows and it works perfectly.

As one of the comments says there’s loads of great command line tips to be found at commandlinefu.com, including the one I mention here.

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

Virtualbox First Impressions

April 19th, 2008

I’ve been wanting to try using virtual machines for quite a while now. I really want to use an Open Source application so I first thought of using the Kernel Based Virtual Machine but that requires virtualization extensions (Intel VT or AMD-V) which my 5 year old laptop doesn’t have.

After talking to a work colleague about innotek VirtualBox I thought I’d give it try.

Installing was a breeze using the Fedora 8 rpm provided and after skimming through the manual I tried installing Ubuntu 7.10. This was easy enough but the first thing I noticed was that I really need more RAM. I only have 512MB on my laptop an allocated 256MB to Ubuntu but it’s pretty sluggish and laggy to use. The other thing I didn’t realise is that to install Ubuntu you need to boot from the CD and then click on the Install icon on the desktop, otherwise it’s just like running a Live CD.

Next I thought I’d try Mint 4.0. I’ve read a few good things about this so decided to give it a run. Unfortunately the install crashed soon after booting (which is strange since it’s based on Ubuntu and that booted fine) so I’ll have to wait to see Mint in action.

Next up it’s Slackware 12.0 when I have the time, I’ll post my further impressions with Virtualbox as I progress but so far so good. My only complaint is that use of the Qt toolbox which looks decidedly ugly on Fedora 8.

Google BookmarksEvernoteGoogle GmailHotmailWordPressLinkedInFacebookDeliciousShare

Switch to our mobile site