20120306

Rails is driving me mad, part 1

In django, if a robot is spidering through your site and hitting non-existent links, you can suppress the email warnings about 404s with a simple configuration change, as explained here.

So how does one do this in Rails?

After a half-hour of fruitless searching I stumbled across this blog post and this piece of software.  The software does a lot more than I want, in particular it takes over the exception notification mechanism.  So I followed the instructions in the blog post, copy-pasting the code into my app, and so far it seems to be working OK.

This is not the magical experience I was promised!

20120206

Data Mining Degree?

The Data Collective blog just received the following solicitation:

Hello,

I am Matt with WebSponsors.org. My company represents a leading provider of online education. They would like to purchase ad space on your site's page - blog.datacollective.org/hacking-education-data-analysis-submission-tips-for-success-by-the-numbers.

It would look like...

"data mining degree"

with a link to our client's site. We can pay you $65.00 via PayPal as soon as an agreement is made for this ad space.

Please let me know if you are interested. Thanks for your time & consideration.

Matt
matt@websponsors.org
1-888-853-3601

Disclaimer: You have been selected to participate due to the high-quality of your website. If you accept to place this advertisement on your website, you are accepting the Advertiser Program Policy which can be found at http://www.websponsors.org/advertiser-program-policy.php. WebSponsors.org reserves the right to accept or reject this offer for an advertising placement on your website.
Reference Code: 782034#

20120204

MIT Battlecode!

Two Sigma has been a sponsor of MIT Battlecode for six years now. It's a programming tournament where teams of kids spend a month coding a virtual robot army to battle against other students' virtual robot armies.

Here's what a match looks like:

There's a lot going on in a battle, and it can be confusing. So today my colleague Lee Lin and I coded up some analysis to help us understand what's going on during a match. The x-axis is location on the battlefield -- the left side is one team's home base and the right side is the other team's. The y-axis is the amount of fighting force each team has at that location. We've taken the 2-D battlefield and projected it onto the axis running between the two bases.

The Battlecode code is all java so we started the analysis there. The AffineTransform class came in handy for the projection math. The java code dumped its frame-by-frame data in as valid JavaScript code. The visualization is a Highcharts chart being manipulated by JavaScript code on a simple timer.

The core of the updating code is offensively simple:

function updateData() {
  for (i=0; i<2; i++) {
    chart.series[i == 0 ? 1 : 0].setData(thedata[roundNum][i]);
  }
  if (roundNum < thedata.length-1) {
    roundNum++;
  }
  setTimeout(updateData, 15);
}

The chart is in an object called "chart". The data for the entire match is in a two-dimensional array called "thedata". The function "updateData()" gets called every 15 milliseconds -- we'd like a framerate of 60fps if possible. At the end of updateData() we call setTimeout() which asks JavaScript to call updateData() again in 15 millis.

20120127

Ruby/Rails is confusing for noobs

Here are my questions about Ruby/Rails:

  • After automagically generating the model/view/controller code for a given object, I then want to customize the HTML/CSS/JS for some of its views.  What's the right way to do this?  Do I directly edit the files like "show.html.erb"?  If I do, then don't I lose the ability to automagically update them when I add fields to that object?
  • ERB vs HAML appears to be a religious war... has anyone cleanly summarized the pros and cons?  I would rather not choose randomly, nor spend two hours reading articles about this just so I can decide.
  • Rails 3.2 came out on Jan 20.  Should I use it?  Are Rails releases typically well-tested upon release, or do they typically have bugs that I should hang back and let other people find?
  • Speaking of Rails 3.2, the wonderful site http://api.rubyonrails.org/ seems to have already switched to showing the 3.2 API.  But I'm using 3.1... how can I see the 3.1 API documentation?  Shit, just noticed that http://guides.rubyonrails.org/ switched over to 3.2 as well.  Must I therefore switch?
  • To generate the 3.1 documentation on my own machine, are these the steps I must follow?  http://www.nullislove.com/2007/05/29/rails-documentation/  This post is from 2007, I expect things have changed since then!  Here's more confusing garbage from 2007: http://www.ruby-forum.com/topic/113997  Sadly all the top hits appear to be from 2007.
  • Where do I put the static images that my site is serving?  /public/images or /app/assets/images?  I would like to use image_tag to generate my image tags.  http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html claims that "By default, Rails links to these assets on the current host in the public folder" , but in my own system the generated image_tag has a src of "/assets/img.png" which ends up being served from the directory /app/assets/images.  So, the docs are lying, they are not linked to the public folder.  Or is my setup misconfigured somehow?  Which files in my setup control this behavior?

Here are the meta-questions:
  • Where can I find best-practice source code for non-trivial sites built in Ruby/Rails?  I could then mine that code as a source of examples.
  • Where are the best up-to-date tutorials and references for Ruby/Rails?  Videos don't count because they're not searchable and their effective bit-rate is excruciatingly low, compared to well-written text.  http://guides.rubyonrails.org/ is nice but appears to leave many important questions and issues unanswered
  • Where can I best find out how to do X with Ruby/Rails?  For example I want to use jquerymobile for my UI.  What's the best way to integrate jquerymobile into Ruby/Rails?  Should I use a Gem?  There appear to be three competing gems for this.  And on further inspection they each seem to be pretty trivial, and potentially out of date.

20111208

Drink for America


I have a four-year-old daughter who asks about everything. Here’s what she knows about America: The King of England used to be in charge.  Then, we told him No! and we fought with his soldiers, and it was a hard fight.  It was an incredible fight.  We hid in the forest, it was cold and it was terrible, but in the end, we fought, and we won.  We sent his soldiers back to England.

And then we, the people, were in charge.  As a result, we get to vote on who’s the President, and on who makes the laws.  A lot of young men died to get it done.  The brightest lights of a generation spent their lives to get it done.

An incredible dream, brought to life on our soil.  Let's fast-forward two hundred years.  If you believe what you read in today's opinion pieces and blogs, you'd think that American democracy is dead.  What do I tell my daughter?  That corporations, lobbyists, and the two-party system really run the country?  And that there's nothing we can do about it?

I don't believe it.  There are a lot of things we can do to make the dream of American democracy not just a beautiful ideal but a fact on the ground.



Here’s one: Drink for America.


Let me put it this way: Who do you talk to about America, politics, the country?

Where I’m from, it ain’t polite to talk about religion, sex, or politics.  For me, it never seems to be the right time to bring it up.  Whatever you think of Occupy Wall Street, I do love how they got people together to provoke discussion, debate, and reflection about what’s wrong with America, and how to fix it.

However, due to its image, OWS is primarily gathering people of a leftward political persuasion, which is too bad.  There are plenty of rightists and libertarians and others who would like to see American democracy restored, both in perception and in reality.  Only when we engage across traditionally dividing lines do we have a chance of forming a more perfect Union.



When will we ever find time to talk about America?

You do go out for a drink with friends from time to time, don't you?  So how about coming out for a drink to talk about America?  Bring your friends if they’re interested.  And if they’re not, ditch ‘em for a night.  Or maybe, you need better friends.

It can be simple.  Meetup is good for organizing this sort of thing.  It could be every Monday night at a quiet neighborhood bar.  Maybe everyone wears a nametag with their name and a proposal.  Mine would say “David / No More Ag Subsidies”.  You may think that's a crap idea; I’d like to hear why.  And I’d love to hear your ideas.

OK, you say, so we’ll have a drink and discuss our ideas.  How does that change anything?

It changes you.

You walk in with one set of ideas and walk out with some different ones.  You might change your mind about something you think is important.  You might find out that some of your favorite ideas actually suck.  Or that everyone agrees with you and your idea is awesome.  You might discover a candidate that really deserves your support.

Remember, it doesn’t actually take that many thoughtful, committed citizens to make a difference.  Test your ideas in the crucible of discussion with friends, associates, enemies and people you just met!  Get some conviction.  You'll find it doesn't take long to write an email or two, make a phone call, or get busy online.  Multiply your activity by tens of thousands of us who feel the same way, and you've become part of a powerful force.  Think about how the American revolution got started in the first place...



So, is Drink for America already happening somewhere?  Taking a look at my local politically-oriented Meetups, every single one is in support of a particular candidate or party.  There's nothing wrong with that, but I'm proposing a different kind of meet-up, a gathering for people to exchange views rather than to strategize about how to advance the views they already share.

It might be fairly described as taking a page from the Occupy Wall Street playbook; that is, we ought to be talking before we’ve decided which candidate, party or proposal to support.



Would you like to help organize this?  I think it'd take two or three co-organizers to make this happen in NYC.  Drop me a line!  Join the group!  How are we going to find the people who are interested in this?  Do they make a bat-signal in the shape of the American flag?


ps. interestingly, not everyone shares my perspective on the American revolution.
pps. thanks to Dave, Peter, Thom and Michele for feedback on drafts of this post!

20111202

Pro Tools for Digital Life

Whether it's programming, cooking or carpentry, having the right tools makes a huge difference.

Same goes for communication.

Here's my toolbox. I use these all the time.

  • gmail. best web email ever.
  • the Getting Things Done system. A great methodology for staying on top of what you can, and ditching the rest. Thanks Jon!
  • google calendar.  i can see my wife's calendar when i need to.  one of our regular babysitters keeps her schedule on it and shares it with us.  we can see when she's free/busy, saving everybody time when scheduling.
  • bit.ly.  you give it a long URL and it shortens it.  a pro feature is that you can customize the shortened URL.  for example, the URL for my public Google calendar, which shows my free/busy time but not the details, is http://bit.ly/dsj_cal.  I give that out to anyone I'm scheduling a meeting with.
  • twitter. this is where i go when i want to "read the newspaper". Over the past 6 months I've found 400 people worth following. I think of it as "build your own newspaper". If someone is polluting my stream with stuff I'm not interested in, I just de-follow them. I make no attempt to "keep up" with all the tweets. This is just what I read when I have downtime to read interesting things.
  • news.me's daily email. they scrape my twitter feed to find very interesting things i ought to read. i look at this every day and there's usually one or two really good things in it.
  • buffer.  If you tweet regularly, you need buffer.  They space out your tweets so that you're not overwhelming people.  They also track stats on clicks and retweets.  Why is this useful?  Here's the problem.  Let's say you spend 20 minutes a day reading twitter and re-tweeting the things you find interesting.  So then you've made 5 tweets in the span of 20 minutes, which is probably annoying to some of your followers.  That's where buffer comes in.  Instead of tweeting directly, you Buffer them up using their nice Chrome plugin (if you are not using Chrome now, close this window immediately and install it), and Buffer tweets them out for you at scheduled times.  It might sound a bit OCD, but I think your followers will be happier not getting 5 tweets from you all at once.
  • followupthen.  Send emails to your future self.  In an hour, a day, a week, month, specific date, whatever.  This helps keep your inbox free of clutter that's there only to serve as a reminder.  Example: I email someone, asking them to do something for me.  But I know they're a little busy/forgetful.  So I also bcc 1week@followupthen.com, so that I'll get an email about it in a week.  In a week, when I get the email, if they haven't done anything yet, I can bug them again or otherwise deal with it.  In the interim, my inbox is blissfully clean, which is good since then I'm not devoting valuable brainspace or inbox space to the matter.  This harmonizes very well with the Getting Things Done methodology.
  • ohours.  If you're in a line of business where people "meet for coffee" all the time, you might find it more efficient to schedule a 20-minute videoconf chat instead.  ohours handles the logistics of scheduling and connecting.  If you want to chat with me, here's my ohours.
  • skillshare.  If you have a skill, you should be teaching it.  Today, I'm teaching Fun With Data 101.  If you don't have a skill... come on!  You have a skill!
  • about.me.  A nice place to send people who want to learn more about you.  I need a better picture there.  Someday when Tom and I are on the same coast, he'll take one.
Do you have tools you like?  Add 'em in the comments!

One final note about twitter, buffer and news.me.  I think buffer and news.me are, together, improving serious problems with twitter, from the outside.  Interestingly, they both attack temporal problems with twitter, buffer on the way in and news.me on the way out.  With buffer, I can compose my tweets when I want, and they'll send them out later, on an optimal schedule for my followers.  With news.me, I can read whenever I want, and they've taken the trouble of figuring out which tweets in my stream are most likely to interest me.

What do you think?