<commit_before>
# ==============================================================================
#                                                                        HEX2RGB
# ==============================================================================
def hex2rgb(s):
    """ Given a color coded in hex code, eg `"#FF00FF"`, it returns
        the RGB pixel intensity representation of those values,
        scaled between 0-255
    Examples:
        >>> hex2rgb("#FF44AA")  # with hash notation
        (255, 68, 170)
        >>> hex2rgb("FF44AA")   # RGB
        (255, 68, 170)
        >>> hex2rgb("F4A")      # RGB compressed
        (255, 68, 170)
        >>> hex2rgb("FF44AAFF") # RGBA
        (255, 68, 170, 255)
        >>> hex2rgb("F4AF")      # RGBA compressed
        (255, 68, 170, 255)
    """
    if s.startswith("#"):
        s = s[1:]

    if len(s) == 6:
        return int(s[:2], 16), int(s[2:4], 16), int(s[4:6], 16)
    elif len(s) == 3:
        return int(s[0]+s[0], 16), int(s[1]+s[1], 16), int(s[2]+s[2], 16)
    elif len(s) == 4:
        return int(s[0]+s[0], 16), int(s[1]+s[1], 16), int(s[2]+s[2], 16), int(s[3]+s[3], 16)
    elif len(s) == 8:
        return int(s[:2], 16), int(s[2:4], 16), int(s[4:6], 16), int(s[6:8], 16)<commit_msg>FEAT: Add rgb2hex()<commit_after>
# ==============================================================================
#                                                                        HEX2RGB
# ==============================================================================
def hex2rgb(s):
    """ Given a color coded in hex code, eg `"#FF00FF"`, it returns
        the RGB pixel intensity representation of those values,
        scaled between 0-255
    Examples:
        >>> hex2rgb("#FF44AA")  # with hash notation
        (255, 68, 170)
        >>> hex2rgb("FF44AA")   # RGB
        (255, 68, 170)
        >>> hex2rgb("F4A")      # RGB compressed
        (255, 68, 170)
        >>> hex2rgb("FF44AAFF") # RGBA
        (255, 68, 170, 255)
        >>> hex2rgb("F4AF")      # RGBA compressed
        (255, 68, 170, 255)
    """
    if s.startswith("#"):
        s = s[1:]

    if len(s) == 6:
        return int(s[:2], 16), int(s[2:4], 16), int(s[4:6], 16)
    elif len(s) == 3:
        return int(s[0]+s[0], 16), int(s[1]+s[1], 16), int(s[2]+s[2], 16)
    elif len(s) == 4:
        return int(s[0]+s[0], 16), int(s[1]+s[1], 16), int(s[2]+s[2], 16), int(s[3]+s[3], 16)
    elif len(s) == 8:
        return int(s[:2], 16), int(s[2:4], 16), int(s[4:6], 16), int(s[6:8], 16)


# ==============================================================================
#                                                                        RGB2HEX
# ==============================================================================
def rgb2hex(code, hash=True, upper=True):
    """ Given an iterable of integers representing an RGB or RGBA color
        it returns the hexadecimal version of that color:

    Examples:
        >>> rgb2hex([7, 33, 255])
        '#0721FF'
        >>> rgb2hex([7, 33, 255], hash=False, upper=False)
        '0721ff'
    """
    prefix =  "#" if hash else ""
    hx = prefix + "".join(["{:>02s}".format(hex(channel)[2:])  for channel in code])
    if upper:
        hx = hx.upper()
    return hx
{'fraction_non_alphanumeric': 0.3060042669917708, 'fraction_numerical': 0.0853398354160317, 'mean_word_length': 2.3185035389282103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3481177', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1037, 'n_words': 265}