Sunday, October 12, 2014

Cats are like highschool girlfriends

Cats are like your high-school girlfriends.  You have no idea what they like but when they look at you and invite you to pet them, you drop what you're doing and pet them as much as you can.  Until they remember you're worthless and walk away, leaving you to try figuring out what you did wrong.

Tuesday, August 19, 2014

Boat Table: Redux


For four years at Mizzou, I was on the rowing team.  When I graduated, I ended up with about a five foot long section of an old boat we were getting rid of.  After graduation, before moving, starting a new job, etc., I quickly made it into a table.  Which was pretty awesome.


As a boat-table, it was pretty good.  But I’d always wanted to make the -table part of it better.  Now that I have a house and a workbench, and a wife who only threatened to “tear that table apart” two or three times, I finally had a chance to make the table awesome.

Goals:
  1. Make it cat- and eventually child-safe.
  2. Make it a nice enough piece of furniture to not just live in the basement.
-> Full photo gallery

I already had the boat, and I already had the piece of glass.  Some of the dimensions were pretty tight, so there was a LOT of planning, measuring, drawing, and calculating.  I even used graph paper.  After determining how it would all fit together, the fun work began.

Once again, I loaded the Altima with lumber and lugged it into the basement.  Cut the frame, which was only hard because I wanted miter corners and only had a circular saw.  Three sides went easily enough, but the fourth took a second try.  Then right into one of the parts I was most concerned about. The boat tapers and because the glass and boat dimensions were already so close, in order to fit the boat into the table and still have room for the glass, I had to taper the insides of the two long sides.  Again, tapering a five foot piece about 1 inch.  With only a circular saw.  That was fun.  Routing the dado for the glass required building a complicated jig to keep it straight.  Cut out an apron, glue and screw the frame to the apron, and glue and screw the table together.  Test fit the boat – all still fits.

Cut table legs to length, cut out notches so it fits around the apron just right, then glue and screw it to the table.  Somehow, it was level.  Then sanding.  And more sanding.  And sanding again.  Some with the random orbital sander, some with my hand and a wood block.    I only went down to 150 grit, but it seemed pretty smooth.

Went out to the garage for three coats of stain and two coats of poly.  Cut some plexiglass to fit the ends of the boat, screw in some hooks, and hang the table!

-> Full photo gallery

Friday, July 11, 2014

Amazon, NSA, and The Matrix; or, How I Invented Advertising

I saw a tweet earlier today that was something along the lines of “if a company/organization/government” knows what you’re going to buy/say/do before you do it, how is that differentiated from mind reading?”
This got me thinking that it’s one thing to know you want to buy something, but a whole different thing to know if you are going to buy it or not.  Maybe if Google and my bank partnered up, but that’s a whole new arena of scary.
But then I got thinking that instead of Amazon saying “here’s a shirt we think you’re interested in buying” saying “I know you aren't thinking about buying a shirt, but we want to sell you a shirt, so here’s an ad for a shirt and now you’re interested in buying said shirt.”
Then, just as I started to realize I’d reverse-invented the entire advertising industry, I remembered the scene in The Matrix when the Oracle tells Neo not to worry about knocking over the plate of cookies right before he does and then my head was doing somersaults through itself.

Friday, June 27, 2014

Boat table v2: In Progress

There are grand plans underway to completely rebuild the boat table.  Two days ago I got the basic frame cut, then last night I put in the dado for the glass insert.  Coming along!

Also, I learned that when a board hits you in the face, it hurts.

Wednesday, June 25, 2014

Spring autowired testing problems


Lately I’ve been working on putting tests around some of our legacy (ie, untested) code.  Much of the app uses Spring’s auto-wiring, so we have fields that look like:

private @Autowired FieldValidator fieldValidator;

Spring can wire this together reflectively so there is no need to write a constructor or setters.


Therein lies my problem.


Without a constructor or setter, how can I (easily) write tests that inject mocks?  As far as I can tell, the official solution is to use Spring’s ReflectionTestUtils class that has a method setField to set these private instance fields.  I have two issues with this though.

First, it is very reflection’y, which is to say, not a natural code style.  Instead of action.setFieldValidator(mockValidator) that looks and behaviors like traditional Java, we are stuck with ReflectionTestUtils.setField(action, “fieldValidator”, mockValidator).  Yes, I can read it and know that it’s doing the same thing, but it’s not nearly as intuitive.  Even statically importing ReflectionTestUtils still leaves me with a setField method that requires a target instance and method passed in instead of, you know, passing something directly to the instance.  There’s a bit of a feeling of IoC here, which makes sense coming from Spring; but for a unit test, I WANT the control.

Second, and more importantly, it isn’t safe.  We have powerful IDEs to do everything except make toast (although, I wouldn’t be surprised if there’s an emacs command for that too), yet formidable Spring’s best advice here doesn’t make a peep at compile-time when there’s a flagrant error?  Try to pass in a value that isn’t compatible with the field?  Find out at runtime.  Typo the field name?  Find out at runtime.  Change the target and thus break the rest of the setter?  Find out at runtime.

No IDE will update this line when you refactor your code.  You should be able to change a private field safely basically at no expense, but now you’ll break your test – and won’t know it until it runs.  I understand that a test can and should be tightly coupled the class under test, but if they’re going to be coupled, can’t we at least keep them automatically in sync?


So if you use Spring’s autoMagic Autowired without a constructor or setter, how do you mock your tests?   

I’d love to know.

New programming font


Earlier I was reading Dan Benjamin’s hivelogic.com post of the Top 10 Programming Fonts. I’m not exactly a fontiphile* so it doesn’t bother me the article is from 2009.

For most of my programming life, I’ve just used whatever my editor’s default font is.  Sometimes that’s Consolas, other times it’s Courier New or Lucida Console.  But for being what I spend the bulk of my day looking at, maybe it’s worth a little bit of thought.

I have to commend Dan’s selection and order.  Though I couldn’t exactly describe what was different about each font, I liked each one better than the previous.  Never did I say, “Eh, not feeling this one.”  I decided to start using his first choice: Inconsolata.  Actually, I’m using a modified version by David at nodnod.net called Inconsolata-dz that has straight single- and double-quotes instead of angled.


So far, I’m enjoying it.  Easier to read at the same size and no complaints yet.


* Disclosure: I once was stuck in a car on a five hour trip with two journalism students that were copy-editors at the student paper.  They spent an hour discussing their favorite Serif fonts.  Then an hour discussing their favorite Sans Serif fonts.  Then discussing their preferred kerning styles.  I was weighing the pros and cons of killing them both – they just barely made it out alive.

Monday, April 28, 2014

Cat tree

Our two cats love sitting by the windows and looking outside.  This is a problem however, since they're only about 18" tall when sitting up and our windows aren't that low.  Generally we've been keeping a stool in front of the big front window and another by a back window and keep the shades open some for them.
A while back the missus and I looked at buying a cat tree for them but decided that $60 or $100 seemed crazy.  This was before I'd built my awesome workbench, but I said "Hey, I could build one of those once I build that workbench!"

For about $60 (cheaper if I could have gotten a cheaper carpet remnant) and a borrowed staple gun, I made this awesome cat tree.  The bottom level has a tennis ball in a box for the cats to hunt (they haven't quite figured it out yet).  There's a middle level just big enough for one cat if they want to be alone but still looking out the window.  The top, or sun deck as I call it, it big enough for them both to lay out and look outside all day.  One post has sisal rope that goes high enough for them to stretch up to and another has a second type of carpet for a different texture.  Of course, there's also a dangley feather toy hanging for them to play with.


They seem to like it.


Tuesday, April 22, 2014

Passover Short-takes

Note:

I wrote this a week ago (Tuesday, April 15, the first day of Passover) but didn't get around to publishing it because apparently Passover's become a busy holiday of party hopping for eight nights.

Vegetarian Passover Offering

It sounds like a joke, but I discovered yesterday that instead of putting a bone on the Seder plate (representing the sacrificial lamb), some vegetarians use a beet because it is as red as blood.  Other’s use a sweet potato instead as a substitute sacrificial yam.

Exodus from Work

My drive home from work yesterday reminded me of the Israelites exodus from Egypt.  I was trying to get home as quickly as possible, but traffic kept opening up then slowing down again.  It was like Pharaoh saying “You can leave, no you can’t, yes you can, no you can’t.”  Finally traffic parted in front of my like before Moses at the Red Sea and I hightailed it through there as fast as my 4-cylinder Altima could take me as if Pharaoh and his army were coming up behind me.  I made it through and traffic crashed (figuratively) closed behind me, sealing my enemy traffic behind me and leaving me to wander across I-80 to my home, my Sinai, to pick up my wife.

Diyanu

If we had only one seder yesterday but not a second one: diyanu.
If we had two seders yesterday but the second one ended before midnight: diyanu.
If the second seder had ended before midnight but we didn’t have to work today: diyanu.
If we had to work today but weren’t hosting another seder tonight: diyanu.
If we were hosting a seder tonight but didn’t have to work tomorrow: diyanu.
If we had to work tomorrow but didn’t have plans every night the rest of the week: diyanu.
If we had plans the rest of the week but my birthday wasn’t in the middle of it all: diyanu.
If my birthday was in the middle of it all but I got to have cake: diyanu.
If I got to have cake: diyanu diyanu diyanu.

Wednesday, April 2, 2014

Adding sysouts to external classes in Eclipse

Yesterday, I was debugging through some unpleasant code (man, I was like 40 minutes deep into debugging some recursive reflection) and was getting really irritated with tweaking my conditional breakpoint so I could see the value of something right before it blew up.  The problem, as suggested by the title of this post, was that the code wasn't mine - it was a 3rd party jar (the struts2-json-plugin jar, not to name names).
I wanted to add a sysout, but I didn't have access to change the code.  Finally I googled, and in December 2011, Jonas Helming answered my problem.

Put a sysout in a conditional breakpoint.  And then return false, so the breakpoint never breaks.


Also of course, instead of return false, you can do whatever normal conditional breakpointing you'd like.

Even cooler, through this I discovered the code was blowing up when trying to access a non-public field.  So while later today I will come up with a test case to demonstrate the problem and find a real solution, etc. etc, in the meantime, I added field.setAccessible(true);.  Boom, reflection issue resolved.  Printout, resolved.  As long as I run my code in debug for the time being, it works with no action on my part.



This kind of reminds me of AOP, in the sense that code's getting executed and you don't see where from.  But it fits - debug statements are an aspect of programming that shouldn't be in your code.  At least because this is in your IDE, it guarantees the magic doesn't end up in production code.

Maybe this isn't new to you.  I mean, I learned it from another blog that says it got it from other blogs, but I wanted to share my new trick.  Hopefully it's helpful to you.

Workbench


The Project

Last month I had a much-needed few days off, so I decided to finally build myself a workbench.  This has been a project I've been wanting to work on for around a year now, and I'm thrilled with how it turned out.  Let's just say it's as good as I hoped, but way better than I expected. :)

My design came from a combination of my dad sending me some pictures and measurements of his workbench along with lots of Googling pictures and design plans, along with a health dose of "it's just a frame with some boards, right?".  I'm not planning on making any fine furniture or anything like that; it's more of just a solid project table that can take a beating, not worry about getting messed up, or maybe make some more neat things (like an improved boat table).

I didn't get a picture* of the pile of wood, but I was the guy loading $100 of lumber into the back of my Nissan Altima.  Always a good feeling.

Without a workbench to create this on, the first cut was a little difficult.  As I progressed and had more and more of a bench to work on, it got increasingly easier.  Until of course it was almost complete, I had started loading tools on it, and had to flip it over to add a forgotten brace to the bottom.

The Process

Basically, it's a 2x4 frame with 4x4's for the legs.  Making sure to stagger the screws into the legs so they didn't hit each other was the hardest part so far.  It was pretty cool when all of a sudden I had the frame of the bench standing.

I screwed on some more 2x4's about 18" off the floor (I can't remember how high off-hand, but I know a debating with myself on exact hight; I think it involved the height of a can of paint) as supports for a shelf.  Cut some 2x6's to length, measure and cut out notches to fit around the legs, and screw the boards to the lower frame to make a shelf for tools.  Bam!  Why'd I do the shelf first?  Practice before getting to the main work surface.

The top was basically the same process as the shelf, but even easier without having to cut notches.  I used a 2x8 for the very front to give myself a bit of an extra overhang for clamping things to, and there's overhangs on both ends too.  Right about the time I finished screwing it all down, I remembered that I forgot to leave space between the boards for expansion.  I'm really hoping that doesn't come back to bite me.

This was about when my wife got home, and since I like to cook and had the week off, I'd promised dinner.  I'm quite the Renaissance Man.  Build workbench; take a shower, grill salmon.

The next day, I flipped the bench over and added some extra supports I'd forgotten about.  Two additional ones width-wise for the top and one for the shelf.  Getting these just right after the fact was a little tricky, but I managed.  Flip it back right-side up and drive in a dozen more screws to attach the surfaces solidly to the new supports.

I rechecked it was still level.  It was now flat enough for my purposes.  And I dropped some scrap lumber on it and it seemed to take the beating just fine.

The Finishing Details

I'd bought a decent vice at an estate sale a year ago in anticipation of building this.  Feeling that the section of bench this gets bolted to needed a little extra oomph, I attached some scrap board under the corner of the bench and bolted the vice through that.  It's going nowhere.

I sanded down all the edges and gave the surface a quick pass to make it a little smoother.  I thought about using a finish/stain/paint/etc, but decided to keep it natural.  I read somewhere the best finish for a workbench is (to paraphrase): a lifetime of nicks for errants saws and drills; splotches of paint, glue, and stain; and undecipherable diagrams and measurements.

I ran a piece of adhesive measuring tape lengthwide and widthwise so there's always an available ruler.

There's a surge protector mounted on the side for the power tools, and I hung a plug-in shop light from the ceiling.

* Sadly, a few days after building this my phone's memory card went belly up, so the couple pictures I took during the process are kaput. :(

Saturday, January 25, 2014

Posts to look forward to

I haven't really had time to flesh out any of these ideas into full-fledged posts, but there have been a handful of ideas stewing around in my head and drafts-box.  So, things to look foward to include:
  • How to balance wanting a stable tech stack vs replacing then-advanced-now-outdated tools with now-advanced ones over the course of a long project.
  • We bought new towels!
  • Meandering thoughts about how to develop systems that are easily usable by both an aging workforce with lower computer skills and a new, young tech-savvy one.
  • An attempt to explain why different shades of the same religion all have value (possibly derived from an on-going discussion with my wife's dad).