Skip to content

Instantly share code, notes, and snippets.

@gunthercox
Created September 29, 2014 14:11
Show Gist options
  • Save gunthercox/efd5656f27637652c32e to your computer and use it in GitHub Desktop.
Save gunthercox/efd5656f27637652c32e to your computer and use it in GitHub Desktop.
Converts a file name to a color code.
def filecolor(filename):
colors = ("#f15501", "#f15501", "#f3ca0a", "#199c4b",
"#0298c3", "#ca2afe", "#6e4a7e", "#701516",
"#6594b9", "#0d3c6e", "#3ebc27", "#a9188d",
"#f15501", "#543978", "#37775b", "#0579aa",)
# if the filename has an extension, use it for the hash
if "." in filename:
filename = filename.split(".")[1]
selection = hash(filename) % 16
return colors[selection]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment