Skip to content

Instantly share code, notes, and snippets.

@rafael25
rafael25 / brightnessByColor.js
Created February 21, 2018 23:40 — forked from w3core/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);
@rafael25
rafael25 / gist:6911010d77c298233946434cdb0893c4
Created February 14, 2018 05:07 — forked from mikeal/gist:1840641
get a new/clean port with node.js
var portrange = 45032
function getPort (cb) {
var port = portrange
portrange += 1
var server = net.createServer()
server.listen(port, function (err) {
server.once('close', function () {
cb(port)
@rafael25
rafael25 / data.json
Created February 23, 2016 17:56
Setear objeto json usando el campo _id
[
{
"_id": 7,
"assignmentDateFormats": {},
"idAssignment": 29,
"assignmentDate": {},
"currentAssignment": 0,
"idEmmployee": 24,
"idDwEnterprise": 85,
"idStock": 1,
@rafael25
rafael25 / git_diff_details_error.log
Created July 9, 2015 09:45
Output from: apm install git-diff-details --verbose
Installing git-diff-details to /home/rafael/.atom/packages REQUEST { method: 'GET',
url: 'https://atom.io/api/packages/git-diff-details',
json: true,
retries: 4,
proxy: null,
strictSSL: true,
headers: { 'User-Agent': 'npm/2.5.1 node/v0.10.35 linux x64' },
uri: null,
callback: [Function] }
REQUEST make request https://atom.io/api/packages/git-diff-details
@rafael25
rafael25 / .gitignore
Last active August 29, 2015 14:09 — forked from octocat/.gitignore
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #