tech.zpoley.net

quick little hacks 

Javascript: Server callback on window unload

I'm using this simple cross-browser script to send tracking information back to the server when users leave a page.

Here's an example page.

I've tested it across Safari4.0.5/MobileSafari4.0.0+/Chrome5.0.375/Firefox3.6.3 and IE 6/7/8.

Loading mentions Retweet
Filed under  //   callback   Cross-browser   Javascript   onunload   tracking  

Comments [0]

Ruby Logger: Format log lines like "[H:M:S.uS]: #{log_line}"

Much shorter log format from logger if you don't care about anything but time.

[Hour:Minute:Second.Microsecond]: Log message

Loading mentions Retweet
Filed under  //   Logger   Logging   Ruby  

Comments [0]

Python subprocess

I thought this was cool because it made writing a quick test for my simple UDP server really clean and easy. What I needed to do was spawn another process to run alongside my script. In this case it was this subprocess that I wanted to test. Python subprocess made this really easy.

The script starts the udps server in a child process using subprocess.Popen and then sends a UDP datagram to the udps server, which gets written to the server log file. The test verification is the printed content of the udps.log file created by the udps server subprocess, and then subprocess.Popen.kill is a nice simple way to end the udps process.

Loading mentions Retweet
Filed under  //   Python   subprocess   UDP   udps  

Comments [0]

Simple C UDP logging server

I've been using and liking this simple UDP server setup to receive and log stats data from iPhone apps. I'm running this simple UDP server (udps), and using the following code to send UDP datagrams from iPhone apps:

The benefits of this setup are no waiting client side, and low overhead server side (just write to a log file to process later). UDP is unreliable so I could be missing a few datagrams, but I'm just sending stats that are nice to have but not necessary. I process the entire log every once in a while, and stream it back over http to analyze the incoming results in real-time.

Loading mentions Retweet
Filed under  //   AsyncSocket   C   Logging   Objective C   Server   UDP   udps  

Comments [0]

Accessing <script> src CGI params in Javascript

This has come up a few times now as a way to avoid server side coding and use Javascript more dynamically based on the CGI parameters passed in the src attribute of the <script> tag.  This script has been cross-browser tested in Chrome5+/Safari4+/FF3.6+/IE6+.

The way this script works is:

  • create/increment global index of this script in the DOM
  • find all script tags currently in the DOM
  • count occurences of this script using the sentinel __JSCGI=1
  • assign scriptElement variable to the current instance of the script
  • parse CGI parameters from src attribute

Being setup this way also allows the script to be included in the DOM multiple times specifying different CGI parameters to determine different functionality for the script. 

A simple demo can be found here using the cgi.js file here.

If you have a better way of doing this please do share.

Loading mentions Retweet
Filed under  //   CGI   Javascript  

Comments [0]