Skip to content

Instantly share code, notes, and snippets.

Created June 1, 2013 17:23
Show Gist options
  • Select an option

  • Save anonymous/5691090 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/5691090 to your computer and use it in GitHub Desktop.
test
# python's hex function
import struct
def hex_to_rgb(rgb_str):
int_tuple = struct.unpack('BBB', bytes.fromhex(rgb_str))
return tuple([val/255 for val in int_tuple])
print(hex_to_rgb('f8ff35'))
def hexify(color):
strip_n_pad = lambda stp: str(stp[2:]).zfill(2)
return "#" + "".join([strip_n_pad(hex(col)) for col in color])
print(hexify((128,128,128)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment