Skip to content

Instantly share code, notes, and snippets.

@ryancat
ryancat / colorConvert.js
Created May 9, 2018 06:10
Convert color from RGB to LAB, RGB to HEX, or vice versa
/**
* Convert a hex color string to RGB array
* @param {String} hex Hex color string
*/
function hexToRgb(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? [
parseInt(result[1], 16),
parseInt(result[2], 16),
parseInt(result[3], 16)
@ryancat
ryancat / colorDiffUtil.js
Created May 9, 2018 06:07
Color difference in RGB and LAB
/**
* Compare color difference in RGB
* @param {Array} rgb1 First RGB color in array
* @param {Array} rgb2 Second RGB color in array
*/
export function deltaRgb (rgb1, rgb2) {
const [ r1, g1, b1 ] = rgb1,
[ r2, g2, b2 ] = rgb2,
drp2 = Math.pow(r1 - r2, 2),
dgp2 = Math.pow(g1 - g2, 2),
@ryancat
ryancat / test_example.js
Last active March 12, 2018 19:51
webdriverjs tests locally and use sauce labs to run remotely
const {Builder, By, Key, until, remote} = require('selenium-webdriver');
const sauceUsername = process.env.SAUCELABS_USER,
sauceApiToken = process.env.SAUCELABS_APITOKEN;
(async function example() {
let driver = await new Builder()
.forBrowser('firefox')
.build();
@ryancat
ryancat / handleTouchMove.js
Created September 12, 2017 06:25
Mobile touch move detection
let touches = {
touchstart: Object.assign({}, {
x: -1,
y: -1
}),
touchmove: Object.assign({}, {
x: -1,
y: -1
})
}
@ryancat
ryancat / gist:d4b1521f82a30b9a1354df1280daade9
Created July 10, 2017 15:23
Fix flow import style issue
GOAL:
Make flow understand *.css files and map them to an exported Object or whatever type you need... also to prevent this dreaded module not found error.
STEPS:
In your project folder, create a file helpers/CSSModule.js with following content:
//@flow
export default {};
@ryancat
ryancat / remove multiple git branch
Created March 1, 2016 21:40
remove multiple git branch
git branch | grep '3\.2' | xargs git branch -d
@ryancat
ryancat / gist:0a8f39b5f001f2f8f231
Created April 8, 2015 01:06
How to use two different versions in bower
http://www.danschnau.com/multiple-versions-of-a-package-in-bower/
"dependencies": {
"jquery-1.9.1": "jquery#1.9.1",
"jquery-1.8.1": "jquery#1.8.1"
}
@ryancat
ryancat / gist:90679171d27eda64bbf2
Created April 2, 2015 15:20
How to change file name in multiple folders
http://unix.stackexchange.com/questions/102647/how-to-rename-multiple-files-in-single-command-or-script-in-unix
for file in aro_tty-mIF-*_opt
do
mv -i "${file}" "${file/-mIF-/-mImpFRA-}"
done
@ryancat
ryancat / gist:f67c3eab4a7e25858586
Created April 2, 2015 05:56
How to add folder in multiple folders
http://unix.stackexchange.com/questions/61907/how-do-i-create-a-directory-in-all-subdirectories
for dir in */; do mkdir -- "$dir/tmp1"; done