Skip to content

Instantly share code, notes, and snippets.

@jimr
Last active December 15, 2015 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimr/5302878 to your computer and use it in GitHub Desktop.
Save jimr/5302878 to your computer and use it in GitHub Desktop.
Python script for finding the first difference between two lines. Useful for (e.g.) diffing minified JS. Usage: git diff -p some/minified/file.js | grep "^[+-]" | tail -n 2 | python diff.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import fileinput
lines = list(fileinput.input())
if len(lines) != 2:
raise Exception("Input must be a pair of lines to diff")
for i, (char1, char2) in enumerate(zip(*lines)):
if char1 != char2:
print i, char1, char2
if i > 0:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment