Skip to content

Instantly share code, notes, and snippets.

View ConnectedReasoning's full-sized avatar

Manuel Hernandez ConnectedReasoning

  • Southern California
View GitHub Profile
@ConnectedReasoning
ConnectedReasoning / brightnessByColor.js
Last active August 6, 2018 19:17 — forked from rafael25/brightnessByColor.js
Calculate brightness value by RGB or HEX color
brightnessByColor(color) {
let luminance = 0;
const isHEX = color.indexOf("#") == 0;
const isRGB = color.indexOf("rgb") == 0
let m, r, g, b;
if (isHEX) {
m = color.substr(1).match(color.length == 7 ? /(\S{2})/g : /(\S{1})/g);
if (m) {
r = parseInt(m[0], 16);
@ConnectedReasoning
ConnectedReasoning / brightnessByColor.js
Created August 6, 2018 18:36 — forked from rafael25/brightnessByColor.js
Calculate brightness value by RGB or HEX color
/**
* Calculate brightness value by RGB or HEX color.
* @param color (String) The color value in RGB or HEX (for example: #000000 || #000 || rgb(0,0,0) || rgba(0,0,0,0))
* @returns (Number) The brightness value (dark) 0 ... 255 (light)
*/
function brightnessByColor (color) {
var color = "" + color, isHEX = color.indexOf("#") == 0, isRGB = color.indexOf("rgb") == 0;
if (isHEX) {
var m = color.substr(1).match(color.length == 7 ? /(\S{2})/g : /(\S{1})/g);
if (m) var r = parseInt(m[0], 16), g = parseInt(m[1], 16), b = parseInt(m[2], 16);
@ConnectedReasoning
ConnectedReasoning / svgfixer.js
Created July 11, 2017 20:18 — forked from leonderijke/svgfixer.js
Fixes references to inline SVG elements when the <base> tag is in use.
/**
* SVG Fixer
*
* Fixes references to inline SVG elements when the <base> tag is in use.
* Firefox won't display SVG icons referenced with
* `<svg><use xlink:href="#id-of-icon-def"></use></svg>` when the <base> tag is on the page.
*
* More info:
* - http://stackoverflow.com/a/18265336/796152
* - http://www.w3.org/TR/SVG/linking.html