Skip to content

Instantly share code, notes, and snippets.

View dlebedynskyi's full-sized avatar

Dima Lebedynskyi dlebedynskyi

View GitHub Profile
@dlebedynskyi
dlebedynskyi / ServerProvider.jsx
Last active February 15, 2017 16:11
Prefetch
import React from 'react';
/**
* Server only Provider component that passes promises as context
*/
export default class ServerFetchProvider extends React.Component {
static childContextTypes = {
serverFetchPromises: React.PropTypes.array
};
static propTypes = {
@dlebedynskyi
dlebedynskyi / sw-test-cleaup.js
Created March 23, 2017 15:18 — forked from gauntface/sw-test-cleaup.js
Function to unregister SW and clear out old caches.
window.__testCleanup = () => {
const unregisterSW = () => {
return navigator.serviceWorker.getRegistrations()
.then((registrations) => {
const unregisterPromise = registrations.map((registration) => {
return registration.unregister();
});
return Promise.all(unregisterPromise);
});
};
@dlebedynskyi
dlebedynskyi / get_nested.js
Created April 13, 2017 13:55
get deep nested object prop. functional way.
// https://medium.com/javascript-inside/safely-accessing-deeply-nested-values-in-javascript-99bf72a0855a
const idx = p => o =>
p.reduce((xs, x) =>
(xs && xs[x]) ? xs[x] : null, o)
const getUserComments = idx(['posts', 0, 'comments'])
const user = {}
console.log(getUserComments(user))
@dlebedynskyi
dlebedynskyi / operator_with_ligatures.md
Created July 8, 2017 01:48 — forked from renatorib/operator_with_ligatures.md
Using Operator Mono with Fira Code ligatures in Atom.

Using Operator Mono with Fira Code ligatures in Atom.

  1. Open your Atom's Stylesheet
    image

  2. Put this css

atom-text-editor {
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
@dlebedynskyi
dlebedynskyi / workbox.config.js
Created January 14, 2018 18:39
Workbox cli config
const fs = require('fs');
const path = require('path');
const loadJsonFile = require('load-json-file');
const dotNext = path.resolve(__dirname, '.next');
const stats = loadJsonFile.sync(`${dotNext}/build-stats.json`);
const buildId = fs.readFileSync(`${dotNext}/BUILD_ID`, 'utf8');
@dlebedynskyi
dlebedynskyi / LasyImage.jsx
Created January 14, 2018 19:33
Lasy Image Loading
class LazyImage extends PureComponent {
static defaultProps = {
engage: false,
};
state = {
initialEngage: false,
};
componentWillMount() {
/**
`useChangeLog` - dev-mode helper hook to let you
know why a memoized component re-rendered!
Usage example:
const YourComponent = React.memo((props) => {
// Just drop this fella into your memo component's body.
useChangeLog(props);
@dlebedynskyi
dlebedynskyi / LoadableWebpackPlugin.js
Created November 20, 2018 23:22
loadable-component emit file webpack plugin
const path = require('path')
const fs = require('fs')
class LoadablePlugin {
constructor({ filename = 'loadable-stats.json', writeToDisk = false } = {}) {
this.opts = { filename, writeToDisk }
}
gather = (hookCompiler, callback) => {
const stats = hookCompiler.getStats().toJson({
@dlebedynskyi
dlebedynskyi / git-apply-patch.md
Last active May 11, 2020 18:07 — forked from emmanueltissera/git-apply-patch.md
Generate a git patch for a specific commit #git

Creating the patch

git format-patch -1 <sha>
OR
git format-patch -1 HEAD

Applying the patch

git apply --stat file.patch # show stats.
git apply --check file.patch # check for error before applying

@dlebedynskyi
dlebedynskyi / bookmark.md
Last active November 19, 2020 18:25
wipe cookies and reload

one line

(function () {
    var cookies = document.cookie.split("; ");
    for (var c = 0; c < cookies.length; c++) {
        var d = window.location.hostname.split(".");
        while (d.length > 0) {
            var cookieBase = encodeURIComponent(cookies[c].split(";")[0].split("=")[0]) + '=; expires=Thu, 01-Jan-1970 00:00:01 GMT; domain=' + d.join('.') + ' ;path=';
            var p = location.pathname.split('/');