Displaying articles with tag

Fun with browser error pages

Posted by hank, Fri Oct 26 00:30:00 UTC 2007

So, I though it would be interesting to mimic browser behavior with error pages. I decided I needed to make a page that looked exactly like the Firefox Server-not-found page. I managed to copy the source using Firebug, and I extracted the css out of the jar files on my system. Anyway, I ended up with some source for IE and some source for Firefox.

Test this in IE and Firefox

I left little invisible links in each one (search for ‘Supplies’ on the page). I also removed all the default javascript from the Firefox version and replaced the Try Again action with a simple reload one-liner.

Then, I just wrote some awesome PHP to take care of which one to load, and called it index.php:


<?php 
if (preg_match('/MSIE/i', $_SERVER['HTTP_USER_AGENT'])) {
  readfile("errortest-ie.html");
} else {
  readfile("errortest-ff.html");
}
?>

And we’re done. Not bad, eh?

Tags:

Site5 promo code for October

Posted by hank, Sat Oct 20 04:05:00 UTC 2007

You can still get 13% off a new Site5 7.5TB/750GB/$7.50 Plan until November! These guys are a great rails host. Get this deal while it’s hot!

Code: HALLOWEEN2007

Go Now!

Tags:

Site5's Limited-Time 750GB/7.5TB offer!

Posted by hank, Sun Oct 07 15:47:00 UTC 2007

The Site5 deal just got better. Join now!

Site5 has been great hosting. The site you’re browsing now uses it. I bought this deal when it was 55GB of storage, 5TB of bandwidth, and 55 domain pointers. Now it’s 750GB, 7.5TB, and Unlimited domain pointers. It’s great Linux-based hosting that is Ruby and Rails friendly. They have support for every PHP application out there, as well as a great forum and wiki that can help you with just about any issue you have.

Here are some other posts I’ve made about it:

This one is from when they tripled their deal about a month ago. There is a bandwidth test in there that shows me getting 1.86 MEGABYTES per second transfer from them. They are not a slow host.

This one is from when they doubled the deal.

Tags:

Google releases an IFRAME generator for Google Maps

Posted by hank, Sat Sep 08 15:50:00 UTC 2007

Yes, it’s true, Google has released a simple iframe generator so you can embed Google Maps into anything, like this:


View Larger Map

For the record, Brickskeller is a pretty awesome pub. I highly recommend it if you are in the D.C. area.

Tags:

OMG Java is lame

Posted by hank, Tue Aug 21 06:04:00 UTC 2007

This Demo is an example of a major issue in Java. They seriously need to at least give the user a warning before fullscreening. I mean, that demo could have been really bad. Hint: goatse.

On the other hand, this would be AWESOME for presentations.

Tags:

Sending Adblock Google Blockers Away

Posted by hank, Sun Aug 19 17:42:00 UTC 2007

Of course I know that a simple Greasemonkey script can very easily thwart this, but I don’t expect most people to go out and find it to defeat this. If you don’t like my google ads, you can read this wonderful entry.

function sendJerksAway() {
      // Bye
      eval(unescape("%69%66%28%24" +
      "%24%28%75%6e%65%73%63%61%70%65" +
      "%28%27%25%35%62%25%36" +
      "%65%25%36%31%25%36" +
      "%64%25%36%35%25%33" +
      "%64%25%36%37%25%36%66%25%36%66%25" +
      "%36%37%25%36%63%25%36%35%25" +
      "%35%66%25%36%31%25%36%34%25%37%33%25%35%66" +
      "%25%36%36%25%37%32%25" +
      "%36%31%25%36%64%25%36%35%25%35%64%27%29%29%2e%6c" +
      "%65%6e%67%74%68%20%3d%3d" +
      "%20%30%29%20%64%6f%63%75%6d%65%6e%74" +
      "%2e%6c%6f%63%61%74%69%6f" +
      "%6e%20%3d%20%22%68%74%74%70%3a" +
      "%2f%2f%67%6f%6f%67%6c%65%2e%62%6c%6f" +
      "%67%6e%65%77%73%63%68" +
      "%61%6e%6e%65%6c%2e%63%6f%6d" +
      "%2f%61%72%63%68%69%76%65%73" +
      "%2f%32%30%30%37%2f%30%37" +
      "%2f%32%34%2f%67%6f%6f%67%6c%65%2d%72%65%63%6f%6d" +
      "%6d%65%6e%64" +
      "%73%2d%74%75%72%6e%69%6e%67" +
      "%2d%6f%66%66%2d%61" +
      "%64%62%6c%6f%63%6b%2f%22"));
}

Then it’s just this:


<body onLoad="sendJerksAway();">

Tags:

KLone - C on Rails!

Posted by hank, Sun Jun 10 17:13:00 UTC 2007

Well, I was over at Debian Package of the Day when I noticed an article on KLone. It’s a little application framework that allows you to do XHTML templating in C! Then, you can compile it and send it off to any Linux machine (with a few dependencies of course) to run it. I got it, and it didn’t work for me at first. Then, for some reason, it started working. Here’s what I think did it:

In Ubuntu, I did this:


sudo apt-get install build-essential libssl-dev quilt klone klone-package

Then, I made a new test project:


make-klone-project create -p myhello

This creates a new project directory. Now, go into it and make it your new home:


cd myhello-0.1/
cd userdata/
mkdir www etc
vim etc/kloned.conf

I’m just going to assume you’re using vim because, well, you should be. Make the config file look something like this:


server_list my_http
allow_root yes

my_http
{
    type      http
    addr.type IPv4
    addr.port 8880
    dir_root  /www
}

Now lets give it something to work with (note we’re still in userdata):


vim www/index.klone
<html>
<head><title>Hello Lady!</title></head>
<body>
  <%  io_printf(out, "Hey, Lady!  You call him Dr. Jones!");  %>
</body>
</html>

Now add your precious files to the sauce:


cd ../../site/
klone -c import ../userdata/
# 2 dirs and 2 files imported
cd ..

Now, compile and run it:


kloned-build -o myapp userdata
./myapp -F  # This runs it in non-daemonized mode

If you don’t get any errors, congratulations. That means I did something right.

Now, just hop over to here or wherever you specified it to run, and it will magically appear.

Now you can do this:

<html>
<head><title>Hello World</title></head>
<body>
<%
int i;
for(i=0; i < 10; ++i) {
    io_printf(out, "Hello Lady! %d<br />", i);
}
%>
</body>
</html>

Then run this to rebuild and re-run the server:


kloned-build -o myapp userdata && ./myapp -F

Update

So, I ran some tests, and I have to say, the speed increase from C might be really awesome every now and again. Here’s the code:

   clock_t curtime = clock();
   #define SEED 35791246
   int niter=10000000;
   double x,y;
   int count=0; /* # of points in the 1st quadrant of unit circle */
   double z;
   double pi;

   /* initialize random numbers */
   srand(SEED);
   count=0;
   for ( i=0; i<niter; i++) {
      x = (double)rand()/RAND_MAX;
      y = (double)rand()/RAND_MAX;
      z = x*x+y*y;
      if (z<=1) count++;
      }
   pi=(double)count/niter*4;
   io_printf(out, "# of trials= %d , estimate of pi is %g \n",niter,pi);
   io_printf(out, "%f", (double)(clock() - curtime)/(double)CLOCKS_PER_SEC);

All this is is a Monte Carlo method of calculating pi that I stole from here. It takes 0.56 seconds of CPU time on my Core 2 Duo @ 3.3Ghz. Now for the Ruby on Rails test:

# Controller
    @start = Time.now
    srand(35791246)
    iter = 10000000
    count = 0
    0.upto(iter) do |i|
      x = rand().to_f
      y = rand().to_f
      z = x*x+y*y
      count += 1 if z <= 1
    end
    @pi = count.to_f / iter * 4
    @end = Time.now

This finishes in 20.75 seconds (about 40x slower). C is great for things like this. I hope to use KLone in the future for these kinds of tasks.

Tags:

Precaching Images with Javascript

Posted by hank, Tue Apr 17 02:53:00 UTC 2007

Today, Will told me about some awesome image caching. I used it.

//Do some image caching
cached_image = Array(new Image(), new Image(), new Image(), new Image());
cached_image[0].src="image1.jpg";
cached_image[1].src="image2.jpg";

It’s amazing.

Tags:

Javascript blur problem

Posted by hank, Wed Apr 04 19:49:00 UTC 2007

Today, I had a problem doing this:

<input type='text' readonly onFocus="alert('manatee');this.blur();" />

The problem was it would go into an infinite alert loop. That’s not cool. The fix was to reverse the calls:

<input type='text' readonly onFocus="this.blur();alert('manatee');" />

Tags: