Skip to content

Instantly share code, notes, and snippets.

View jeneg's full-sized avatar

Yevhenii Chubar jeneg

  • GlobalLogic Ukraine
  • Kyiv, Ukraine
View GitHub Profile
@jeneg
jeneg / yiq.js
Created August 7, 2017 19:49
YIQ formula
function yiq(bgColor) {
var r = bgColor.r * 255,
g = bgColor.g * 255,
b = bgColor.b * 255;
var yiq = (r * 299 + g * 587 + b * 114) / 1000;
return (yiq >= 128) ? 'black' : 'white';
}
@jeneg
jeneg / lodashGetAlternative.js
Last active December 21, 2023 17:00
Alternative to lodash get method _.get()
function get(obj, path, def) {
var fullPath = path
.replace(/\[/g, '.')
.replace(/]/g, '')
.split('.')
.filter(Boolean);
return fullPath.every(everyFunc) ? obj : def;
function everyFunc(step) {
@jeneg
jeneg / Angular DI sort function
Last active August 29, 2015 14:17
Function for alphabetical sort of Angular dependency injections
/**
* Function for alphabetical sort of Angular dependency injections
*/
(function() {
var arr = ['$state', '$stateParams', '$rootScope', '$timeout',
'$templateCache', '$compile', 'googleMapService',
'actionCreateService', '$filter', 'configModel'];
arr.sort(function (a, b) {
a = a.replace('$', '');