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 / Copy text on clipboard
Created January 13, 2014 16:18
JS function to copy text in clipboard.
function copyText (text) {
var div = document.getElementById('__special_copy_div'),
saveSelection,
selection,
rng,
i;
if (!div) {
div = document.createElement('pre');
div.id = '__special_copy_div';
@fedyk
fedyk / gist:8147009
Created December 27, 2013 13:40
extend.js
function extend() {
var a = arguments, target = a[0] || {}, i = 1, l = a.length, deep = false, options;
if (typeof target === 'boolean') {
deep = target;
target = a[1] || {};
i = 2;
}
if (typeof target !== 'object' && !isFunction(target)) target = {};