Archive for June, 2010
HTML5 Canvas and Client-side Graphs
We’ve provided our Careerlink clients various metrics for the past fifteen years and have consistently struggled with how to present them. Early on, we decided to render the metrics using JavaScript on the client for a couple of reasons:
- The data rendering would be much more responsive.
- We didn’t need to worry about graphics construction on the server side.
Since there was no client-side raster (or vector) library, all of the charting had to be done with HTML DIV’s and such. There were two disadvantages to that:
- We couldn’t rotate the text to follow the right-hand-rule, so all bars had to be horizontal.
- Printing bar colors required adjusting browser settings (to print background colors) or taking a screen-cap.
The HTML 5 Canvas object provides the client-side raster library. I evaluated a few JavaScript libraries and settled on RGraph to re-implement the client metrics fairly cleanly and easily. RGraph provides a tremendous amount of features and is free for non-commercial use. (Commercial use requires a one-time purchase of an inexpensive license). It was the most mature library I’d come across.
The RGraph library was very easy to implement and renders graphs quickly. I didn’t encounter any issues with its implementation, but I would like to be able to adjust gutter widths (the space around the graph where the labels go) individually.
Thumbs-up for a library that works out of the box.
Extracting email addresses from mbox files
I’ve often been in situations where I want to extract a list of email addresses from an mbox-formatted mail file, usually because I want to send an email to everyone that had sent an email to a certain address. This script will extract email addresses from lines that start with “From:” in a given mbox file, attempting to remove all of the ‘non-human’ email addresses it finds.
The script has extra line breaks to make it more readable. You could remove them for compactness.
The regular expression for matching an email address is courtesy of www.regular-expressions.info.
#!/bin/bash
# This script will parse an mbox file, displaying all of the From: email addresses, removing ones that
# are from postmaster, mail admins, etc
FILE=$1
if [ ! -r $FILE ]; then
if [ -r /var/spool/mail/$FILE ]; then
FILE="/var/spool/mail/$FILE"
else
echo "Sorry! Neither $FILE nor /var/spool/mail/$FILE exists, or I can't read them"
exit
fi
fi
grep "^From:" $FILE | egrep -vi \
"(postoffice|\
postman|\
administrator|\
bounce|\
MAILER-DAEMON|\
postmaster|\
Mail Administrator|\
Auto-reply|\
out of office|\
Mail Delivery System|\
Email Engine|\
Mail Delivery Subsystem|\
Mail.Administrator|\
non.deliverable)" |\
egrep -io "[A-Z0-9._%+-]+@[A-Z0-9.-]+\.([A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)" |\
tr '[A-Z]' '[a-z]' |\
sort | uniq
