Thursday, July 28, 2011

Wheatley: Semi-Automated JavaScript Refactoring

Incomplete, and I hope to refactor it (ironically enough), but kind of awesome.

it "can do an ultra-simple refactor, namely creating a wrapper function" do
@code = <<-CODE
console.log("foo");
CODE
@refactored = <<-REFACTORED
function asdf(qwerty) {
console.log(qwerty);
}
asdf("foo");
REFACTORED
Wheatley.create_wrapper_function(@code).should == @refactored
end

Extensive documentation on GitHub.

Features

  • Wrap function definitions in wrapper functions
  • Identify similar JavaScript code blocks
  • Calculate similarity percentage between any two code blocks
  • Compare code blocks to see how many specific tokens they differ by
  • Extract the variant tokens by which similar code blocks differ
  • Extract a literal from a simple function
  • Create function calls
  • Create wrapper functions
  • Perform simplistic proof-of-concept refactoring

Named after the dumb AI from Portal 2.

Wednesday, July 27, 2011

Daily Bitcoin Exchange Rate Miniapp

You can't do this for Bitcoin yet:



Until tonight, your best bets were bitcoincharts.com and the painful cognitive overhead of its UI, or Mt Gox and the painful cognitive overhead of its UI.

Here's a temporary solution:



http://btcusd.gilesb.com/

https://github.com/gilesbowkett/btcusd

The site updates daily via cron. Pull requests are very welcome. I'm especially hoping to add some nice CSS and a command-line calculator interface like Google's.

At the risk of stating the obvious, btcusd.gilesb.com does not constitute financial advice. Absolutely no guarantees are made regarding the usefulness, accuracy, or freshness of the data. The miniapp functions purely as a convenience for busy people who are curious enough to keep an eye on Bitcoin but not serious enough to pour their entire life savings into it.

Monday, July 25, 2011

Automated Refactoring Is *A* Future

As opposed to the future. You may only see it today in research projects, but consider: there are plenty of COBOL projects still running today. Now imagine it's the year 2350. Who do you think maintains ultra-legacy code?

In a fortunate coincidence, Hacker News featured an academic automated refactoring project today, and I began repackaging a moderately successful automated refactoring research project of my own (which I had hoped to make into a business) for public consumption as open source.

It's just barely clean enough to release, but I'm going to take a little longer to make it something I can be more proud of. So, stay tuned.

Edit: Related:

data mining cucumber features
automated refactoring: this spec passes
current projects: twitter newspaper and automated refactoring

Friday, July 22, 2011

Career Exploration: Work For Free Rather Than Lowering Your Rate

Long-time readers of this blog know that I'm a very experienced programmer and a very inexperienced actor. I have three times taken on Rails projects in the entertainment industry at a discounted rate in order to get my foot in the water - maybe two and a half times, depending on your definitions. Two companies with very firm entertainment industry roots, and one which you might call half entertainment and half Silicon Valley.

Anyway, at the two companies with really strong roots, the discounted rate fell much, much lower than my normal rate. In both cases, I took on side projects - additional clients and my own business projects - to generate additional income, and had to, in order to pay my bills. In one case, the side projects paid more than four times as much as the entertainment industry project.

I got the idea to make this sacrifice from a period when I was researching career changes. I don't recall the specific books or articles, but the reasoning was that you leverage your existing skills to get a foot in the door. To some extent, that works. I learned a lot about the entertainment industry and met amazing people - but each project ended badly. The half entertainment/half tech company paid a rate nearer to my normal rate, and didn't end as badly as the pure entertainment industry projects, but it still didn't go as smoothly as it should have.

This was very disappointing.

I read a great thing online once, about why lawyers should do pro bono work rather than lowering their fee, in instances where they want to help people who can't afford them. ("Pro bono" means "for the good" in Latin and is an idiom lawyers use to indicate work done for free.) I'm going to say this reasoning applies to my entertainment industry experiments as well.

The reasoning goes like this: people will not compare your discounted rate to your real rate. Instead they'll compare it to the rate they hoped to pay. In some cases, they may even suspect you of making up a completely false "real rate" to use as a bargaining chip.

The experience of lowering your rate to get your foot in the door in some new industry carries with it all the disadvantages of being overqualified. If you're curious enough about a new industry to consider making this sacrifice, it is much, much wiser to instead tell people your normal rate, and if they say they can't afford it, offer a small amount of your time for free on a regular basis. A small team with a novice programmer will get more work done (and better work) if that novice programmer can run his or her thoughts and code by a more experienced programmer for feedback from time to time.

Tuesday, July 19, 2011

The $40 Table Of Contents

I badgered thoughtbot on Twitter the other day about their new book on Backbone.js. Full disclosure: I did the music for the PeepCode video on Backbone, which is obviously a competing product. But I'm really looking forward to this Backbone book and I can't wait to read it, so I was frustrated when I asked thoughtbot how much material they had so far, because they told me all they had was the table of contents.

This led to some snark about $40 being a lot for a table of contents.

What's ironic about this is that I have a table of contents which I could charge $1000 for in good conscience. In fact it's barely even a table of contents, it's almost just a list, but I wrote it down during a conversation I had with James Golick. James runs a web site which sees staggering traffic and handles it gracefully. We were talking about putting together a video series on scaling Rails applications.

Say you're an entrepreneur and you want to tell venture capitalists that you'll be able to scale a Rails app. You're about to go into a meeting which could net you millions in investment. You have every other piece of the puzzle, but you face concerns about scalability. That one little issue is all that stands between you and millions in cash. Under those circumstances, how much money is that list worth to you? The answer is literally millions of dollars, so $1000 for that little table of contents would be an incredible bargain.

What you're selling there is not the piece of paper or the PDF, and it's not even the information either format contains. You're really selling the opportunity to reap millions in investment (in this example).

The pricing of information products should reflect their value.

Go to Amazon or a physical bookstore and run a little test. Find some tech books written by industry stars who unquestionably know exactly what they're talking about. Then find some utterly useless tech books filled with horseshit and documentation copy/paste. Compare the prices of the books in each category.

Tech books are not priced by value.

Monday, July 18, 2011

Hacker Newspaper Bans Marco Arment

Brief note to those of you who use Hacker Newspaper: I'm finding the complaint/useful ratio in marco.org too low.

It could probably be easy to customize these filters on a per-user basis, by the way, and I may do so in future.

Sunday, July 17, 2011

Capo Is Absolutely Fantastic

Capo is an OS X music analysis app which musicians can use to very rapidly figure out melodies, chord progressions, and bass lines from mp3s. I went to the web site, watched a couple demo videos, downloaded the demo, and had extracted a melody all in a matter of minutes. The videos use guitar rock for the examples but I analyzed dubstep with it. The app assumes you're using a guitar, and while my background in (very basic) guitar made it easier to use, I don't own a guitar these days and that didn't slow me down at all.

I cannot recommend this app highly enough. Words do not exist suitable to capture and contain its magnificence.

Wednesday, July 13, 2011

Buscando El Viento: PostgreSQL Search Migrations Gem

buscando el viento is a search migrations gem for PostgreSQL and Rails 3. It enables full-text searching by automating the process of creating appropriate migrations, and is largely based on Xavier Shay's PeepCode video on Postgres.

I created this because I needed it. PostgreSQL is powerful but obtuse, in my opinion.

This gem makes some blithely cavalier assumptions about indexing and search vectors, so please use with caution. PostgreSQL boffins, please do contribute to this; it currently lacks much-needed setweight() support, and comes from a guy who's pretty new to Postgres.

gem install buscando_el_viento

Tuesday, July 12, 2011

Star Wars Lamborghini

People usually see awesome and pathetic as polar opposites, so it's always interesting to see things that hit a very high degree of both awesome and pathetic simultaneously. A bit like quantum physicists seeing a particle exist in multiple places at the same time.

Monday, July 11, 2011

Oooo Eeee Ooeeeooe Woooaaaaaooeeee



"interactive architectural mapping" on a former theater in Lyon, France last year. The sounds of the audience controlled the visuals projected onto the building's fa├žade.

ERROR: must be owner of language plpgsql

Update: I created a gem to make PostgreSQL a bit easier to use with Rails.

In my opinion, this error message constitutes definitive proof that PostgreSQL hates America, murders babies, supports terrorism, and worships Satan. I have paid leather-clad dominatrices in London thousands of British pounds to whip me and humiliate me, and not one of them ever came close to the anguish inflicted by this horseshit error message and the documentation which "supports" it.

(If you are a lawyer for PostgreSQL, please be advised that this is only my opinion. If you are a police officer on a vice squad, particularly in the United Kingdom, please be advised that I may be exaggerating. If you are a developer for PostgreSQL, please be advised that the Pope Himself has assured me you will burn in Hell for all eternity for writing this error message, and that Satan Himself has personally apologized to me that Hell Itself does not hold torments sufficient to punish you for what you've done.)



Fortunately, the solution is easy:

↪ psql template1
template1=# alter role my_user_name with superuser;


You may wonder what the hell template1 is. Fear not! It represents systemwide settings, so naming it after view-formatting variables could not have been more logical. Absolutely could not. No way on earth could any more logical name have been found, anywhere in all the lexicons of every human language.

To be fair, "template" can carry broader meanings, but even then, naming a template "template" is like naming a variable "variable." Anybody who does that to their users does not have their users' joy at the forefront of their list of priorities.

Anyway. Yes. A perfect fix. And by perfect I mean extremely imperfect. Switching your user to superuser means you don't have to spend three hours on it just to use your dev box, but if you deployed this way, you'd get hacked in seconds. In seriousness, PostgreSQL rocks, but it's not without its limitations. Based on the excellent PeepCode on Postgres, I hacked together (copy/pasted, really) a very, very simple implementation of full-text search.

  def self.search_description(query)
conditions = <<-EOS
to_tsvector('english', description) @@ plainto_tsquery('english', ?)
EOS
where(conditions, query)
end


The repetition of "english" frustrates me as a DRY-crazed Rails dev, but what's more worrisome here is how Postgres handles stemming. Stemming uses basic natural language processing to recognize (for example) that the terms "stem," "stemming," and "stemmed" are all related. It's very useful for "fuzzy" searching, but useless for exact matches, so sometimes you want to turn it off.

Here's what the code looks like with stemming on:

to_tsvector("english"...
to_tsvector("default"...


Of course, if you use "default," PostgreSQL uses an English dictionary, because English is the default for "default." And "english." If somebody who worked for me wrote an API like that, I wouldn't just fire them, I'd probably throw them out of a window and set them on fire. (Hopefully in the opposite order, but not necessarily.) But it gets even worse. Here's what it looks like with stemming off:

to_tsvector("simple"...

So the opposite of "simple" is "default." Here I have a fundamental philosophical disagreement with the Postgres devs, because I believe defaults should be simple, yet I have to applaud their honesty, because, to be fair, in the context of Postgres, it is indeed pretty logical to define "simple" as the opposite of "default." Points for consistency at least.

Spare Mac Mini: What To Do?

I bought a 2001 Mac Mini last year, partly because I wanted to install it in my car.



Now, however, I don't actually have a car. I don't want to use the Mini as a media center, because I have an Apple TV. I'm currently using it as a monitor stand. It seems a terrible waste. I'd love to make it a brain for a robot hexapod, but that requires more time than I really have.



If worse comes to worst, of course, I'll just donate it to a school or something and bask in the warm glow of good karma. Beyond that, the best idea I have at the moment is dedicated hardware for Archaeopteryx. I can probably set it up to launch with all the necessary software configured and running from boot, so that a monitor isn't necessary, but even then your choice of soundbank is limited without using a monitor, keyboard, and trackpad (or trackball). Other options include some kind of semi-autonomous art installation or home automation.

Get your tweet on if you have any notions.

Friday, July 8, 2011

iPad MIDI In: Trivially Easy



Literally just bought it, pulled it out of the box, and plugged it in.

Diamond: Live-Coding Ruby Arpeggiator



Lots more info

Thursday, July 7, 2011

Yet Another dotjs Hack: Fixing GitHub's Graph Links

There's something about GitHub's UI which I've always found counter-intuitive. They have this handy, awesome network graph.



However, if you look for it under "Graphs," you won't find it.



You have to remember, when you look at the UI, that "Graphs" actually means "every graph except the network graph." I never remember that, and honestly, I think GitHub made a mistake here.

With dotjs, it's easy to fix.



Here's the code:

Monday, July 4, 2011

Archaeopteryx Controlling Korg iMS-20 iPad App

Got it working this afternoon. Unfortunately I don't have time to document it properly, so I made a couple quick videos.