Friday, January 21, 2011

4,046

I've disabled this blog's Google Analytics feed. The feed assures me that there were 4,046 visits here over the past year, most of which occurred after a swell of visits in August '10 when I started posting about various coding experiments I was working on. From that time forward, there were over 100 visits per week to the site, most of which turned out not to be loyal fans, but rather one time visits referred here by search engines.

Sunday, January 16, 2011

OSU Math Placement B-test, 1 of ???

A little experiment with Google Docs, Wikipedia's TeX engine for rendering math equations, and trying to help my wife pass her college math requirements.

Where's that Check 21 2 of 2 I promised for yesterday? Still coming, I just need to get my inspiration back after a few, um, let's call them "challenging" weeks at my day job. Anyway, enjoy!

B Test study guide, question 1a

Sunday, January 09, 2011

Adventures in Barretting

In an attempt to be funny, I made up the term “Barretting” to describe the act of driving to Tennessee to see my friend Chris Barrett. My wife, Liberty, and I had some fun throughout the week using the term whenever it would fit. “Well, we don’t need to stop at the store on Friday, we can get to that when we’re back from Barretting.”

Chris introduced us to the “Flying Saucer” pub last year, which has a giant wall full of taps (possibly 20 or 30), as well as friendly wait-staff, not too intolerable prices, and a 100-beer tour that gets you some sort of free party there and your name on a plate if you finish it. Liberty and I went once with Chris to the Memphis location, and have been twice to the one in Nashville while taking an impromptu “let’s see where this road takes us” vacation.

Tuesday, December 28, 2010

Check 21 Java app - 1 of 2

Extracting data and images from Image Cash Letter files

Background

There are many terms relating to Image Cash Letter files: Check 21, DSTU X9.37, X9.100-187, and check truncation, to name a few.

"Check 21" refers to an act passed in 2003. From Wikipedia's "Check 21 Act" article:

Thursday, December 16, 2010

Java greyscale conversion

Using Java, how do you convert a color image to greyscale? The most straightforward answer I've found was on Code Beach, and is as follows:

Saturday, November 20, 2010

Roman numerals redux

A simple JavaScript function to validate Roman numerals, convert them to Arabic numbers, and back again.

I checked Google Analytics this morning and noticed I've been getting a lot of hits on my October 9 entry on JavaScript Roman numeral conversion. In brief, I wrote a simple function to take a number and build its Roman numeral equivalent. While I was mulling it over this morning, I spontaneously thought of a method to validate and parse a Roman numeral and turn it back into Arabic numbers using regular expressions.

Monday, November 15, 2010

The crazy geometry of basketball courts

I saw an interesting question on dy/dan today about posing basketball-related math questions to students. One of the reader suggestions was to talk open-endedly about the geometry of the court itself, to which Dan suggested writing a program that would draw a court given two mouse clicks to denote the baseline. That sounded right up my alley, so I wrote one.

Before starting to code, I had to learn about the measurements of a basketball court, and I was a little surprised by what I found. First and foremost, every league has its own sizes for every piece of the court, most differing by a foot or less. The biggest discrepancy is with the length of the court, which is 10 feet less for high school than for NCAA and above, or about 2 running steps. Naturally the FIBA league had measurements rounded to meters where all the US leagues are rounded to feet.

Thursday, November 11, 2010

Jury Duty

On Wednesday, when I was up walking around to limber up after reading in a chair for a few hours, I came across the bulletin board in the jury pool waiting room. The board had several local newspaper op-ed pieces on jury service that may as well have been written by a chatbot, randomly generating from a dictionary of truisms and catch-phrases. "Ten Reasons I'm Glad I Served. 1: To see the inner-workings of the law. 2: To meet new friends..." Hence this post, a gritty look at my experience being on jury duty. The management summary: my experience was interesting, but the process is flawed. Like Randy Pees used to say, "Our legal system is terrible. The only one worse than ours is everyone else's."

About two weeks prior to my reading of the platitude-laden corkboard, I received a summons in the mail to report for jury duty. I tried to get out of it by replying with a letter claiming a child-care burden, as I pick up Scout from school on Tuesdays and Thursdays so that Liberty can attend later classes on those days. I got a phone call the next day telling me basically to suck it up and make other arrangements. Conveniently, this did not prove to be an actual problem: On Tuesday we were released before 5pm, and the courthouse was closed today for Veteran's Day.

Sunday, October 24, 2010

Awesome Ted talks

(plus some David Byrne worship, because he rocks)
(and Seth Godin at GEL, who also rocks)

Saturday, October 23, 2010

Fun music videos, mostly 80s

Some videos that are cool. No reason.

Saturday, October 09, 2010

JavaScript Roman numeral calculator

Yesterday I saw a homework question on a coding forum I frequent regarding turning Arabic numbers into Roman numerals. Homework questions are a strange breed. Most of the time the posters are blatantly cheating, some times they are up front that the question is for an assignment and they just want a push in the right direction. Responses range from helpful, following the Wikipedia "assume good faith" mantra, to cynical, to pretty damned rude. Forum admins enjoy flexing their dictatorial muscles in these cases, posting warnings, flames, and deleting posts.

My mantra in these cases is simple: If the question is interesting, I try to answer it. If the poster isn't cut out for a programming career, getting my answer isn't going to change that. If he is, he's going to be asking his peers a lot of questions over his career, as no one is born with an innate gift at coding; it's a learned skill like anything else. The young "super hacker" is generally the geek equivalent of a bully - not as skilled/tough as he pretends.

Thursday, October 07, 2010

Korn shell hack of the day

or, "Scope creep and you, a typical example of the modern IT project"

Sometimes I find myself knee deep in a complicated shell script that probably would have been better off written in perl or Java. Today was one of those days. What started as a simple script I wrote for managing sftp traffic to a couple vendors has been transmogrified to handle calling Glub to do an ftps transfer (the "other" secure FTP) from a vendor, then delivering the files to an internal Windows share drive. So far so good, but feature bloat ended up straining my creativity to tackle each new problem, and ultimately saddled me with a workable solution that, while interesting, is sort of a stinker.

The connection to the Windows share was supposed to be via a mounted drive. I would copy the files to a Unix directory, and Unix would manage the SMB transfer transparently. This turned out to be unsupported by our data services group unless the Windows server in question was virtual. It was not. So suddenly I'm on the hook for adding SMB support to the process.

Sunday, October 03, 2010

Picnic with the missus

Liberty got this cool wicker picnic basket on eBay a while ago, and we decided to take it out for a spin yesterday. One of the better side effects of "bill week" (when your bills all come due at once, and your budget spreadsheet looks a little scary) is that you can find fun money savers that double as relationship builders.

Instead of spending $20 on a movie and snacks just to sit in the dark and be quiet, let's go out for a walk in the sunshine and talk to each other... for free. Instead of stopping for greasy fast food somewhere, or spending more at a better restaurant, let's cook up some food for lunch, and take it with us somewhere. In this case, "some food" was steak cut into strips and fried up with pepper, sweet Italian mini bread, cheddar cheese cut into slices, some green onion, and a refreshing carbonated beverage (the basket has a cool separate area for bottles), and "somewhere" was Highbanks park.

When we got there, we found a long trail that didn't seem to have a lot of people on it, and proceeded to hike around looking for unofficial exit points: Good places to hang out that are accessible, hidden from the trail, but without signs saying not to go there. What we found was here:

Thursday, September 30, 2010

Bezier Curves as Ellipses

A couple weeks ago, I was exploring the source code for the Java runtime classes, trying to figure out exactly how Java draws a circle, and was surprised at what I found. A circle can be defined as an instance of the java.awt.geom.Ellipse2D class with equal width and height. Graphics2D attempts to draw the Ellipse2D shape by calling for its PathIterator. A PathIterator returns segments of the shape in the form of SEG_MOVETO, SEG_LINETO, SEG_QUADTO (quadratic Bezier curve), SEG_CUBICTO (cubic Bezier curve), or SEG_CLOSE. An Ellipse2D contains an initial MOVETO, four CUBICTO segments, and a final CLOSE.

I eventually got my head around what that meant and its implication: The standard 2D graphics library doesn't concern itself with center points and radii, or foci, or pi. In fact, it doesn't even render a real circle, but a very close approximation. It renders four cubic Bezier curves representing 90 degree arcs of the circle. I found this discovery strange at the time, but on reflection it made sense.

Tuesday, September 28, 2010

Form validation using custom attributes

Background

A couple months ago, a friend's daughter came to me for help with a website she was writing for a diabetes seminar registration page. The input form needed to ask the user if they had diabetes, and if so, whether it was type 1 or type 2. She was using Dreamweaver, and was having difficulty getting the form to behave correctly with Spry Widgets form validation.

I wasn't familiar with Spry Widgets (or Dreamweaver, for that matter), so I asked her to show me the source code. We hacked out a semi-functional solution in a few minutes, but I wasn't very happy with it. Spry had input validation that intercepted form submit events. You defined some JavaScript objects declaring what input elements were required, and what format they had to be in (e.g., the input must look like a phone number, or it must look like an email address). When you submitted the form, anything that was wrong gets highlighted red, and you have to go back and correct it.

The definition syntax for a single field looked like this:

Monday, September 27, 2010

Building a Java Applet Sudoku Bot

(Warning: huge and crazy, with no practical target audience that I can imagine.)

Background

I've been interested in the game of Sudoku since it became popular a few years ago, and have often daydreamed about what approach one could take to programmatically solve a puzzle. Although I'm not an expert player, when I play I find that I see complex hints about what numbers *must* go here, or *can not* go there. Explaining to another person the logic of each choice would be fairly simple, but coding a straightforward approach for a computer to do the same thing had, until recently, eluded me. I have now successfully licked that problem, and have written a moderately functional solver applet in Java.

This entry takes you through the start-to-finish process of the applet's creation. I decided from the outset not to make this a Swing applet, and to manage event handling and painting directly.

Sunday, September 26, 2010

Java Swing applet to calculate Fibonacci numbers

I understand this is a common skill builder in Java courses. To write this from scratch, you need to understand Swing input fields, layout management, action listeners, error trapping, and a little math. It also helps if you already think the Fibonacci sequence is cool.

So to help you seekers of assignment solutions, here you go. Study it, though, rather than just copying it wholesale. Maybe I'm not making this as streamlined as I should, or maybe the xor business is too much trouble for the modest speed and memory boost.

First, the working applet:

Saturday, September 25, 2010

Concise Perl

One of my favorite tech blogs is the relatively new Ksplice Software Blog, recently made popular with its unique solution to the recent Linux kernel exploit. In late May they posted an entry called The top 10 tricks of Perl one-liners, which brought back a slew of memories from several years ago when I was doing lots of system admin work from a Unix shell prompt, and also taught me a regular expression switch I had never come across before: \K. Commandline junkies being who they are, there was also ample discussion in the comments on everyone's favorite trick or idiom.

A few days after reading the article, I brought my eldest daughter, then 13, to work with me. She recently started high school, and was hanging out with me in the office completing a summer book summary assignment for an honors class due the first day of school. "Dad, what does 'concise' mean?" she asked me, while looking at the instructions. I replied something to the effect that it meant expressing a lot of detail in as few words as possible. The exchange reminded me of the above blog article, and also of some perl mojo I whipped up a couple weeks earlier at work.

Background

Monday, September 20, 2010

Detecting when a mouse cursor is near a line

Warning, this post contains math!

First, I'm abandoning all of my "recreational" coding projects save one: a java applet for my wife to design clothes. Building a CAD system from the ground up is painful and slow, and I can't tinker any further with other fun things without sapping creative energy I need for my day job.

In the current early stages of this project, I've been thinking a lot about design, and what I do and don't like about similar programs. One of the things I don't like about simple CAD-like tools is their approach to manipulating existing lines. The line's endpoints are draggable, and so is a single point in the middle, but the line itself is not. Take this screenshot of Visio, for example:

Thursday, September 16, 2010

Quick experiment with Java 2D, JComponents, and MouseListeners

Here's something I've been toying around with for a couple days as, of all things, a relaxation experiment. Basically when a shape is hollow, you can drag it to change its size. When a shape is solid, dragging positions it. Clicking on a shape without dragging flips it from hollow to solid, and sets its z-order to the top.

Enjoy!

Thursday, September 09, 2010

Labor Day adventure weekend, and the death of a friend

My wife is a saint. If you have any sort of relationship with Liberty, that may not be the first descriptor that jumps to mind, but I assure you it's true. In fact, there was a time when I believed her assertion that she has no empathy, but now I know that for what it really is: a complete ruse. It's her version of my blank expression that I meet most people with, the thing that's a little off-putting and helps me extricate myself from conversations, the thing that lets me keep my distance instead of getting too involved, and has nothing to do with what's actually going on upstairs.

Thursday, August 26, 2010

Fantasy RPG applet in Java, the early stages

For the past week I've been dabbling at home with building an old school Fantasy RPG, and I've been enjoying the hell out of it. It isn't playable yet by a longshot, as so far I've only got a combat framework and map scroller functional. For what the first real build of this will look like, think Bard's Tale 2. Think Ultima 4. At least, that's what I'm thinking now, as turning this into Diablo or World of Warcraft is still a long way off.

I got the itch to design a game after toying around with Google's App Engine framework. I wrote a slideshow unwrapper for my wife to use when browsing on Ebay or Etsy, which lets you paste in several URLs with slideshows in them, and builds a single page containing all the images. App Engine's "fetch url" function and the ability to execute arbitrary Java code made that a snap. While learning the App Engine ropes, I found that it can serve an applet, and receive an arbitrary serialized object and store it in Google's "data store".

In other words, you can play a game in an applet, and save the game state to the data store.

Wednesday, August 18, 2010

A lightweight Java solution to searching image archives

About a month ago, my wife found a collection of dress images, one of her favorite things to search for online, as she is fond of analyzing how clothes are put together and then making her own. The collection was in the form of a Shockwave file, in a neat little scroller app that lets you scan through dresses seen from different angles, find what you like, and go buy it. My wife was unable to save image files from the app, so she elicited my help in the matter.

Sunday, August 08, 2010

Solving the Facebook “Gattaca” puzzle

If you're coming here looking for an algorithm or complete code to solve Facebook's Gattaca puzzle, then first, you're a damned cheater and nobody likes you. Second, they'll never hire you anyway once they realize you couldn't do it on your own. Third, you've come to the right place!

Google assures me that there are publicly available solutions for this puzzle already, and this particular puzzle has been posted in the Facebook careers section for a while now, so I'm going to break with their recommendation to not distribute complete solutions.

Monday, June 28, 2010

My Strange and Awesome Karate Kid Dream

I recently saw the remake of The Karate Kid with Jackie Chan, and enjoyed it quite a bit. In case you haven't seen the movie, I won't say anything about the movie other than what's in the trailer. One of the winking nods to the original was Mr. Han (Chan's recasting of Mr. Miyagi) not catching a fly with chopsticks, but rather killing one with a flyswatter, then using chopsticks to pull it off of the wall and throw it away... a main plot point in the dream I had last night.

My dream was fairly brief, and a bit of backstory was implied, but not shown in the dream itself: Mr. Han now runs a martial arts school. One of his students is a teenaged girl from a culture not very... how shall we say... "women's studies friendly". (It was unclear where specifically she was from - maybe Iran, maybe an African village. My dreams are ambiguous like that). She had an overbearing father who was waivering between supporting his daughter at the school, and pulling her out to have her veiled, executed for being alone with a male non-relative, circumcised, what have you. Mr. Han, sensitive to her plight, does what he can to keep her healthy and free.