May 16

javascript email address sanitizing

I am lazy. Well, not a ‘couch-potato-couldn’t-be-bothered-to-shower lazy’,  but more of a ‘let’s-not-make-things-too-complicated’ lazy. So when it came time to figure out a way to make sure an email address was really an email address on an html submit form, I decided to concentrate on a few things that all valid email addresses have, namely the ‘@’ symbol, and a ‘.’. I know, some of you will say that user@localhost is a perfectly valid email address, and you are quite right about that. It’s not routable on the internet, though, so I am not worried about those types of addresses.

As I am sure you know, most email addresses are in the following format:

bunch.of.letters@somedomain.com

What I decided to do, to keep things simple, of course, was to test for an @ symbol, then test for a . somewhere after the @ symbol. I did this using  the indexOf() and lastIndexOf() functions in javascript.

$(".email").click(function(){

var email = $("#useremail").val();
// check for @ sign
if (email.indexOf('@') > 0) {
// check to see if there is a period after the @ sign
if (email.lastIndexOf('.') >= email.indexOf('@')) {
// everything is ok
// if no username, insert 'anonymous'
if ($("#username").val() == '') { $("#username").val("anonymous"); }
var dataString = "userName=" + $("#username").val() + '&userEmail=' + $("#useremail").val();
$("#output").html("<img src='imgs/ajax-loader.gif'>");
$("#output").fadeIn(3000).delay(3000);
$.ajax({
type:         "POST",
url:         "php/sendit.php",
data:         dataString,
success:     function() { setOutput("Email sent!"); }
});
return false;
} else { setOutput("Invalid Email!"); }
} else { setOutput("Invalid Email!"); }
});
});

The important lines are 14 and 16. Line 14 checks to make sure that there is an @ symbol somewhere in the string. If the indexOf value is > 0, then the next check is done. We use lastIndexOf() when testing for the . because periods may appear before the @ symbol in a valid email address. So to avoid bouncing those types of addresses, we look for a period with an index value greater than the index value of the @. Hence, we know that there is an @ symbol and a period in the email address and we can consider it valid.

Mar 22

update listener.ora with current hostname

Here is a short script that uses SED to update a template listener.ora file and save it as listener.ora.To make it work, you will need to make a copy of your existing listener.ora and rename it listener.template. You will also need to edit listener.template to replace the host entry with myName. SED matches ‘myName’ in the listener.template file and replaces it with the current hostname. Simple.

#!/bin/bash
#
# changeHostname
# --------------
#
# pete tomlinson 22 March 2012
#
# bash script to change the hostname in the LISTENER.ORA file
# this needs to be done every time you launch your AWS cloud machines
# that are not permanent (a.k.a expensive).
#
#
LISTENER='/u01/app/oracle/product/11.2.0/xe/network/admin/'
NEWNAME=`/bin/hostname`

sed "s/myName/$NEWNAME/" ${LISTENER}listener.template > ${LISTENER}listener.ora

/etc/init.d/oracle-xe restart
Oct 15

yet another one of my interests

I have always had an interest in model railroads. I remember as a kid sitting on the basement floor, with my brother’s Hornby/Triang HO scale CN locomotive and car electric train set, the tracks nailed down to a board of homasote, watching it go around and around. It was mesmerizing.

A few nights ago, we built a fire in our fireplace, and I sat watching the fire, slowly letting go of the days’ stresses, when I realized I was feeling exactly like I did as a kid when I sat and watched that train. It seems to me to have been a state of near-statelessness, like meditation. So encouraged by that thought, I’ve decided to get back into the model railroad hobby.

I’ve never been one for prototypical designs, or modelling a specific era or railroad. I’ve always preferred a more free-style approach. My railroads must loop, and preferably be not cluttered with switches or buildings or too many ‘prototypical’ elements, such as ‘yard operations’ I was in the hobby shop not more than one hour ago, and there was a ‘real’ hobbyist in the store talking to the owner in what I will call ‘model railroad language’ (MRL). I could not talk with this man, ever (the ‘hobbyist’, not the owner). I have no interest in the hobby beyond a reasonable layout that is entertaining to build and simple to run. Scheduling cards, digital sounds, and discussions about ‘isolated frogs’ have no place in my interpretation of the hobby.

With this in mind, I came up with the following N-Scale plan, using Atlas’ Right Track Software 10.0, a free application that let’s you design layouts, among many other things. Since Atlas offer this software for free, I try to buy as much Atlas hardware as possible.

Here is a pic of the layout I have in mind.  It’s going to be built on a 2′ x 4′  platform. I am using a 1/2 inch board of plywood as the base, and a  1/4 inch board of plywood for shaping terrain. Forthcoming pictures will explain what I mean by that more clearly. The small inner loop is actually graded up to 2 inches where it crosses over the lower loop:

Oct 10

Garbage Weirdness

I was experiencing some jQuery-UI weirdness with my garbage page; the tabs were not tabbing, so to speak. Turns out the css file had cannibalised itself. I have no idea how or why, seeing as I have not even looked into that file since sometime in August.

At all events, eveything is working properly again since I replaced the broken file.

http://petetomlinson.com/garbage

Sep 17

LEGO Update

NXT Software works fine with VirtualBox. You will need to load the proper drivers for your usb-to-serial cable in the guest operating system.

I have even got RCX Mindstorms 1.5 working (sort of). The Mindstorms IDE has one requirement: Paging File must be set to custom, with an initial size of 128MB. This averts a pagefile error thrown by DirectPlayer (which is required to run the Mindstorms IDE.  It doesn’t seem to like to actually download applications to the brick, although the diagnostics seem to pass. If you are using BrixCC, you are good to go although you won’t be able to use Lego’s block-style of programming. You will, however, have a larger choice for Brick OS’es, such as pbForth, or NQC (not quite C).

I am too sleepy to post pictures, or instructions right now, but hopefully soon…