Saturday, June 05, 2010

A left merge versus a right merge

Recently, I found out that you can set the default winner in a merge for a hash. I wasn’t going to write about it since I figured it was pretty basic. But then again, I hadn’t written in a while. Been busy. So something easy to get me back on the wagon.

I’ll call it a left merge and a right merge. Let’s say we have some options, like default options and new options in a method, and we want merge them together, where options override default options, but you store it into options.

1 # some options 2 default_opts = { :a => 1, :b => 2 } 3 opts = { :b => 3, :c => 4 }

Well, the normal way of merging things won’t work:

1 # the normal default merge 2 opts.merge!(default_opt) # => { :a => 1, :b => 2, :c => 4 }

Well, that’s not right. We want the default options to be overridden by the new options and store it in the opts variable. We could do it like this:

1 # one way of doing things 2 opts = default_opts.merge(opts) # => { :a => 1, :b => 3, :c => 4 }

But then here’s another

1 # the other merge 2 opts.merge!(default_opts) { |k,o| o } # => { :a => 1, :b => 3, :c => 4 }

Yay!

Posted via web from The Web and all that Jazz

Tuesday, June 01, 2010

BrowserCouch is CouchDb for browsers

BrowserCouch Documentation

BrowserCouch is an attempt at an in-browser MapReduce implementation. It's written entirely in JavaScript and intended to work on all browsers, gracefully upgrading when support for better efficiency or feature set is detected.

Not coincidentally, this library is intended to mimic the functionality of CouchDB on the client-side, and may even support integration with CouchDB in the future.

Why?

This prototype is intended as a response to Vladimir Vukićević's blog post entitled HTML5 Web Storage and SQL. A CouchDB-like API seems like a nice solution to persistent storage on the Web because so many of its semantics are delegated out to the JavaScript language, which makes it potentially easy to standardize. Furthermore, the MapReduce paradigm also naturally takes advantage of multiple processor cores—something that is increasingly common in today's computing devices.

Things to do

To learn how to use BrowserCouch, check out the work-in-progress tutorial.

Aside from that, you can run the test suite and the semi-large data set test, though they're not particularly exciting. In the future, we'd like to make CouchDB's Futon client work entirely using BrowserCouch as its backend instead of a CouchDB server, but that's a ways away.

If you'd like to see more code samples of what the BrowserCouch API currently looks like, check out the annotated source code for the test suite. You can also read the primary source code documentation for more on BrowserCouch's implementation.

This is really awesome. I thought about doing this, but figured it was a massive undertaking. I'm glad someone's doing it. CouchDb's replication features (while not implemented yet in BrowserCouch), is something to really look forward to, especially if it's available for mobile browsers.

Posted via web from The Web and all that Jazz

Friday, May 21, 2010

I am one of the creators of the first "synthetic" bacterial cell. AMA : IAmA

More specifically, I am one of the authors of this paper. I was primarily involved in the assembly of the synthetic genome. I will answer your questions to the best of my ability, and to the extent of which I am allowed to discuss these things.

Posted via web from Dumping Grounds of the Web

Monday, May 10, 2010

Whenever I hear "I'm not good at math", it's like people telling "I can't read, and it's ok"

Granted, thinking statistically is tricky. We like to construct simple cause-and-effect stories to explain the world as we experience it. “You need to train in this way of thinking. It’s not easy,” says John Allen Paulos, a Temple University mathematician.

That’s precisely the point. We often say, rightly, that literacy is crucial to public life: If you can’t write, you can’t think. The same is now true in math. Statistics is the new grammar.

Whenever I hear "I'm not good at math", it's like people telling me "I can't read, and it's ok."

Posted via web from Dumping Grounds of the Web

Thursday, May 06, 2010

Friday, April 30, 2010

Henry Ford's "Thoughts on Horses"

The idea of gas engines was by no means new, but this was the first time that a really serious effort had been made to put them on the market. They were received with interest rather than enthusiasm and I do not recall any one who thought that the internal combustion engine could ever have more than a limited use. All the wise people demonstrated conclusively that the engine could not compete with steam. They never thought that it might carve out a career for itself. That is the way with wise people--they are so wise and practical that they always know to a dot just why something cannot be done; they always know the limitation...

Recently, a friend was telling me that DSLR cameras will never be supplanted by cameraphones. As of 2010, it seems a silly proposition. But that's seeing camera technology as they are now, not what they will be.

I don't think DSLRs will ever go away, like the radio never went away. But I don't think it's infeasible that cameraphones will get better and better so that for many DSLR users now, it would get 'good enough'.

I sent him the post I wrote on this subject. But I don't think he read it.

Posted via web from The Web and all that Jazz

Thursday, April 29, 2010

Back to HATEOS and APIs

REST-like discoverability could also be a boon for some services. What if Twitter provided something like this along with a tweet’s JSON?

{  "actions": {  "Retweet" : { "method":"POST", url:"/1/statuses/retweet/12345.json" },  "Delete" : { "method":"DELETE", url:"/1/statuses/destroy/12345.json" },  "Report Spam" : { "method":"POST", url:"/1/statuses/retweet/12345.json", params:{"id":12345} }  }  }

YES. I had talked about this in the HATEOS post that I wrote a while back. Right now, only html is self-discovering. XML and JSON docs should also have self-documented descriptions of next actions a client can take. That way, you'd cut down on the amount of documentation requires to understand or use an API.

One good point brought up in the comments in that last point was that if I had internal links, a client is likely to know what to do with what it gets back. But if I linked outside of my service, say geonames.org, how would I understand the schema? There's no standardized set of tags for geolocation data, like there is hypertext data.

Until we get standard media types for specific kinds of web applications, I'm afraid we're stuck.

Posted via web from The Web and all that Jazz

Tuesday, April 27, 2010

How to kill an unresponsive ssh session

approach has been to switch to another terminal window or shell and then killing the process in question. Today I happened to be skimming through the ssh client’s man page and I found a section about escape characters. Suddenly I gazed upon the glory of the disconnect key sequence: a newline followed by ~.. It works like a charm. As always, I thought I should

That's something I've been looking for a while now. I don't know if this is just bad user interface, or if it's awesome that it has a surprise feature.

Posted via web from The Web and all that Jazz

Friday, April 23, 2010

Whiteboarding

Our new whiteyboard solving factorial problem

Posted via web from Dumping Grounds of the Web

Monday, April 12, 2010

Facebook | A Dismal Guide to Concurrency

Two people can paint a house faster than one can. Honeybees work independently but pass messages to each other about conditions in the field. Many forms of concurrency [0], so obvious and natural in the real world, are actually pretty alien to the way we write programs today. It's much easier to write a program assuming that there is one processor, one memory space, sequential execution and a God's-eye view of the internal state. Language is a tool of thought as much as a means of expression, and the mindset embedded in the languages we use can get in the way. [1]

There's a really interesting idea in this post. It's that in the CAPs theorem, consistency usually get the boot, and we find that it's not the end of the world. Updated state needs to propagate through the system, and hence, you get a speed-of-light effect like in the real world: light(information) has a finite speed, and you need light-cone diagrams to show you what you're talking about.

Posted via web from The Web and all that Jazz

Speed up Rails tests when using Compass

So here's a little tidbit.  When you're using Compass with Rails, check to see if it slowed down your tests.  I used test_benchmark, and saw that it increased my test times 3 fold.  I narrowed it down to the initializer/compass.rb files that gets loaded.  Tests should need to use Compass at all to make it work, and just wrap its contents, like so:

if RAILS_ENV != "test"
  require 'compass'
  # If you have any compass plugins, require them here.
  Compass.configuration.parse(File.join(RAILS_ROOT, "config", "compass.config"))
  Compass.configuration.environment = RAILS_ENV.to_sym
  Compass.configure_sass_plugin!
end

And that'll do it.  

I got too lazy to put this in a gist.  It'd be really nice if posterous let you edit gists in-place in their editor.

Posted via web from The Web and all that Jazz

Friday, April 02, 2010

More Ubuntu-ing, less ranting about the iPad

The technorati over at HN are talking about Cory Doctrow's rant on the iPad.  

Much of the sentiment that I hear opposing it seem to be in the vein of:

The point is, Cory Doctorow is in a small, small minority. The minority isn't small because people don't know what he's saying -- it's small because they don't care. He's protesting the very philosophy that gives Apple products the quality that people who buy Apple products desire. And honestly, making the openness of Apple products your raison d'etre is a bit like getting furious about the mechanical details of your favorite brand of dishwasher. The answer is always the same: don't like it? Don't buy it.
 - Comment on HN

I think what Cory Doctrow is saying matters, but I don't think it's sufficient.

It might not matter much to most people in the world, at least not directly, if you assume most people are just consumers, not makers.  But it should matter to us as makers, and matter to those of us that want to cultivate and provide a place for future creatives.  Without a sandbox to tinker, you have less tinkerers.  

And in addition, we've seen that when you lower the bar, and invite "most people" to tinker, they will.  They'll be rough around the edges, but they will, and some of the stuff they produce are some good shit.  How many writers and video producers would you never heard of if not for blogging and youtube?

What's dangerous is not the iPad itself, but the perpetuating notion that people are just consumers.  The world can only suffer from less makers and tinkerers.  

I do agree that iPad is a fine machine.  And that Apple has presented their wares, and we have brought into their conditions.  To me, that means instead of railing against closed platforms like the iPad, open platforms really need to step up their game.  Open platforms need to take user experience and design into account, like what Ubuntu has done for linux.  

Open source/hardware are very good at building well known and well understood platforms, not new and innovative platforms.  

The best that open tablets can do is be very good and fast followers.  It's not sufficient just to rant.

Posted via web from The Web and all that Jazz

Tuesday, March 23, 2010

The emergence of dudebro

What is it about some internet communities that band together to do something? Is it perhaps for the lulz? In this case, it reminds me of some group projects I had to work with these other guys in junior high. If we had some project to do, it would turn into a large production. It was often imagination running wild, mostly for the laughs of the idea, since we couldn't actually do them.

But here, I guess is not only imagination rampant, but people can do something about it. So as a form of oneupsmanship, they start putting up screenshots, mockups, which stirs the imagination of others to join in on the oneupsmanship.

And perhaps it's because it's so ridiculous that people realize it could never be done elsewhere, so it might as well be done here. Because no one's going to be losing their job over Dudebro. And like snakes on a plane, it just seems like something that should exist.

If someone has a clue, enlighten me. Because as far as I can tell, the most HN's been able to produce has been co-founder dating sites.

Posted via web from The Web and all that Jazz

Saturday, March 20, 2010

Game mechanics roundup

Last week, I went to some meetup, and I met someone that was looking to make a game out of doing things in real life.  It's not really a new concept, but I don't think people really understood it until recently with foursquare and gowalla.  

Mobtropolis was suppose to be something that improved your life experiences as you got better at the game.  But My execution sucked, and I didn't know where to find users.  But like someone said to me, just because you wandered around in the desert doesn't mean you found the treasure.  Lots of other people wandered there, you just don't know about it--I mean, how many people knew about Mobtropolis?  

Anyway, it was good to hear about people interested in gaming mechanics in applications.  I don't think there are hardly any games that were hard to figure out how to use it.  It may be that games copy each other a lot, or because it's because I was persistent as a teen gamer.

If you're interested in game mechanics in applications, here's a round up.  We can start with Amy Jo Kim with "Putting the fun in functional"
here are her slides:

However, just because you put points on something isn't quite enough to motivate people to do things in real life.  I think it'd do you well to play more games to figure out what's fun.  Here's another oldie, but goodie about the theory of fun.  
http://www.theoryoffun.com/theoryoffun.pdf

You can also use games as a way of motivating people to do grunt work.  Here's the ESP game:

And the talk about it by the professor that invented it.  He basically concocted a game for people to play that generates test data for machine learning algorithms to learn image recognition.  

There's also a protein folding game for people to compete on how to compactly fold proteins.  Some people do a lot better and faster than computers doing a search.

And most recently, there's this talk of Jesse Schells talk on future of games and casual gaming in every day life:

And a TED talk about how gaming in real life can safe the world.  See a pattern yet?

I play casual games on:

They post one every day of the working week, so you can just try them out and see what makes you play for a long time.  They're all casual games that you can pick up easily.  

Long live games.

Posted via email from The Web and all that Jazz

Monday, March 15, 2010

Chat roulette as a platform for new video content formats

I thought this was pretty interesting use of chatroulette.

When we first got TV cameras, we just video broadcasted radio shows--which became late night talk shows. Eventually, we figured out that you can shoot shows with different formats, from sitcoms to reality TV.

It seems like we're exploring different formats of internet video, chatroulette being one of them. Sure, you can chat with people, with chatroulette, but if you can come up with something interesting that interacts with the person on the other end, you essentially have a never-ending stream of people as an audience on chat roulette.

In addition, when you record your performances to one person over the chat, you can broadcast it on justin.tv or youtube. Plenty of enjoyment to be had from watching these records, as shown by the video above, as well as the original people in the video getting their 15 mins of fame.

Whoever figures this formate out first is going to have a lot of fast followers and land grab. This is the story that journalists are looking for on chat roulette, not that chatroulette is like playing russian roulette with cocks in five of the chambers.

One of the YC companies in our batch did something like chat roulette, but as video speed dating facebook app. I thought it was pretty brilliant, but somehow they never pursued it. I have no idea why.

Posted via web from The Web and all that Jazz

Wednesday, March 03, 2010

How to alter columns in postgresql

So here's a goodie for those of you using postgresql.

Let's say you have a migration to do where you need to change a column from an integer to a boolean. So if you're doing a rails migration, you might write something like

And then postgresql throws up (well, it does on Rails 2.3.5):

== ChangeDatatableAttributes: migrating ======================================
-- change_column(:datatables, :is_numeric, :boolean)
rake aborted!
An error has occurred, this and all later migrations canceled:

PGError: ERROR: column "is_numeric" cannot be cast to type boolean
: ALTER TABLE "datatables" ALTER COLUMN "is_numeric" TYPE boolean

Well, that's no good. The web was not exactly much help here, but I managed to find this in the postgresql docs:

the USING expression is not applied to the column's default value (if any); the result might not be a constant expression as required for a default. This means that when there is no implicit or assignment cast from old to new type, ALTER TYPE might fail to convert the default even though a USING clause is supplied.

Looks like you need to drop the default also, and then set it afterwards.

Or if you'd like, create a method that you can throw into a module to mixin.

And use it like so:

Or if all else fails, you can just follow Heroku's advice and just drop the column and create another. Tip!

Posted via web from The Web and all that Jazz

Sunday, February 28, 2010

Yeah, I use Google Wave to 'sign off' on informal agreements

Yeah, I use Google Wave.  I honestly don't know what everyone else is talking about when they say they don't know what it's for.

Ian and I don't talk on the phone about Graphbug maybe as much as we should.  There's a number of reasons for this, but as a result, we mostly communicate over Google Wave, which also serves as documentation for us.  

It's better than email for communications that's consistently about something specific.  We know what the other's doing code-wise, through pivotal and commit logs, and things outside of code, we update in a google wave.  Or if we have a spec that we need to hammer out, it's better to do it through wave.  It's more like a real-time wiki in this sense.

But we also use it to "Signing off" on informal agreements.  We'll type up a set of bullet points and keep editing and arguing about it in the discussions below the main wave.  The threaded nature of a wave keeps arguments and counter-arguments on target.  And then when we're both in agreement, we sign the bottom of the top wave (with all the bullet points) and the date.  

Because you can replay a wave, and that history doesn't change, we can be sure that neither one of us changed the bullet points after we've 'signed off' on the agreement.  

Of course, there's nothing verifying the authenticity of the signature (meaning we can't verify who signed it), only that it's signed at the right time.  There's probably a way, but for just us, just putting our names and date down is enough.  Given that there's only two of us we know who signed what name.

Tip!

Posted via email from The Web and all that Jazz

Thursday, February 25, 2010

It sucks to visualize public data

A while back, I made a graph overlaying the senate party majority with the national debt. While correlation isn't sufficient for causation, I did learn a lot about the shape of the national debt as well as assertions between political party and national debt is not as clear cut as political commenters and pundits would like you to believe.

However, the entire experience of producing the graphs in those blog post left me dumbfounded with how tedious it was just to see the shape of the data.

First, finding the data was difficult. Many of the census bureau and government websites have confusingly bad user interfaces. It took me a while to figure out how to find the number of single females by year and state. Go ahead, try it.

Once you've found the data, you need shape it into what you need for the visualization, which is difficult because data on the web is in a sad state of affairs. Images, video, and text on the web are limited to a few popular formats. Not only that, the actual format is abstracted out with an image tag--and soon to be video tag--by the browser or flash. No widespread consensus exists for raw data, with the exception of a limited number of domains dictated by microformats, KML, and its ilk. Many publish data through html tables or CSV files, which comes in surprising variety of hard-parsable formats.

Then, it was tedious simply finding a free visualization tool that produce moderately good looking graphs. There are a plethora of javascript graphing libraries, not to mention flash libraries like amcharts and flare, each with their own strengths, weaknesses, aesthetics, and ramp-up time. It took a while to pick the one that was suitable.

The whole thing was harder than it should have been, and if I couldn't convey to you how mad I am, just insert expletives above, whenever possible.

As a programmer, I can figure out how to find and graph the data, however painfully. But it's completely inaccessible to regular everyday person that uses the internet. There's a lot of pubic data out there, but people aren't able to access it easily. If it doesn't show up on google's search, that's where they stop.

It's not that people aren't interested that data, but it's because the data is completely inaccessible. If blog and news articles about unemployment, STD rates, and gas prices are any indication, people want to know this kind of information.

Even more so, people want to be able to explore different aspects of this data like the New York Times' interactive visualizations by cutting and slicing the data as they see fit, because often times a statistic only makes sense when you can answer the question, "compared to what and how?" And people want to be able to explore it visually in a way that gives insight.

This is why I'm working on Graphbug--making public data more easily accessible through visualizations. Some questions are best answered visually.

We want to make it easy to find data that you need, and make it as fluid as possible to move between different datasets to compare them, in the same way that google maps made it fluid to navigate a map. Then if you need to do more hardcore analysis, you can download it and play with it however you like.

Of course, the topic is too broad at the moment. We'd like to focus on particular datasets first, and though we picked the US Census to start, we'd like to hear from you what sorts of datasets you'd be interested in? iPhone market share? Number of earthquakes in each state by year? The male to female ratio at colleges over the years?

So visit graphbug.com, and let us know and give me feedback or comment on whether you felt the same pain or you have a need for this. And if so, what are you currently using to solve this problem?

Posted via email from The Web and all that Jazz

Saturday, February 20, 2010

What to listen for from technology scrooges

Consider today's online world. The Usenet, a worldwide bulletin board, allows anyone to post messages across the nation. Your word gets out, leapfrogging editors and publishers. Every voice can be heard cheaply and instantly. The result? Every voice is heard. The cacophany more closely resembles citizens band radio, complete with handles, harrasment, and anonymous threats. When most everyone shouts, few listen.

I saw this short opinion piece from 1995, and it's related to the technology myopia I wrote about recently, even amongst the technologically well-versed.

Once again, it's easy for us to say Mr. Stoll here is a fool. But that's not what we should glean from this. We now know that even if every voice can be heard cheaply, that data can be easily accessed in text form, and someone will come up with an algorithm to organize it all. Not only that, there's more than one algorithm. Some, like Pagerank is all in a computer. Others, like Digg, Reddit, and HN, are computer-human hybrids that require a bit of social engineering. So while Mr. Stoll correctly identified the problem, he let that stop him there. It was beyond his imagination if, much less how, that problem would be solved.

The same goes when any technology pundit talks about the current new crop of technologies. He might just not have the background to know whether it's possible at all, or he might just not have the imagination. You need both to see clearly.

That's not to say you should ignore everything these pundits say. Instead, listen carefully. The hard part of product development is making something people want. What pundits have done is the hard part of identifying the problem. It's up to you to figure out how to prove them wrong.

Posted via web from The Web and all that Jazz

Friday, February 19, 2010

I take it back. Haml's got some vinegar for a reason.

I take it back.

I gave HAML a second shot, and I rather like it. The conversion was pretty easy, and having emac's haml-mode saved a lot of indentation headaches--even moving blocks left and right in indentation.

How come I liked it better the second time around?  The first time I saw it, it was written by someone that ignored convention and just powered through nesting HAML div elements 10 to 12 levels deep in one file.  You know what?  You're doing it wrong.  

Writing HAML from scratch this time, and reading Haml Sucks for Content, I've found that HAML is designed with intentional weaknesses to make you stay clean and clear. Indentation too far in an HTML document? Chances are, there are repeating elements. Refactor it out to a partial, and you get to start at column zero again. Have the urge to make multi-line ruby statements? Refactor it out to a helper. You'll live longer that way.

By making some things intentionally hard to do--giving them some syntactic vinegar, you'd hope that your users end up Doing the Right Thing™.  But then again, some people just are immune to having code indent 10 to 12 levels deep, or name their variables 'ii' and 'jj' when they're not programming in Fortran.

Posted via web from The Web and all that Jazz