Access Email Domain Query

Working for an email database company, I spend quite a bit of time using Microsoft Access and over the past three years I’ve learned quite a few useful tricks. One such query I run from time to time is stripping out the domain for an email address. Lets say you have a field in Microsoft Access called EMAIL and you want to strip the domain out from that, you could run the following query:

SELECT EMAIL, Right([EMAIL],Len([EMAIL])-InStr([EMAIL],"@")) as Domain
FROM TableName

That’s it, pretty simple. Read up on the Right() function here. In our case, the first parameter in the function will be the [EMAIL] field. The second parameter is doing two things, first we take the length of the [EMAIL] string by calling the Len() function and then subtract the position of the “@” sign in the email address.
So, for user@hotmail.com the query would literally translate as follows:

  • Right(“user@hotmail.com”, Len(“user@hotmail.com”)-InStr(“user@hotmail.com”,”@”))
  • Right(“user@hotmail.com”,16-5)
  • Right(“user@hotmail.com,11)
  • hotmail.com (hotmail.com is returned because they are the 11 rightmost characters in “user@hotmail.com”)
Advertisements

Dell 2007WFP (sweeeeeet…)

Well, it’s been a long time coming but I finally have a computer monitor that fits me perfectly. I’ve had a 17″ normal CRT monitor since my college days (it’s somewhere around 4-5 years old) and while there is nothing wrong with it… I had no clue what I was missing. The 2007WFP boasts a 20″ wide-screen and has a native resolution of 1680X1050. I’m telling you, my desktop never looked so damn sexy. My 17″ monitor I normally run at 1280X1024, the new 2007WFP is about a 35% increase in desktop space. That may not seem like much, but looking at my two monitors side-by-side, there is no comparison. In fact, now when I look at my 17″ CRT the thing looks slightly blurred and I wonder how I ever used the thing. Typical users (and by typical I mean old people who can’t read small text) of a 17″ monitor probably have a 1024X768, now in their case the increase in desktop space is more than double.

First thing’s first, don’t buy a monitor from Dell unless they are offering discounts or you have a coupon. Dell regularly has sales on their website and if you are in the market for a monitor, wait until Dell has theirs on sale. My monitor was ordered on a Tuesday night (at about 11pm), so I figured my order would take a day or two to ship, and I didn’t pay extra, so the Dell website said 3-5 business days for shipping. To my astonishment the delivery man was knocking on my door Thursday at about 5:30pm. I didn’t expect it until the weekend or beginning of the following week, so that was a great surprise. Anyways, I’ll tell the rest of the story with some pictures (unfortunately they were taken on my old 2 megapixel digital camera).

Inside the box:

The stand on top:

After taking the stand out:

Oh yes Dell, you know how to excite a geek:

After following the very complicated instructions:

*Drool:

The ol’ CRT gets a new home:

Yes, I’m a computer geek:

Unfortunately my camera does not do the monitor justice, it is bright, sharp and damn sexy. In fact right now (I started this post a week ago and never got around to finishing it) I’m no longer using my CRT, I connect to my laptop via RealVNC. Oh, I should mention that the monitor does support more than one input method (VGA, S-Video, Composite, and DVI-D), but I’d rather not have to hit the switch input button everytime I want to look at my laptop. I was a little bit hesitant about choosing this monitor, but I don’t have a single complaint, I can never go back to old clunky CRTs.

And now I have all this space:

Simple AJAX

For those of you that don’t know what AJAX is, you probably want to skip right over this. Anyone else who has heard of AJAX, or maybe is a little overwhelmed by how to use it, let me see if I can make your life easier. I recently wanted to implement some AJAX coding on a website, but I was a little bit annoyed at how the XMLHttpRequest implementation worked. It didn’t really provide me with the flexibility I wanted and frankly, was overkill for what I was doing.

Let us say that you have code somewhere on a webpage that does a query to a datasource based on a URL variable (my examples are in Cold Fusion, but you should get the idea). The below could be a section of code on any page.

home.cfm
<cfif isDefined("URL.variable")>
<cfquery name="exampleQuery">
SELECT *
FROM table
WHERE field = #URL.variable#
</cfquery>
<cfoutput query="
exampleQuery">
#exampleQuery.field1#
#exampleQuery.field2#
...
</cfoutput>
</cfif>

The flaw in this design is that in order to pull new information from your datasource, you need to wait for the entire webpage to reload. One of the advantages in using an AJAX-like framework is that you reload only what you need to. Let’s look at the above code and see how we can improve page performance by only reloading the section of code above. The first thing to do is remove the code that pulls the information and displays it and place it in a new page and between a <div> tag. So the code above could be removed from home.cfm and placed in a new page:

getData.cfm
<div id="QueryResult">

</div>

After moving this data we need a placeholder where the data will be dynamically inserted back in.

home.cfm
<div id="QueryContent"></div>

The trick to getting the browser to request the data and reload it involves a bit of javascript and the use of an <iframe> which the user cannot see. The javascript sends a request to the hidden <iframe> and then a little more javascript updates the content on home.cfm. First, let's add the <iframe> and javascript.

home.cfm
<script type="text/javascript">
function getData(urlVar){
document.getElementById('hiddenFrame').src = 'getData.cfm?variable=' +
urlVar;
}
</script>
<iframe name="hiddenFrame" id="hiddenFrame" src="" width="0" height="0" frameborder="0"></iframe>
<div id="QueryContent"></div>

The function above points the hidden <iframe> to the page we created which gets the data we need and displays it to the user. The final and most important step is to add some script to the page which retreives our data.

getData.cfm
<script type="text/javascript">
function UpdateParent(parentContent, content){
var pd = parent.document;
pd.getElementById(parentContent).innerHTML = document.getElementById(content).innerHTML;
}
</script>
<div id="QueryResult">

</div>
<script type="text/javascript">
UpdateParent('QueryContent','QueryResult');
</script>

The javascript above in UpdateParent is rather simple and just swaps out the content between the <div> tag hidden in the <iframe> and the <div> tag on home.cfm. What is really happening is the hidden <iframe> is doing all the work, then the javascript at the bottom of getData.cfm simply updates the home.cfm page which the user is viewing. The final step would be to replace your links with the javascript call on home.cfm. For example, instead of <a href="home.cfm?variable=1">Load Data 1</a> you would have <a href="javascript:getData('1');">Load Data 1</a>

It should be mentioned that this is not true AJAX as it does not present you with any status as to the current state of your request (ie if the query has finished, or is still running). Also, when debugging you will have to change the <iframe> to a visible height and width so you can see any error messages. Unless you are loading a incredibly large amount of data, this method should work just fine. When the user clicks the link, their browser will still display an animated icon indicating that data is being loaded. I have found that I am able to drastically increase performance by using this method and it provides me with a great deal of flexibility. Your getData.cfm page could be a template that you simply populate based on a query, which ultimately saves time waiting for pages to reload. The faster our users get what they want, they happier they are.

Why the Wii?

Remember the Power Glove for Nintendo? No?! Well for those of you that don’t, it looked something like this:

It was for Nintendo… and it totally sucked. My brother and I got this elaborate piece of crap most likely after begging our parents to buy it. Although it was a long time ago, I remember waving my hand around trying to get Mario to jump and becoming incredibly frustrated by his non-responsive diet-needing ass. Was it Mario’s fault? Of course not, perhaps it was due to the fact that you had to be wired like Robocop to get the damn thing to work. That flashy ad above is great and all, but look at this thing:

“The glove was somewhat difficult to use; in order for the glove to register with the ultrasonic sensors, one had to keep their knuckles pointing at them at all times. In addition, since each finger had 4 positions, it is difficult to have disparate fingers in different positions simultaneously. Thus, while it was possible to control 16 different states simultaneously, most people have difficulty keeping the ring and index fingers straight, while bending the middle finger. [-wikipedia]” Somewhat difficult to use? Somewhat… try impossible. Unless you are a master finger pupeteer you ain’t getting shit done with this thing.

Now Nintendo has been hard at work developing the Wii. Anyone who has heard about the Wii knows about it’s unique motion-sensitive remote. Umm… is it just me or is this thing the Power Glove all over again? Sure technology has come a long way and it’s wireless, but that doesn’t eliminate the fact that motion-sensing remotes aren’t for traditional console gaming. I really cannot see how this remote is going to make a game that much more fun. I’m sorry Nintendo, but do you really expect me to stand up in front of my TV and play virtual paintbrush or a thrilling round of golf with that thing? Just think, you too can look almost as cool as these kids:

The remote will appeal to kids between the ages of 5-11… anyone older than that… I have a hard time believing they will be standing in front of their TV for hours on end battling through Red Steel trying to make themselves think they really have a sword in their hands. However, I have yet to actually try the Wii’s remote, so I’m mostly speculating here… it is Nintendo after all, hopefully the Wii’s remote won’t suck as bad as the Power Glove.