(void* dan)

[Flash 9 is required to listen to audio.]

I can’t get enough of Shutterbugg, new track from Big Boi.




Rails Finite State Machine: AASM != perfect, but > Workflow

I recently re-wrote an old model that desperately needed a formalized state machine definition (instead of the fragile logic I originally strung together).  After reviewing both AASM (formerly acts_as_state_machine) and Workflow, I went with the former for a couple of reasons.

  1. AASM seemed to be a bit more mature
  2. It made more sense to describe an event (i.e. state machine input) once, with all the transitions it could cause and its to/from states, rather than defining it a separate time for each state-transition pair it could affect.

For example, one might define a traffic light in AASM as follows:

aasm_state :red, :yellow, :green
aasm_event :timer_done do
	transitions :from => :red, :to => :green
	transitions :from => :green, :to => :yellow
	transitions :from => :yellow, :to => :red
end

Whereas Workflow would have one define it:

workflow do
	state :red do
		event :timer_done, :transitions_to => :green
	end
	state :green do
		event :timer_done, :transitions_to => :yellow
	end
	state :yellow do
		event :timer_done, :transitions_to => :red
	end
end

I suppose it depends on the situation whether it’s clearer to define states - and everything that can cause one to leave that state - or to define events - and all the states on which they operate.

But beware: AASM is not a perfect finite state machine.  You cannot auto-transition out of the initial state via the :after_enter method.  The initializer code will set your model’s state variable to whatever is defined by aasm_initial_state after all callbacks are run, even if the state machine transitions to a new state due to those initial states’ callbacks.

For example, the following code would result in a :red initial state, not a :green initial state as would be expected:

aasm_initial_state :red
aasm_state :red, :after_enter => Proc.new { |x| x.go_green! }
aasm_event :go_green do
	transitions :from => :red, :to => :green
end


There’s a Van de Graaff generator under your hood

…or at least there could be.

My brother, a solid mechanical engineer and muscle car devotee, was diagnosing an engine problem and asked me what I though.  A customer at his job was reporting sparks coming from one of the pulleys on the front of an engine.  This had been seen only a few other times, and the theories my brother heard were just entertaining.  The customer had no idea what was going on, how to fix it, or whose fault it was.

When I learned a little more about the engine, and the pulley in particular, it became quite clear what was going on.  The pulley, normally a solid circle of metal attached to the engine via a metallic shaft, was made of two separate metal pieces; an outer metal ring and and inner metal pulley, separated by a dielectric (rubber, in this case).  If the belt was slipping on the pulley, an electrostatic charge could build up on the outer ring.  The charge would have no way to dissipate like it would on a normal pulley.  This charge could then arc to the engine block when it was strong enough (which isn’t too difficult, as the block and the pulley are fairly close).

So my brother went on site and sure enough, the belt was loose.  A quick touch with the multimeter confirmed that the pulley was acting electrically as a capacitor, and a new (correctly tightened) belt fixed the issue.  What’s interesting is that at some point, a mechanical engineer added that rubber ring as a damper without realizing the electrical implications under a common failure mode.


Negative content-length in HTTP header

I recently debugged a fairly interesting problem one of our HomeField users was having with uploads.  The file was > 2GB so the Flash uploader was not an option, and they were using our HTTP uploader.  But every time they tried, after a couple of minutes, the connection would fail due to timing out.  So I got in touch with their IT staff who graciously captured all the traffic on the uplink during a failed upload via wireshark.

After filtering for the ip address of our upload server, I was surprised to see only a handful of packets, most of which were retransmits.  A deep dive showed that the TCP handshake completed, but the first HTTP packet never heard any response back from us.  It was retransmitted by the client, as per TCP specification, and the receiving software on our server never responded.  Closer examination of the HTTP portion of that packet revealed an interesting header field: content-length: -194931179

HTTP 1.1 specification says that “any content-length greater than or equal to zero is a valid value.”  Unfortunately, Windows NT 5.1 (Windows XP) and IE 8 - according to the same header - have an integer overflow issue when dealing with files greater than 2GB.

This OS level issue was causing the negative content-length, which prevented our server from responding, which caused a confusing (and poor) user experience.  Now I just need to get this user on a *nix OS…


One Leg Chuck

I love good music, especially when it’s being played live in public.  It’s not often that I hear a public performance I particularly like though.  I’m sick of the pile-o-garbage drummers, wandering mariachi bands and the didgeridoo guy at the Bedford L.  The full drumlines are cool, and sometimes there’s some funky asian musician with an instrument I know nothing about who sounds decent.  But for the most part, these folks only make me turn my iPhone to 11.

Last night, waiting for the L at my strategic platform location in Union Square, I heard a musician that I really liked.  He was playing an acoustic guitar and covering Blind Melon’s No Rain with a Johnny Cash meets NIN kind of feel.  I loved it.  So I walked over and payed him a compliment, accompanied by a dollar bill.  Considering that I only heard him for about 5 minutes, he was making $12/hour from just me.

My only point is that I respect this guy.  Like Bleeding Gums Murphy - my nickname for the saxophonist on Thayer St at Brown University - One Leg Chuck is making the world a better place, and I value that.  I just wish he was on iTunes or Amy Street instead of myspace: http://www.myspace.com/fromcaliforniatonewyork

Found him on YouTube, much better live.



For a while, my Google Analytics dashboard looked like the above image.  I could see trends, but it was like feeling the slope of a hill in the dark: no idea how high it went.  That sucked.  After a little research, it turns out that the Arial font in ~/Library/Fonts was somehow causing this Flash failure.  So I removed the file, and things are back to normal.


…driveby culture is both fast and free. When there’s no commitment of money or time in the interaction, can change or commerce really happen? Just because you can measure eyeballs and pageviews doesn’t mean you should.

– The full article from Seth Godin was shared with me by Joe Yevoli. It highlights a significant and great argument for our little app, HomeField.  You could break down web app audience into two categories as suggested by this article: drive-by users and value-driven users.  We have the later, and a working business model that needs tweaking (vs. a business model that needs creating).  As we read from the beginning, via Guy Kawasaki, we need to set out to change the world in a meaningful way. We are.

Don’t mark my app’s email as SPAM

Judging by the number of email outsourcing companies, there is clearly a large problem to be solved.  I’ve had sporadic issues with email being marked as SPAM with HomeField, and then regular issues on my latest project, FoundersCard.  I’ve finally got them fairly well sorted, as far as I can tell…

  1. The DNS records on your name sever must be setup correctly (and verified)
    1. The A record of the domain you’re actually sending mail from (i.e. teamhomefield.com) must point to the IP of the actual server sending the email (in this case 8.12.42.205)
    2. You should also configure the SPF record which is being used increasingly by recipient mail servers to further determine if the sending servers IP address is authorized to send email for the given domain.  My DNS has a TXT record with the value “v=spf1 a mx ptr ~all”.  
  2. rDNS (reverse DNS) must be setup
    • On the server sending the mail, the PTR record must correctly specify the hostname pointing to this sever (teamhomefield.com)
  3. Your Rails setup…
    • You can set from to be any username at the domain configured above, but I’ve found that GMail will mark SPAM unless the following format is used
      • from  ”anything@teamhomefield.com (Anything Else)”
      • Not sure why “Anything Else <anything@teahomefield.com>” doesn’t work..
    • The reply-to is great for sending on behalf of a user
      • reply_to “Dan Spinosa <spinosa@gmail.com>”
    • I am using the following ActionMailer configuration
      • config.action_mailer.sendmail_settings = {
          :location       => '/usr/sbin/sendmail',
          :arguments      => '-i -t'
        }
  4. Your emails content…
    • If you’re sending HTML email, be sure to send it as a multipart email including a text part that closely matches the HTML (which, BTW, should include <html> and <body> tags)
      • In Rails, if your mailer action is named “notify_email”, Rails will automatically create a multipart email for you if you have multiple views: notify_email.text.html.erb and notify_email.text.plain.erb
    • It’s free to check your spam score & deliverability at contactology
  5. Your mail servers IP…
    • Make sure it is not listed by Spamhaus, and remove it if it is.  It is common to see your IP in their PBL, which can easily be remedied.

HTH, and hope I don’t have to deal with this again.


Web Based S3 File Manager

I didn’t want a desktop app just to browse my files on S3 and double check that my code was actually doing what it seemed to be doing. I have no regular need to access these files and don’t want another throw-away app cluttering up my MBP.  So I did a little searching, and found this sweet freebie…

An awesome web based file manager for S3: http://www.s3fm.com/

You got something better?


14
To Tumblr, Love Metalab