Josh Haas's Web Log

How to merge json files using git

leave a comment »

For my startup bubble, I do a lot of work using json. I have a number of very large, frequently-changing json files checked into git.

This causes a fair amount of pain, because git’s merge algorithm doesn’t know how to interpret or preserve the json tree structure, so it reports conflicts for things such as adding different keys to the same parent object, which textually can look like a conflict but semantically isn’t, at least for my purposes.

It got to the point where I’d be coordinating with my teammate to make sure we didn’t touch the same json files at the same time. Since the big win with git is being able to skip that kind of coordination, I got fed up and wrote a custom driver for merging json files.

It requires coffee-script to use (although porting it to javascript should be as simple as dumping it into coffeescript.org’s converter). Installation instructions are in comments at the top of the file.

The way it works is it recursively walks the structure of the file we’re merging into ours, and checks that each value matches the value of our file. If the value differs, it looks at the ancestor file (the version from before the two branches diverged) to see whether our version or their version was changed… if our version matches the ancestor file, then it goes with their version, and visa-versa.

If neither our version nor their version matches the ancestor, it reports that as a conflict. It reports a conflict by replacing the node with an object that looks like this:

{
   "CONFLICT": "<<<<<<<<>>>>>>>>",     //this is to make conflicts easy to find
   "OURS": ...our version of the node...
   "THEIRS": ...their version of the node...
   "ANCESTOR": ...the ancestor version....
   "PATH": a .-seperated list of keys, indicating where in the file we are
}

Resolving the conflict is as simple as copying our version or their version and pasting it over the conflict object.

The final, merged version of the file is then pretty-printed (it should be pretty easy to modify the code if pretty-printing isn’t what you want). And you’re all set!

Written by jphaas

June 27, 2014 at 2:44 am

Posted in Uncategorized

The revenge of the sheeple

leave a comment »

Sheeeple, Sheeeeeeeeeeeple, wake up!!!!!!!!!!!!!!!!

But seriously, is the protestor right? Are we all sheep?

Yes, and maybe no.

A sheep is a tamed creature. It follows behavior patterns that its shepherd designed for it. Those patterns serve the shepherd’s interests; they only serve the sheep’s interests insofar as those interests align with the shepherd’s. Once those interests diverge… it’s time for some lamb chop. Read the rest of this entry »

Written by jphaas

June 3, 2014 at 4:02 pm

Posted in Uncategorized

Responding to hate

leave a comment »

So a writer at Jezebel collected a day’s worth of transcripts from a PUAHate chat group, which is the community that helped develop / reinforce the worldview of the UCSB shooter.

I really dislike this piece of reporting. I think it’s valuable to shed light on dark corners of the internet like that, but when the writer says things like “From an observer’s perspective, PUAHate is a group of self-pitying babies who believe they’re entitled to women who are much more attractive than they are,” she is saying exactly what all of these guys would expect, in their distorted world view, that she would say.

The kind of hate on display by these guys comes from a place of deep lack of self-worth, which they then protect themselves from by inventing them-against-the-world stories. Read the rest of this entry »

Written by jphaas

May 30, 2014 at 3:06 pm

Posted in Uncategorized

What we’re trying to do with Bubble

with 2 comments

I wrote a new post on the Bubble blog explaining what we’re trying to accomplish:

Our goal is to erase the distinction between software use and software creation.

Good software, when used, is:

* Helpful. It empathizes with the users’ point of view, understands what they want, and lets them do it with as little effort as possible. My email provider, GMail, tries to figure out what mail I actually want to read. It marks things as spam for me, it guesses which mail is important, and it lets me hide emails I don’t want to see without making me delete them.

* Friendly. It communicates a desire to be the user’s ally. Have you ever used TurboTax Online? The users of that software are doing a stressful, hateful chore. TurboTax is their friend, holding their hand as they go through it. It goes out of its way to comfort and reassure. It’s not a perfect piece of software, but it’s pretty damn impressive.

* Empowering. Good software lets its users work miracles. Love it or hate it, what would the world look like without Microsoft Word? Fifty years ago, type-setting a document for printing was a professional trade. It took years to master the technologies behind setting margins, picking colors, preparing fonts of different sizes. Now, a five-year-old can do in ten minutes what used to take an expert hours or days.

That’s what using good software is like. Creating software, on the other hand…

Read the full post here!

Written by jphaas

May 29, 2014 at 5:14 pm

Posted in Uncategorized

Instability and the unknown

leave a comment »

What if you’re a good cancer cell?

Selfless, considerate, hard-working, supportive of your friends and neighbors. Good. But, your friends and neighbors are also cancer cells, and while you may be doing your part to make your community grow and prosper, your community is slowly killing the larger world that you’re a part of?

I just read this talk on how Silicon Valley is creating a dystopic internet. It’s a disturbing read. Some parts of it I viscerally agree with (the venture-capital ecosystem being toxic, and big tech companies having too much power) and other parts I viscerally disagree with (that data collection is a bad thing, and that governments should play a role in deciding which data companies can keep). My biggest take-away, though, is uncertainty. I don’t think I have the information nor the wisdom to know how all these forces will play out in the long term, and I don’t trust people who think that they do.

The scary thing is this is my industry. This is a subject-matter that I’ve spent thousands of hours thinking about and working on, and I still don’t know what “good” for the system is. I don’t think anyone really knows.

Read the rest of this entry »

Written by jphaas

May 27, 2014 at 2:23 am

Posted in Uncategorized

Debugging code, McKinsey-style

leave a comment »

The consulting firm McKinsey teaches all its analysts a concept called “Mutually Exclusive, Collectively Exhaustive” (MECE). It’s a way of breaking down a problem into a set of smaller problems that guarantees that the smaller problems contain the answer to the larger one.

Mutually exclusive means: each small problem doesn’t overlap with others; they can be analyzed independently.

Collectively exhaustive means: when you sum the small problems up, they equal the larger problem.

The classic example is business profit. Suppose John’s apple farm is no longer making as much money as it used to, and you want to know why. Read the rest of this entry »

Written by jphaas

May 24, 2014 at 5:03 pm

Posted in Uncategorized

Can I put “meta-ethics” in a post title and have anyone read it?

leave a comment »

I guess by writing this post, I’m making this question non-rhetorical.

Anyway yes this is about meta-ethics, sorry. If ethics is “why is stealing wrong?” meta-ethics is “What does it mean to say that stealing is wrong?” I.e., it’s like ethics, but meta: yeah?

So lately I’ve been bashing on utilitarianism and its daddy-philosophy, consequentialism. Smashing shoddy philosophy is fun, but it’s a lot easier to tear things down than to build them up. So I feel like it’s only fair to say what I believe in. Read the rest of this entry »

Written by jphaas

May 23, 2014 at 8:21 pm

Posted in Uncategorized

Consequentialism is logically indefensible

leave a comment »

I had previously written about my intuitive objections to utilitarianism as a moral framework, mainly that it’s premised on there always being a right answer, which is something that’s neither obviously true nor desirable.

I think those objections arise for me because at its core, consequentialism is a philosophically indefensible idea. Here’s my attempt at a charitable statement of a minimal consequentialist position:

1. Some possible states of the physical universe are better or worse than other possible states
2. Let’s say choice A leads to state of the universe A, and choice B leads to state of the universe B. If state of the universe A is better than state of the universe B, choice A is better than choice B.

Or less formally, the better-ness or worse-ness of a choice comes from the better-ness or worse-ness of the choice’s consequences. Read the rest of this entry »

Written by jphaas

May 22, 2014 at 4:56 pm

Posted in Uncategorized

Should all technology be open-source?

leave a comment »

In my last post, I wrote about frameworks for seeing the world that have lost their transformative power.

Here’s one that hasn’t.

I’m a fan of the open-source software movement. Open-sourcing software means releasing it under a license that lets others freely use, modify, and build on top of it. When the movement started, this was a deeply counterintuitive idea. Software was and is valuable; people’s livelihoods depend on selling it. Giving it away, for free, with no strings attached seemed as crazy as throwing a stack of hundred-dollar bills out the window of your car.

Since the movement started in the late 90s, open-source has moved from a fringe practice to the lifeblood of the entire software ecosystem. Pretty much every new software company builds on top of years and years worth of open-source code. Meanwhile, programming has become increasingly lucrative as a profession, and I would argue that that’s because of, not in spite of, open source: an hour spent by a programmer today is worth hundreds of times more than an hour spent by a programmer twenty years ago, because today that programmer is building on top of twenty years of open source code. Read the rest of this entry »

Written by jphaas

May 21, 2014 at 10:15 pm

Posted in Uncategorized

So You Say You Want a Revolution

with 3 comments

From Robespierre the Incorruptible, Robespierre the Daemonic:

But The Gleaming Vision and False Consciousness are two of the most crucial tools in the Revolutionary’s toolbox. I think that the tepid nature of much current Leftist writing (when it isn’t just disappearing entirely into theory) owes to the lack of a forceful (coercively so) positive future vision, and the complementary near-myopic focus on critique. …

Without a Gleaming Vision, and the accusations of False Consciousness to level at those who reject the Gleaming Vision, critique only serves the purpose of establishing internal purity tests, one-upping dialogic opponents, and getting tenure or magazine posts. Allusions to Gleaming Visions remain steadfastly vague, whether you are reading Slavoj Zizek, Naomi Klein, Silvia Federici, or Antonio Negri. While they are hectoring in their criticism of capitalism’s blatant faults, they are fuzzy on the details of its successor–and thus the need for revolution rather than reform is not clear. Thomas Piketty’s surprisingly modest solutions in Capital in the 21st Century–a global wealth tax, but that’s about it–drastically separate him from the radical crowd. In The Nation, Timothy Shenk half-heartedly carps about Piketty’s incrementalism while making only the fuzziest motions at “a much richer set of possibilities” and “a more promising alternative” for the future. He doesn’t bother to say what they might be. That won’t cut it.

Yeah.

This is the Occupy Wall Street circumstance: something is wrong, we don’t know how to fix it. Read the rest of this entry »

Written by jphaas

May 20, 2014 at 5:03 pm

Posted in Uncategorized