@param array|string $rgb
@param bool|TRUE $withHash

@return string
18464
public static function rgbToHex($rgb, $withHash = TRUE)
	{
		if (is_string($rgb)) {
			$rgbString = $rgb;

			// TODO : use regex
			$rgbString = str_replace(' ','', $rgbString);
			$rgbString = str_replace('rgb','', $rgbString);
			$rgbString = str_replace('(','', $rgbString);
			$rgbString = str_replace(')','', $rgbString);

			if (strpos($rgbString, ',') !== 0){
				$rgb = explode(',', $rgbString);
			} else {
				throw new InvalidArgumentException('Param was not an RGB in string');
			}
		}

		if (is_array($rgb)){
			if (isset($rgb['r']) && isset($rgb['g']) && isset($rgb['b'])){
				$rgb[0] = $rgb['r'];
				$rgb[1] = $rgb['g'];
				$rgb[2] = $rgb['b'];
			}

			if (empty($rgb) || !isset($rgb[0]) || !isset($rgb[1]) || !isset($rgb[2])) {
				throw new InvalidArgumentException('Param was not an RGB array');
			}
		} else {
			throw new InvalidArgumentException('Param was not an RGB array or string');
		}


		// Convert RGB to HEX
		$hex[0] = dechex($rgb[0]);
		$hex[1] = dechex($rgb[1]);
		$hex[2] = dechex($rgb[2]);

		if ($withHash) {
			return strtoupper('#' . sprintf("%02s%02s%02s", $hex[0], $hex[1], $hex[2]));

		} else {
			return strtoupper(sprintf("%02s%02s%02s", $hex[0], $hex[1], $hex[2]));
		}
	}
583384
public final void mHASH() throws RecognitionException {
		try {
			int _type = HASH;
			int _channel = DEFAULT_TOKEN_CHANNEL;
			// src/main/resources/org/drools/compiler/lang/DRL5Lexer.g:315:9: ( '#' )
			// src/main/resources/org/drools/compiler/lang/DRL5Lexer.g:315:13: '#'
			{
			match('#'); if (state.failed) return;
			}

			state.type = _type;
			state.channel = _channel;
		}
		finally {
			// do for sure before leaving
		}
	}
234201
public static function Map($MapHash) {
      if (array_key_exists($MapHash, self::$Maps))
         return self::$Maps[$MapHash];
      
      if (is_null($MapHash)) return self::$Maps;
      return FALSE;
   }
342383
public static function rgb2hsv( $rgb )
	{
#		return self::rgb2hsv_2( $rgb );
		list( $r, $g, $b ) = $rgb;
		$v	= max( $r, $g, $b );
		$t	= min( $r, $g, $b );
		$s	= ( $v == 0 ) ? 0 : ( $v - $t ) / $v;
		if( $s == 0 )
			$h	= 0;
		else
		{
			$a	= $v - $t;
			$cr	= ( $v - $r ) / $a;
			$cg	= ( $v - $g ) / $a;
			$cb	= ( $v - $b ) / $a;
			$h	= ( $r == $v ) ? $cb - $cg : ( ( $g == $v ) ? 2 + $cr - $cb : ( ( $b == $v ) ? $h = 4 + $cg - $cr : 0 ) );
			$h	= 60 * $h;
			$h	= ( $h < 0 ) ? $h + 360 : $h;
		}
		return array( round( $h ), round( $s * 100 ), round( $v / 2.55 ) );
	}
1222370
public function selectObjectByHash($hash)
       {
            $index = array_search($hash, $this->map, true);
            return (false !== $index) ? $this->selectObjectByKey($index) : false;
       }
211193
def render_hash(hsh)
      str = ""
      indiff_hsh = hsh.with_indifferent_access
      indiff_hsh.keys.sort.each do |key|
        str << "#{key}: "
        value = indiff_hsh[key]
        PP::pp(value, str)
      end
      str
    end
1148126
private function _rgb2hex(array $rgb)
	{
		if (isset($rgb['alpha']))
		{
			unset($rgb['alpha']);
		}
		$out = "";
		foreach ($rgb as $c)
		{
			$hex = base_convert($c, 10, 16);
			$out .= ($c < 16) ? ("0" . $hex) : $hex;
		}
		return '#' . strtoupper($out);
	}
1265387
private static function hex2rgb($hex, &$r, &$g, &$b)
    {
        // Remove hash if present
        $hex = preg_replace('/[^a-fA-F0-9]/', '', $hex);

        if (strlen($hex) == 6) {
            // 6-digit hex
            $r = substr($hex, 0, 2);
            $g = substr($hex, 2, 2);
            $b = substr($hex, 4, 2);
        } else {
            // 3-digit hex, pad to 6 total...
            $r = $hex[0] . $hex[0];
            $g = $hex[1] . $hex[1];
            $b = $hex[2] . $hex[2];
        }

        $r = hexdec($r);
        $g = hexdec($g);
        $b = hexdec($b);
    }
943805
public function byHash($hash)
    {
        $params = ["hash" => $hash];
        $apiUrl = $this->getPath('get', $params);
        $response = $this->api->getJSON($apiUrl);

        //XXX include Error checks
        $object = json_decode($response, true);
        return $this->createTransactionModel($object['data']); //XXX brr => error/content validation first
    }
1213187
public function calculateHash(): string
    {
        return EntityUtils::calculateHashOfArray([
            $this->red,
            $this->green,
            $this->blue,
            $this->alpha,
        ]);
    }
653369
public function with($withs)
    {
        if ( ! is_array($withs)) {
            $withs = func_get_args();
        }

        $this->withs = $withs;

        return $this;
    }
674373
private function convertHashToArrayOfBoolean()
	{
		preg_match_all('/(\w)(\w)/', $this->hash, $chars);

		foreach ($chars[1] as $i => $char)
		{
			if ($i % 3 == 0)
			{
				$this->arrayOfSquare[$i/3][0] = $this->convertHexaToBoolean($char);
				$this->arrayOfSquare[$i/3][4] = $this->convertHexaToBoolean($char);
			}
			elseif ($i % 3 == 1)
			{
				$this->arrayOfSquare[$i/3][1] = $this->convertHexaToBoolean($char);
				$this->arrayOfSquare[$i/3][3] = $this->convertHexaToBoolean($char);
			}
			else
			{
				$this->arrayOfSquare[$i/3][2] = $this->convertHexaToBoolean($char);
			}
			ksort($this->arrayOfSquare[$i/3]);
		}

		$this->color[0] = hexdec(array_pop($chars[1]))*16;
		$this->color[1] = hexdec(array_pop($chars[1]))*16;
		$this->color[2] = hexdec(array_pop($chars[1]))*16;

		return $this;
	}
1216342
public function setFromValue($rgb, $hasalpha = true)
    {
        $r = ($rgb >> 16) & 0xFF;
        $g = ($rgb >> 8) & 0xFF;
        $b = ($rgb >> 0) & 0xFF;
        if ($hasalpha) {
            $a = ($rgb >> 24) & 0xff;

            return $this->setRed($r)
                            ->setGreen($g)
                            ->setBlue($b)
                            ->setAlpha($a);
        }

        return $this->setRed($r)
                        ->setGreen($g)
                        ->setBlue($b);
    }
1132342
private function compileWith($with)
    {
        static $mapping = [
            'rule'     => self::WITH_RULE,
            'media'    => self::WITH_MEDIA,
            'supports' => self::WITH_SUPPORTS,
            'all'      => self::WITH_ALL,
        ];

        // exclude selectors by default
        $without = static::WITH_RULE;

        if ($this->libMapHasKey([$with, static::$with])) {
            $without = static::WITH_ALL;

            $list = $this->coerceList($this->libMapGet([$with, static::$with]));

            foreach ($list[2] as $item) {
                $keyword = $this->compileStringContent($this->coerceString($item));

                if (array_key_exists($keyword, $mapping)) {
                    $without &= ~($mapping[$keyword]);
                }
            }
        }

        if ($this->libMapHasKey([$with, static::$without])) {
            $without = 0;

            $list = $this->coerceList($this->libMapGet([$with, static::$without]));

            foreach ($list[2] as $item) {
                $keyword = $this->compileStringContent($this->coerceString($item));

                if (array_key_exists($keyword, $mapping)) {
                    $without |= $mapping[$keyword];
                }
            }
        }

        return $without;
    }
433953
public static TermColor getColorByHash(String hash) {

    	if(hash==null)
    		throw new IllegalArgumentException("Invalid hash value (null) for color construction");
    	
    	// lowercase and remove hash character, if any
    	hash = hash.toLowerCase().replaceAll("^#", "");
    	
    	// color written in #ABC format
        if(hash.matches("^[0-9a-f]{3}$")) {
            String r = hash.substring(0, 1);
            String g = hash.substring(1, 2);
            String b = hash.substring(2, 3);
            return new TermColorImpl(Integer.parseInt(r+r, 16), Integer.parseInt(g+g, 16), Integer.parseInt(b+b, 16));
        }
        // color written in #AABBCC format
        else if(hash.matches("^[0-9a-f]{6}$")) {
            String r = hash.substring(0, 2);
            String g = hash.substring(2, 4);
            String b = hash.substring(4, 6);
            return new TermColorImpl(Integer.parseInt(r, 16), Integer.parseInt(g, 16), Integer.parseInt(b, 16));
        }
        // invalid hash
        return null;
    }
670752
public function getKeyStr($hash = true)
    {
        $key =  $this->key . self::$INDEX_SEPERATOR . $this->groupId . self::$TAG_SEPERATOR . implode(self::$TAG_SEPERATOR, $this->gatherTags());
        if($hash) {
             $key = md5($key);
        }
        return $key;
    }
772582
function(rgb){
            var parts = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
            var hex = (parts[1]<<16|parts[2]<<8|parts[3]).toString(16);
            return "#"+Array(6-hex.length).concat([hex]).toString().replace(/,/g, 0);
        }