Friday, May 18, 2012

Compass and Straightedge geometry meets HTML5

This is a proof of concept build of an HTML5 engine to perform classical Greek compass and straightedge calculations, as described in this Wikipedia article. In brief, an initial set of points can be created, and then points can be connected by lines, circles can be drawn with one point as center and another as one point in the circumference, and finally the points where circles and/or lines intersect can be added as new points. With those simple rules, angles and line segments can be bisected, and certain regular (equilateral) shapes can be created.

I have created a rudimentary language to describe the adding of points, lines, and circles, and finding their intersections, which I discuss briefly after the demo below. Without further ado, choose a sample "program" to run to bisect an angle or create a regular shape. If you're a fan of Gauss, be sure to check out the heptadecagon.

Thursday, May 10, 2012

Animated prime number machine

This uses the HTML5 canvas architecture, so no IE8 or less; sorry. I have only tested it with Google Chrome, so it may not work in other HTML5-capable browsers. If you find this to be the case, please leave feedback with any errors you see, and what browser version you're using, and I'll see what I can do to get it working for you.

The principle of the prime number machine is of rolling coins and elevators. I created this because I thought it would be neat to have a way for prime numbers to be produced by a set of mechanical rules rather than with pure mathematical methods. Here is a basic description of the rules:

  • If a coin rolls into an empty box, it creates an elevator with the height shown on the coin, and a new empty box appears.
  • If a coin hits the top or bottom of an existing elevator, it bounces off with no effect.
  • The coin's number increments after each cycle
  • The elevators go down a floor during each cycle until the top car is flush with the ground line, then they begin going back up to where they started.

This results in two basic phenomena: All new elevators correspond to prime numbers. When a coin does not have a prime number on it, all of the elevators corresponding to the coin's prime factors have a car flush with the ground.

Enjoy!

Wednesday, December 07, 2011

Encounters with the police

The cops have had an awful lot of bad press lately, for example the interactions with OWS protestors such as this one, and this sobering article from the Sarasota Herald-Tribune, or this report of a former marine killed in his home by a SWAT team who erroneously thought he was a drug dealer. And erroneously thought their team member who tripped had just been shot.

My personal encounters with law enforcement have been qualitatively different. I have interacted with the police 26 times, and although that number seems large, none of them ended in an arrest, and in only two seemed like good material for an episode of Cops. In rough order of occurrence (I'm approximating my age on a few of these), they are:

Wednesday, November 23, 2011

Think of the children!!

No seriously, think of the children. And not the bounty.

About a month ago, I listened to an NPR story on "All Things Considered" on my drive home from work, which concerned Native American children in South Dakota being declared "neglected" in high numbers, and being removed from their families and put up for adoption. The implication is that the South Dakota government was using a financial incentive as an excuse to go all Captain Pratt on the natives, killing the Indian and saving the man, by means of placing their kids in white homes. The text version of the NPR story is available here.

Sunday, October 30, 2011

Tinkering with Calculus

A little document I whipped up on Google Docs after dusting off a calculus book:

Sunday, October 16, 2011

Adelaide

Adelaide Lenora Allerding
October 14, 2011 4:20am
6lbs 12oz, 19.5"

Friday, April 22, 2011

Designing a Notes iPhone web app

"A pedagogical decision hides behind every design decision" -Dan Meyer

For the last few weekends, I've been coding in the early mornings while my wife sleeps beside me, working on a replacement for the broken built-in Notes app on her iPhone. My replacement is usable and stable at this point, and I'm just putting the final polish on the code to remove duplication, improve comments, delete orphan code, etc.

The tools I used to design this are the same as the diet tracker app I wrote for her to track her protein and calcium during her pregnancy: handwritten JavaScript, and Google's appspot.com webserver to properly serve the cache manifest's content type. This was initially going to be a quick hack to learn the API for Web SQL Databases, so I could retrofit database support in the diet tracker, but along the way I learned a lot about designing an HTML Notes application, which was more involved than I anticipated.

This post recounts some of the lessons I learned, and the decisions I made between competing solutions that each had pluses and minuses. Some screenshots of the current product are available below the fold.

Wednesday, April 13, 2011

Emulating iPhone rotating buttons with HTML5 canvases

This is a quick proof of concept tested with Chrome and Safari (which might also work in Firefox... testers?). I'm using timeouts and HTML5 canvas operations to spin buttons, and some DOM tomfoolery to add and remove rows to the document's body. The end result is an approximation of some iPhone settings screens that make you unlock delete buttons before you can remove items.

Enjoy!

Friday, April 08, 2011

HTML5 Web Databases in Chrome, round 1

New fact of life: To keep up with modern web programming, you need to get your head around asynchronous callbacks. To illustrate, here is a quick script I wrote to experiment with Chrome's JavaScript calls into it's SQLite implementation:

Wednesday, April 06, 2011

Rage against the Pitocin-Cesarean Complex

(and how I wrote my first iPhone web app)
"So I got me a pen and a paper and I made up my own little sign. I said thank you Lord for thinking about me, I'm alive and doing fine." - Five Man Electrical Band

Before rambling about my latest tinkerings, I have a small announcement: My wife and I decided to have a baby. She asked me not to make a big deal about it online, not post a broadcast "guess what?!?!" message on Facebook, and in the spirit of that I won't make flowery pronouncements here about the joys of fatherhood, or starting over at 40, or any of the hundreds of other things I would otherwise go on at length about. But there it is: I'm in love with a woman I think the world of, and at the beginning of January, with our third wedding anniversary near us and neither of us having one foot out the door or buyer's remorse, we decided to stop using birth control and try to have a baby.

By the end of the month, Liberty was pregnant.

Saturday, March 05, 2011

Success through embracing mistakes

"The dogmas of the quiet past, are inadequate to the stormy present. The occasion is piled high with difficulty, and we must rise -- with the occasion. As our case is new, so we must think anew, and act anew. We must disenthrall ourselves, and then we shall save our country." - Abraham Lincoln
"I hate math, dad" my daughter said to me a few days ago. It wasn't really a shock to hear it, rather it was the final nail in the coffin, which I'd seen coming for the last few years. The middle school years, sitting in rows, staring at the backs of her peers' heads, listening to lectures, seeing story problems which were so fanciful as to be ridiculous. So Bill's dad's age is 5 less than 3 times Bill's age, and the sum of their ages is 49? Really? Does that sort of thing come up in life a lot?

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.