How Do You Look When Merging Fails ;-)

2009 May 9
by Andi Albrecht

There was a Simpsons episode, I can’t recall correctly, but I think Bart recorded Lisa when her heart broke and he watched it in slow motion to stop exactly at that point.

I thought of this episode yesterday while playing around with my laptop’s webcam and a Python shell. Finally I wrote a little fun script that does almost the same: Just register it as a hg hook and it takes a picture of you exactly at the unique moment when merging fails and it sends it directly and without any further questions to Twitpic and Twitter:

#!/usr/bin/env python

import os
import sys
import tempfile
import time

from CVtypes import cv
from twitpic import TwitPicAPI

DEVICE = 0
TWITTER_USER = 'xxx'  # CHANGE THIS!
TWITTER_PWD = 'xxx'   # CHANGE THIS!
# This is the time in seconds you need to realize that the merge has
# failed. When setting this consider that it already takes about a second
# for the camera to take the picture. "0" means no delay ;-)
EMOTIONAL_SLUGGISHNESS_RATE = 0.0

def grab_image(fname):
  camera = cv.CreateCameraCapture(DEVICE)
  frame = cv.QueryFrame(camera)
  cv.SaveImage(fname, frame)

def how_do_you_look():
  failed = bool(os.environ.get('HG_ERROR', 0))
  if not failed:
    return  # hmpf, maybe next time...
  fd, fname = tempfile.mkstemp('.jpg')
  if EMOTIONAL_SLUGGISHNESS_RATE > 0:
    time.sleep(EMOTIONAL_SLUGGISHNESS_RATE)
  grab_image(fname)
  twit = TwitPicAPI(TWITTER_USER, TWITTER_PWD)
  retcode = twit.upload(fname, post_to_twitter=True,
                        message='Another merge failed.')
  os.remove(fname)

if __name__ == '__main__':
  how_do_you_look()

You’ll need the CVtypes OpenCV wrapper and this Twitpic Python module. I’ve patched the twitpic module to support messages. Have a look at this issue if it’s already supported, otherwise a diff that adds the message keyword is attached to the issue. To use it as a Mercurial hook just add to .hg/hgrc:

[hooks]
update =  /path/to/the/above/script.py

and make the script executable.

The results are pretty good :)

Another merge failed. on Twitpic

Have fun!

BTW, the way how to access the camera is inspired by this nice blog post about face recognition using OpenCV.

Edit (2009-05-12): It was Ralph, not Lisa. Thanks Florian!

63 Responses leave one →
  1. 2009 May 11

    Hallo Andi,

    ich glaube, du meinst diese Folge:

    http://simpsons.wikia.com/wiki/I_Love_Lisa

    Beste Grüße
    Florian

  2. 2009 May 14
    Guy permalink

    Andi, schau’ Dir mal ctypes-opencv an. Da ist CVtypes schon deutlich weiterentwickelt. Sehr elegant: http://code.google.com/p/ctypes-opencv/

  3. 2010 January 8

    That’s excellent. You could do a gallery of code fails.

  4. 2010 January 8
    evan permalink

    love it. pure genius

  5. 2010 January 8

    Haha, wow, that is such a neat idea!

  6. 2010 January 8

    You should add a hashtag to the Tweet for an easy search of photos. :)

  7. 2010 January 8

    I think it was when Ralph’s heart broke, not Lisa’s

    • 2010 January 10

      yeah it was Ralph. Lisa broke his heart. It was really funny. Frame by frame slow motion.

  8. 2010 January 8

    This is the simpsons episode you’re thinking of

    http://en.wikipedia.org/wiki/I_Love_Lisa

  9. 2010 January 8
    Dave permalink

    This is unbelievably hilarious and should become standard practice for all software development. I would probably end up mid-way through a loud F#$* in the majority of cases.

  10. 2010 January 8

    Haha this is so great! I think of all the angry calls from work when people have to do a gigantic and tiresome merge.

  11. 2010 January 8

    I love this! Very cool idea. Very cool execution.

    Other admittedly-less-inspired possibilities:

    At point in a web app when users see results of analysis – - (impressed? confused?), at point in a web app when users submit customer feedback – - – (happy? furiously angry at a bug or horrible UI? pleading/grovelling for a new feature request?) etc.

    • 2010 January 8

      i was thinking maybe one that hooks all Python exceptions :)

      or for c++ a segfault :p

  12. 2010 January 8
    creaothceann permalink

    “when her heart breaked” should be
    “when her heart broke”

    • 2010 January 9

      ups, thanks :)

      • 2010 January 9

        “ups” should be “oops” :-D

        • 2010 January 9
          Jenna permalink

          Oops is “oops” only in native English countries. It’s “ups” in Germany, and a valid spelling.

          • 2010 January 10

            Oh! Now I understand the name of the delivery company! Does dhl mean something like “sorry about that” in german too? =)

  13. 2010 January 8

    You should include a hash tag in the auto tweets. #mergefail or something. That way we can see a feed of these pics.

    • 2010 January 10
      Rob permalink

      Write a patch!

      Just be sure to modify one of the other lines so we can all have a good laugh when Andi tries to merge it.

  14. 2010 January 9

    Love it. So. Hard.

  15. 2010 January 9

    What the heck is merging? Like, in a car?

    • 2010 January 9

      Sean, you lucky sod, if you don’t know what it is, I guess you’ve never had to suffer it ;-) Unless I’ve got the wrong end of the stick, it’s when you’re working on shared code concurrently with other people (i.e. editing the same files) and have to submit your results to the repository without screwing up your/anyone else/the repo’s version. It can be an utterly soul-destroying and miserable experience, if you have a lot of changes to merge.

  16. 2010 January 9
    nex permalink

    Like, merging two similar files together into one, so all the new changes that were made to these files are consolidated.

    > I think Bart recorded Lisa when her heart breaked
    Broke! When her/his heart broke.

    Oh, and the variable ‘failed’ … shouldn’t it be ’success’ instead? Because it’s False in the case of failure, right?

    Anyway, very creative idea! Surely has the potential to produce hilarious pictures.

  17. 2010 January 9
    Anonymous permalink

    grammar fail

  18. 2010 January 9
    artagnon permalink

    Awesome! Made me laugh :)
    I’ll probably write myself a Git hook when I get a webcam :p

  19. 2010 January 9

    Idea of the week, epic :)

    We could generate a Gallery of Fail. “This is how I look after screwing it up again.” Many sad faces, some angry, and one guy smashing his screen.

    Imagine the possibilities…

  20. 2010 January 9
    Tobias permalink

    Nice idea. You should really have added a hashtag to the default code. #mergefail would make it to my saved searches ;o)

  21. 2010 January 9

    Assome!!!!

  22. 2010 January 9

    LOL, can you make a version for git?

  23. 2010 January 9
    Erban permalink

    I’m sorry but I don’t understand what “merging” reffers to, can anyone explain?

    • 2010 January 9
      Anonymous permalink

      Merging is when one guy makes a change to a file and you make a change to the same file. You have to manually merge your changes if he checked his file in first (saved it, basically) and you modified the file in the same location he did. So you need to combine your changes w/ his changes in the same spot.

    • 2010 January 9

      Erban, Sean: Merging, in this case, refers to the act of taking two separate code development histories that share a common start and unifying them to create a common end.

      With modern development tools, some merging can be done automatically. This script would kick in whenever the automatic merge failed and the user has to take control of the situation.

  24. 2010 January 9

    Many shades of awesome, sah! Kudos :-)

  25. 2010 January 10

    I tried to search for “another merge failed” on twitter, only found this one but I LOL’ed hard : http://twitter.com/tombrow/statuses/7546658329

  26. 2010 January 10

    Genius idea. I laughed long and hard :) I want to see the gallery!

  27. 2010 January 10
    bagus permalink

    :-)

  28. 2010 January 11

    Awesome to the max! :)

  29. 2010 January 11
    pafcu permalink

    Inspired by your post I took a shot at a more general solution. I made a shell script that runs a program and then checks the exit code. It the program it called fails it runs a little program I made that takes a shot of your face using face detection. The code can be found at http://vervelend.wordpress.com/2010/01/11/failface-so-you-can-relive-that-magic-moment-again-and-again/

  30. 2010 January 20
    gammy permalink

    Interesting – it’d be neat if someone (hint hint) bothered to expand this for most types of version control frameworks. Of course it’d become less beautiful considering the hacks required for it to “hook” into other systems, but still…

Trackbacks & Pingbacks

  1. How do you look when margin fails? - Technology
  2. No Huddle Offense » Blog Archive » How do you look when mergin fails?
  3. Life, The Universe & Chips » Bookmarks for January 8th from 13:13 to 21:36
  4. === popurls.com === popular today
  5. How Do You Look When Merging Fails « LostFocus
  6. How Do You Look When Merging Fails ;-) « Andi Albrecht : Popular Links : eConsultant
  7. links for 2010-01-10 « Breyten’s Dev Blog
  8. Recording your emotions during development « Wat Vervelend!
  9. Failface – So you can relive that magic moment again and again « Wat Vervelend!
  10. Messylaneous for 2010/01/15 · DragonFly BSD Digest
  11. Messylaneous for 2010/01/15 « The Daily BSD

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS