Rings Are Purchased

Posted: 24th July 2010 by Adam Presley in General
Tags:

Today Maryanne and I went for another round of wedding ring shopping. I am pleased to announce that we have made our final decision and rings have been purchased for both her and myself. We ended up making our purchase at Zales from the manager Chris. It was actually a really great experience working with him to pick out our rings. So many of the previous sales people were… well… too “salesy”. I know that they are supposed to make the sale, but I honestly don’t need to continually hear about “great value” and “superior service” and “fantastic warranty”. Most all jewelry providers offer some type of warranty, and most all are interested in providing a good service, as most all of them want my money!

Chris at Zales was friendly, easy to talk to, and was quick to point out the sales, specials, and not try to shove the $24,000 rings on Maryanne’s fingers. If you would like to see a picture of her ring and Maryanne’s account of the shopping experience you can visit our wedding site, http://www.adamandmaryannewedding.com.

Oh, and yay! Another wedding checklist item marked off the list! Woo hoo!

Today was a busy news day for me. Most of it just personal stuff, but the story of the day in the world of ColdFusion is the departure of Adobe, or more specifically Adam Lehman, from the CFML Advisory Committee. I say it’s big news, but it seems to me that it will be the big event in ColdFusion history that no one will really know, or care too much about. Sad? Perhaps.

For those who do not know what the CFML Advisory Committee is allow me a brief detour to give the 60-second rundown. The CFML Advisory Committee, as defined by their own website is to “…define what is ‘core’ to the ColdFusion Markup Language, how that core should behave and what is considered ‘extended core’ – what language features useful CFML processors should implement – as well as offering guidelines for vendors to provide extensions to CFML in a consistent manner.” It seems like a noble goal for certain.

Read the rest of this entry »

Creating a SMTP Mail Server for Development

Posted: 20th July 2010 by Adam Presley in Development, Java
Tags: ,

While working on ColdFusion applications with Railo on Tomcat I have been piecing together tools necessary to get these applications to do everything I need them to do. So I’ve bolted on Hibernate, a URL rewriter, and so on. Now I found myself needing an SMTP server of some type so that emails generated by the application don’t create a ColdFusion error. I then thought to myself, “Wouldn’t it be fun to write a small SMTP server?” So I did.

Read the rest of this entry »

At home my daughter has a little “spy” safe where she can keep money, rocks, or whatever else she wants in there. This safe is guarded by a passcode, and when you enter the passcode incorrectly twice it makes an alarm sound. Real cute.

I am always stopping by when she’s trying to do something and guess the passcode, annoying her with the alarm sound. Last night it occurred to me to write a quick little program to display all possible combinations for the passcode. So I did. With digits 1, 2, 3, and 4 there are 256 possible combinations.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.adampresley.NumDigits;
 
public class Main
{
	public static void main(String[] args)
	{
		go("1234", 4, new StringBuffer());
	}
 
	static void go(String input, int depth, StringBuffer output) 
	{
		if (depth == 0) 
		{
			System.out.println(output);
		} 
		else 
		{
			for (int i = 0; i < input.length(); i++) 
			{
				output.append(input.charAt(i));
				go(input, depth - 1, output);
				output.deleteCharAt(output.length() - 1);
			}
		}
	}
}

After 15 tries my fiancee gets tired of the noise it’s making and has my daughter come take the safe away from me. My daughter then tells me the actual combination. Social engineering at it’s finest!

Happy coding!

Experimenting with SQL to JSON in SQL Server 2008

Posted: 14th July 2010 by Adam Presley in C#, Development, SQL
Tags: , ,

In the last couple of days at work my friend Adrian (@iknowkungfoo) and I (@adampresley) have been tossing around how we can improve performance on various portions of the application we work on. On of the trouble areas has always been large query sets that then have to be transformed into JSON for an AJAX response.

One little feature introduced in SQL Server 2005 that I had completely forgot about is the ability to take a given query result set and turn it into XML. It’s a very nifty feature, and once Adrian reminded me of this some thoughts started to take shape. First let’s look at how the XML feature works. Below is a query that I ran against a test database that contains address information. Below that is a screenshot of how the result set looks using the XML feature.

SELECT
    id
    , firstName
    , lastName
    , email
    , phone
    , postalCode
FROM address
ORDER BY
    firstName, lastName 
FOR XML AUTO, ROOT('addresses')

Read the rest of this entry »

Download A File From a URL in Java

Posted: 9th July 2010 by Adam Presley in Development, Java
Tags: ,

I was approached tonight with a question on how one could download a file from a specific URL in Java. I had never done this in Java before, but I have done this very same task in C#, so I figured it couldn’t be too different of a solution. After a few minutes of digging here is what you need.

First, using the java.net package you will need the URL class. This class allows you to open a socket connection to a specified URL. This class also has the handy ability to open up a stream to the newly opened connection, allowing you to use the many Java stream and reader classes.

From here we probably want to actually save the file that we have a connection to and put it somewhere on our filesystem. To do this we will use a FileOutputStream class in the java.io package.

The concept is to read a specified number of bytes from the input steam into a buffer, write those out to our file output stream, and repeat until there are no more bytes to read. Below is a full code sample that connects to the Mura CMS website and download the newest version of their awesome software, then save it to a ZIP file on your C: drive (yes, Windows). Cheers, and happy coding!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.adampresley.examples;
 
import java.net.*;
import java.io.*;
 
public class DownloadFile 
{
  public static void main(String[] args) 
  {
     try 
     {
        /*
         * Get a connection to the URL and start up
         * a buffered reader.
         */
        long startTime = System.currentTimeMillis();
 
        System.out.println("Connecting to Mura site...\n");
 
        URL url = new URL("http://www.getmura.com/currentversion/");
        url.openConnection();
        InputStream reader = url.openStream();
 
        /*
         * Setup a buffered file writer to write
         * out what we read from the website.
         */
        FileOutputStream writer = new FileOutputStream("C:/mura-newest.zip");
        byte[] buffer = new byte[153600];
        int totalBytesRead = 0;
        int bytesRead = 0;
 
        System.out.println("Reading ZIP file 150KB blocks at a time.\n");
 
        while ((bytesRead = reader.read(buffer)) > 0)
        {  
           writer.write(buffer, 0, bytesRead);
           buffer = new byte[153600];
           totalBytesRead += bytesRead;
        }
 
        long endTime = System.currentTimeMillis();
 
        System.out.println("Done. " + (new Integer(totalBytesRead).toString()) + " bytes read (" + (new Long(endTime - startTime).toString()) + " millseconds).\n");
        writer.close();
        reader.close();
     } 
     catch (MalformedURLException e) 
     {
        e.printStackTrace();
     }
     catch (IOException e)
     {
        e.printStackTrace();
     }
 
  }
 
}

SES URLs With Mura on Tomcat

Posted: 2nd July 2010 by Adam Presley in ColdFusion, Development
Tags: , ,

Tonight as I’m setting up a new server I wanted to make sure I had URL rewrite ability. Normally this is no issue as I use Apache for most anything web server related. However this time I am setting up a Mura site on Railo running on Tomcat. And yes, I’m using Tomcat for both my Java Servlet engine and my web server. As such I wanted to ensure I have “pretty URLs” for my Mura-based application. In this post I will attempt to show you how to set that up.

Read the rest of this entry »

Grouping Structures in Groovy

Posted: 10th June 2010 by Adam Presley in Development, General, Groovy
Tags: ,

A useful tidbit for those interested in playing around with Groovy. I had need recently to take a structure, or more Groovy-like, a Map, and group by a particular key, and iterate over the grouped items. Turns out to be quite easy in Groovy. Let’s see an example of such a structure and how one would normally iterate over it and display the data.

public def Example1()
{
	def sampleData = [
		[ "name": "Adam Presley", "title": "Architect", "id": 1 ],
		[ "name": "Collin Judd", "title": "Dev II", "id": 15 ],
		[ "name": "Steve Goodly", "title": "Architect", id: 2 ],
		[ "name": "Chris Jordey", title: "Dev II", id: 3 ],
		[ "name": "Ben Nadel", title: "ACP", id: 5 ]
	];
 
	/*
	 * Display existing map.
	 */
	println "Existing structure:";
	sampleData.each {
		println "Name: ${it.name}, Title: ${it.title}";
	}
	println "";
}

As you can see iteration over the structure is fairly easy. Now I want to actually group the structure items by the person’s title, iterate and display the title, then each person who has that title. Here’s how, using the same structure as above.

/*
 * Group the data by title
 */
sampleData.groupBy {
	it.title
}.each { group -> 
	println "*GROUP ${group.key}*";
 
	group.value.each { item ->
		println "Name: ${item.name}, Title: ${item.title}";
	}
 
	println "";
}

When you use the groupBy method you return, through a closure, the criteria to group by. Groovy then gives you a new structure, each key being the value to group by, which is an array of the group matches. Pretty cool!

Hope you enjoyed, and happy coding!