Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
RGBCell represents a color as the coordinates in the x-y-z coordinate system. Each of the three component color elements, red, green, and blue, have a float value from 0 to 255.
Creating an object without any params creates black:
1. require 'rgbcell'
2. color = RGBCell.new
3. color.to_s #=> #000000
4. color.red #=> 0.0
5. color.green #=> 0.0
6. color.blue #=> 0.0
Line 1 loads the RGBCell module. Line 2 create an RGBCell object. Because there are no parameters given, the object represents black. Line 3 show the stringification of the color such as might be used in CSS. Lines 4-6 show the numeric values of the three component colors, which are stored as floats.
There are several ways to indicate the color in RGBCell::new. One way is to give its three components as numeric values.
color = RGBCell.new(127, 255, 0)
color.to_s #=> #7fff00
You can indicate the color using hex format:
color = RGBCell.new('#7fff00')
color.to_s #=> #7fff00
color.red #=> 127.0
color.green #=> 255.0
color.blue #=> 0.0
You can give one of the HTML named colors. All 140 official named HTML colors are available. See W3C's page for the complete list.
color = RGBCell.new('purple')
color.to_s #=> #800080
color.red #=> 128.0
color.green #=> 0.0
color.blue #=> 128.0
You can use 'random' to get a random color:
color = RGBCell.new('random')
color.to_s #=> #dbd25b
color.red #=> 219.0
color.green #=> 210.0
color.blue #=> 91.0
Finally, you can also set each component color individually. Notice in this example that an integer value is converted to float.
color = RGBCell.new()
color.red = 60 #=> 60.0
color.green = 230 #=> 210.0
color.blue = 91.005 #=> 91.0005
color.to_s #=> #3ce65b
Because every color is a set of coordinates, the difference between two colors can be expressed as a distance. The distance is always zero or a positive number. For example, the following code gives the distance between red and chartreuse.
red = RGBCell.new('red')
chartreuse = RGBCell.new('chartreuse')
red.distance(chartreuse) #=> 285.3226244096321
The same thing can be expressed with the minus operator.
puts red - chartreuse #=> 285.3226244096321
The second color does not have to be an RGBCell object; it only needs to be an expression that can be used to create an RGBCell object.
puts red - 'green' #=> 360.62445840513925
Two or more colors can be averaged by calculating the midpoint of their
coordinates using the average
method. The result of the average is itself an
RGBCell object.
red = RGBCell.new('red')
tomato = RGBCell.new('tomato')
avg = red.average(tomato)
puts avg.class #=> RGBCell
puts avg.to_s #=> #ff3100
You can pass in more than one color for averaging. You can use RGBCell objects or any object that can be used to create an RGBCell object.
tomato = RGBCell.new('tomato')
puts tomato.average('orange', 'olive') #=> #d48200
If you prefer not to create any colors at all, you can use the class method.
puts RGBCell.average('tomato', 'orange', 'olive') #=> #d48200
gem install rgbcell
Mike O'Sullivan mike@idocs.com
version | date | notes |
---|---|---|
0.5 | June 25, 2020 | Initial upload. |
0.6 | June 26, 2020 | Edits to documentation. |
0.7 | June 26, 2020 | Another important edit to documentation. |
FAQs
Unknown package
We found that rgbcell demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.