Archive

Archive for the ‘Uncategorized’ Category

Pattern Recognition and Fun With Seven

August 27th, 2009

I admit it. I’m a math and science geek. I am, undoubtedly, a software engineer as well so I better be darn good at working with numbers and recognizing patterns.

The other night, I was playing around with math. When I was younger I would play games with license plate tag numbers trying to make equations out of them. It was pretty easy. By assigning numeric values to the letters using a base-10 system with A = 1, you could take a tag number of AC214D and come up with the individual numbers 123144. You’d then have to figure out some way to make the equation work. The equivalency operator and parenthesis could go anywhere in the equation and you could combine numbers. This particular tag number supports:

(1+2-3+1)*4 = 4
1+2-3+1 = 4/4
12/3*1*4 = 4

You get the idea, but back to the point.

The other day I noticed something about the number 7. Particularly about 7 and 21. I found it odd that the sum of the digits of 21 (2+1) is also the multiplier of 7 required to equal 21. Or 7 * (2+1) = 21. I started playing randomly with other numbers to see if it would work and then I realized that it applies to the following:

7*(4+2) =42
7*(6+3) = 63
7*(8+4) = 84
7*(10+5) = 105

7*(18+9) = 189

(My math language is likely going to start to break down here so bear with me. Anyone have a whitboard?)

The pattern, in case you don’t see it yet, is that the two numbers in the sum, when concatenated as strings, equal the product of the sum and 7. Further, the first number of the sum is always a multiple of two and the second number of the sum is 1/2 the first number (9 is half of 18).

I was pretty excited (yes, excited) until I reached the following:

7*(20+10) != 2010

Rats. Unthwarted, I started to pursue this a little further and realized there was a more subtle pattern. Instead of concatenating the string representation of the numbers, what if the first number was moved over one digit (multiplied by 10) and then added to the second number.
This would mean:

7*(2+1) = 21 = (2*10)+1
7*(10+5) = 105 = (10*10) + 5
7*(20+10) = 210 = (20*10) + 10

Low and behold, it worked. And it works for much larger numbers as well.

7*(14296+7148) = 150108 = (14296*10)+7148

One thing I noticed that I thought was neat until I could easily explain it away is that the product of the numbers abiding by this pattern was always divisible by three. The reason is that your multiplying 7 by (2x+x) This is the same as multiplying 7 by 3x and so all numbers are divisible by 3. Incidentally, if the sum of the digits of a number are divisible by three, then the number itself is divisible by 3.

Turns out there IS a simple reason this occurs. If you multiply 7 by (2x+x) you essentially have (7 * 3x). Thusly, 7*3x = 21x = 20x+1x. So the reason the pattern occurs is pretty simple to understand but I still think it’s pretty neat.

Did I mention I love math?

andy Uncategorized

Comments Now Enabled

July 14th, 2009

I’ve enabled comments as I’m changing the direction of the blog. I’ll be posting more information shortly.

andy Uncategorized

Oops. Bump for ASP.NET WebResource.axd, and Reverse Proxies.

July 13th, 2009

So I hopped in my way-back machine trying to determine what posts, if any, to cull before I take a new approach to this blog — and attempt to be active in its updates. I found an old post, ASP.NET, Web Resource.axd, and Reverse Proxies, and noticed that it was marked as private. So… oops?
It’s now available for all to consume and deals with hiding IIS behind a reverse proxy, specifically Apache for me.

andy Uncategorized

JQuery autocomplete bug fix

December 16th, 2008

Submitted a bug for jquery’s autocomplete plugin that would occur when multiple selections were allowed but the selected had to exist before (multiple and mustMatch both set to true).  Simply put, when the user would try and type in a case-sensitive manner and the word after a space was capitalized, hitting the shift key would result in an invalid selection and would, thus, clear what had been typed.

I have no idea if this fix will be accepted and incorporated into the codebase, but it can be downloaded here if you need it.

andy Uncategorized

Using ImageMagick to create overlayed thumbnails

March 26th, 2008

Gotta keep this short, but it’s been a while and I wanted to throw this on the blog before I forgot.

I have a client that wanted to have a PDF icon displayed over a thumbnail of a pdf document. These thumbnails are generated dynamically from documents that my client was uploading to a custom CMS site. The goal was to place the PDF icon over the thumbnail in the way Windows puts the arrow overlay on a shortcut except the pdf icon overlay needed to be placed on the bottom right and offset from the image. All I have to say is thank God for ImageMagick.

Using ImageMagick, I wrote a little bash shell script that creates a matte for the background, resizes the pdf and places it on the top left of the matte and then overlays the pdf icon on the bottom right.  When it’s done, it deletes the matte.  You can change sizes and background colors through the variables at the top of the script.

#!/bin/bash

appname=`which $0`
appdir=`dirname $appname`

backgroundcolor=white
compositesize='88x100'
coversize='69x90'
overlay=${appdir}'/adobe-overlay.png'

echo $overlay

convert -size $compositesize xc:$backgroundcolor background.jpg

composite -size $compositesize -compose atop -gravity NorthWest -resize $coversize $1.pdf background.jpg $1.jpg

composite -compose atop -gravity SouthEast $overlay $1.jpg $1.jpg

rm -f background.jpg

This script was written for ImageMagick 5.4.7-10 running on RedHat 9 (yes, it’s old). It only works for single page pdfs and the overlay is assumed to exist in the same directory as the shell script. Contact me with any questions or comments.

andy Uncategorized

Using CSS to scale images

December 12th, 2007

Typically you wouldn’t want to do this but if you ever have the need… well, here ya’ go.

The styles max-width and max-height work for images. Just create a style as follows:


.resize400
{
max-width: 400px;
max-height: 400px;
}

Note that the code will only work in Mozilla > 1.5 and IE > 7.0. To make it work in IE 6.0, use a selector and modify the style as follows:

.resize400
{
max-width: 400px;
max-height: 400px;
width: expression(this.width > 400 ? 400 : true);
height: expression(this.height> 400 ? 400 : true);
}

I take no responsibility for how ugly this will make your images.  And forgive the formatting.  I’m fighting with WP at the moment and it seems to be winning.

andy Uncategorized

XML Validation

November 3rd, 2007

I just recently had to convert a DTD from UPS into an XSD as part of a Commerce Server integration project. Wanting to test my code (imagine that), I needed to validate both the XSD and sample XML against it. To create the schema I used dtd2xsd available on GotDotNet — looks like MS got stuck holding this open for a bit.

I then needed to create a couple small tools to test the output. Ok, I didn’t NEED to do it, but I love to write tools and they help me procrastinate. Anyway, after a couple of tweaks to the generated schema to solve a UPA problem I validated that the schema was valid and could be used to reliable validate the XML. The benefit of the schema is that I can generate the classes to handle this data using xsd.

If anyone is interested in the tools, they are simply two .NET 2.0 console applications that were based on samples available online. I’ve attached the binary versions to this post but if you want the code feel free to disassemble them.

Validate.zip

andy Uncategorized