Skip to content

Instantly share code, notes, and snippets.

View fedyk's full-sized avatar

Andrii Fedyk fedyk

View GitHub Profile
@fedyk
fedyk / test.js
Created March 27, 2021 17:54
Add avatars to visitors
[{
name: "Dwight Schrute",
email: "d.schrute@dunder-mifflin.com",
avatar: "https://i.ibb.co/PYzBDTy/dwight.png"
}, {
name: "Kevin Malone",
email: "k.malone@dunder-mifflin.com",
avatar: "https://i.ibb.co/0n7D37f/kevin.png"
}, {
name: "Pam Beesly",
@fedyk
fedyk / app-freeze.js
Created July 19, 2019 14:37
Script allows you to test freeze in web application
function freezeApp(duration) {
var now = new Date().getTime();
var endTime = now + duration;
console.log('start freeze time', new Date().toISOString(), 'window is focused:', document.hasFocus());
while(new Date().getTime() < endTime) document.querySelector('this.is > [very] > *[heavy] > .css[selector]');
console.log('end freeze time', new Date().toISOString(), 'window is focused:', document.hasFocus());
}
/**
* Freeze app for 5000ms with 2000ms delay
@fedyk
fedyk / my-component.jsx
Last active March 26, 2019 15:49
Why my `PureComponent` is re-rendered?
class MyComponent extends React.Component<IProps> {
shouldComponentUpdate(nextProps, nextState) {
const nextPropsKeys = Object.keys(nextProps)
const propsKeys = Object.keys(this.props)
if (nextPropsKeys.length !== propsKeys.length) {
console.warn(`[MyComponent]: Mismatch in prop's keys`)
return true;
}
@fedyk
fedyk / rgbatorgb.js
Created March 11, 2019 20:05 — forked from tqc/rgbatorgb.js
Convert RGBA to RGB
function RGBAtoRGB(r, g, b, a, r2,g2,b2){
var r3 = Math.round(((1 - a) * r2) + (a * r))
var g3 = Math.round(((1 - a) * g2) + (a * g))
var b3 = Math.round(((1 - a) * b2) + (a * b))
return "rgb("+r3+","+g3+","+b3+")";
}
$("#result").html(RGBAtoRGB(225,110,0,0.5,255,255,255));
@fedyk
fedyk / React.Component.js
Last active November 29, 2018 09:55
what was changed
class App extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
const nextPropsKeys = Object.keys(nextProps);
const nextStateKeys = Object.keys(nextState);
for (let i = 0; i < nextPropsKeys.length; i++) {
const key = nextPropsKeys[i];
if (nextProps[key] !== this.props[key]) {
@fedyk
fedyk / main.js
Created February 6, 2018 14:42
async/await test
const request1 = () => new Promise((resolve, reject) => {
console.log('request1')
setTimeout(() => {
console.log('request1-resolved')
resolve(true)
}, 1000)
})
const request2 = () => new Promise((resolve, reject) => {
console.log('request2')
@fedyk
fedyk / bob.js
Created September 7, 2016 11:58
bob(1)(2)(3)(4)...(n) + '' == 1 + 2 + 3 + 4 + ... + n
function bob(val) {
if (this === window) {
return (new bob(val)).factorInc();
}
else {
this.v = val;
}
}
bob.prototype.inc = function(v) {
@fedyk
fedyk / nginx.conf
Created May 11, 2016 16:22
Add gzip compressing for nginx
server {
# ...
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
@fedyk
fedyk / ngPhone.js
Last active October 24, 2015 18:50
Angular Phone Validation
angular.module('myModule')
.directive('ngPhone', function() {
return {
require: 'ngModel',
link: function(scope, elem, attr, ngModel) {
function isPhone(str) {
var lengths = [7,10,11];
function eventThrottler(callback) {
if (!callback) {
return callback;
}
// @see http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
var requestAnimFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||