Skip to content

Instantly share code, notes, and snippets.

@franklincm
Last active August 29, 2015 14:17
Show Gist options
  • Save franklincm/5c46dce73f886e46671a to your computer and use it in GitHub Desktop.
Save franklincm/5c46dce73f886e46671a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
import sys
data = ''
if len(sys.argv) == 2:
data = sys.argv[1]
else:
print "No input specified\n"
sys.exit(0)
data = open(data).read()
chars = ['{','}']
for ch in chars:
if ch in data:
data = data.replace(ch,'')
def print_color(text, color):
colors = {"red" : '\033[1;31m%s\033[1;m',
"green" : '\033[1;32m%s\033[1;m',
"yellow" : '\033[1;33m%s\033[1;m',
"blue" : '\033[1;34m%s\033[1;m',
"magenta" : '\033[1;35m%s\033[1;m',
"cyan" : '\033[1;36m%s\033[1;m',
"white" : '\033[1;37m%s\033[1;m',
"crimson" : '\033[1;38m%s\033[1;m'
}
return colors[color] % text
def find_differences(input_data):
differences = []
lines = input_data.split('\n')
lines_array = [list(line.split()) for line in lines]
for line_index,line in enumerate(lines_array):
if line_index == 0:
continue
for token_index,token in enumerate(lines_array[line_index]):
if lines_array[line_index - 1][token_index] != token:
tmp = (line_index, token_index)
differences.append(tmp)
return differences
def print_output(input_data, differences_list, color1, color2):
lines = input_data.split('\n')
lines_array = [list(line.split()) for line in lines]
for line_index,line in enumerate(lines_array):
for token_index,token in enumerate(lines_array[line_index]):
if (line_index, token_index) in differences:
sys.stdout.write(print_color(token, color2) + ' ')
else:
sys.stdout.write(print_color(token, color1) + ' ')
sys.stdout.write('\n')
return
differences = find_differences(data)
print_output(data, differences, 'blue', 'yellow')
{0000 0000 0000 0000 0000 0000 0000 0000}
{0000 0000 0000 0000 0000 0000 0000 0f00}
{0000 0000 0000 0000 0000 0000 c0de 0f00}
{0000 0000 0000 0000 0000 ac1d c0de 0f00}
{0000 0000 0000 0000 face ac1d c0de 0f00}
{0000 0000 0000 d06e face ac1d c0de 0f00}
{0000 0000 0000 d06e face ac1d d06e 0f00}
{0000 0000 0000 d06e face face d06e 0f00}
{0000 0000 0000 d06e ac1d face d06e 0f00}
{0000 0000 0000 c0de ac1d face d06e 0f00}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment