Skip to content

How Do You Look When Merging Fails ;-)

May 9, 2009

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!

About these ads
63 Comments
  1. May 11, 2009 9:54 pm

    Hallo Andi,

    ich glaube, du meinst diese Folge:

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

    Beste Grüße
    Florian

    • May 12, 2009 3:59 am

      Ah, es war Ralph dem das Herz bricht und nicht Lisa! Danke! :)

  2. Guy permalink
    May 14, 2009 4:15 am

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

  3. January 8, 2010 7:15 pm

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

  4. evan permalink
    January 8, 2010 7:21 pm

    love it. pure genius

  5. January 8, 2010 7:26 pm

    Haha, wow, that is such a neat idea!

  6. January 8, 2010 7:28 pm

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

  7. January 8, 2010 8:15 pm

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

    • January 10, 2010 9:05 pm

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

  8. January 8, 2010 8:23 pm

    This is the simpsons episode you’re thinking of

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

  9. Dave permalink
    January 8, 2010 9:01 pm

    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.

    • January 9, 2010 11:38 am

      so… you don’t like F# ;)

  10. January 8, 2010 9:19 pm

    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. January 8, 2010 10:25 pm

    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.

    • January 8, 2010 11:36 pm

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

      or for c++ a segfault :p

  12. creaothceann permalink
    January 8, 2010 11:10 pm

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

    • January 9, 2010 6:08 am

      ups, thanks :)

      • January 9, 2010 3:43 pm

        “ups” should be “oops” :-D

        • Jenna permalink
          January 9, 2010 9:20 pm

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

          • January 10, 2010 6:44 am

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

  13. January 8, 2010 11:30 pm

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

    • Rob permalink
      January 10, 2010 9:47 am

      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. January 9, 2010 12:55 am

    Love it. So. Hard.

    • Anonymous permalink
      January 9, 2010 1:20 am

      Tory, how errotic!

      • January 9, 2010 1:13 pm

        Only 1 ‘r’ in erotic!!

        • Łukasz permalink
          January 9, 2010 3:29 pm

          It’s more erotic if you have more ‘r’s ;-)

      • January 11, 2010 7:17 am

        wow, how sexist a comment

  15. January 9, 2010 1:49 am

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

    • January 9, 2010 11:26 pm

      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. nex permalink
    January 9, 2010 4:31 am

    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. Anonymous permalink
    January 9, 2010 5:46 am

    grammar fail

  18. artagnon permalink
    January 9, 2010 7:31 am

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

  19. January 9, 2010 11:40 am

    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. Tobias permalink
    January 9, 2010 2:36 pm

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

  21. January 9, 2010 3:56 pm

    Assome!!!!

  22. January 9, 2010 4:07 pm

    LOL, can you make a version for git?

  23. Erban permalink
    January 9, 2010 5:21 pm

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

    • Anonymous permalink
      January 9, 2010 8:26 pm

      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.

    • January 9, 2010 8:34 pm

      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. January 9, 2010 11:27 pm

    Many shades of awesome, sah! Kudos :-)

  25. January 10, 2010 3:36 am

    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. January 10, 2010 12:16 pm

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

  27. bagus permalink
    January 10, 2010 4:59 pm

    :-)

  28. January 11, 2010 10:21 am

    Awesome to the max! :)

  29. pafcu permalink
    January 11, 2010 11:09 pm

    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/

    • January 12, 2010 4:51 am

      Cool! I always wanted to add the face detection part to the snippet… :)

  30. gammy permalink
    January 20, 2010 10:04 pm

    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

  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

Comments are closed.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: