Skip to content

Instantly share code, notes, and snippets.

View lxynox's full-sized avatar
🌴
On vacation

⦇⦀∙ˇ∎ˇ∙⦀⦈ lxynox

🌴
On vacation
View GitHub Profile
@lxynox
lxynox / node_modules.md
Last active November 19, 2019 15:13
Things around node_modules

Dependency

Peer Dependency

What we need is a way of expressing these "dependencies" between plugins and their host package. Some way of saying, "I only work when plugged in to version 1.2.x of my host package, so if you install me, be sure that it's alongside a compatible host." We call this relationship a peer dependency.

Problem Solution
@lxynox
lxynox / axios.md
Created April 1, 2019 19:24
Error handling
axios.get('/user/12345')
  .catch(function (error) {
    if (error.response) {
      // The request was made and the server responded with a status code
      // that falls out of the range of 2xx
      console.log(error.response.data);
      console.log(error.response.status);
      console.log(error.response.headers);
 } else if (error.request) {
@lxynox
lxynox / progressive-image-loading.md
Last active June 22, 2019 09:01
Progressive Image Loading (react)

What ('s the problem)

How can we improve image loading experience while waiting the browser download the image?

  • Doing nothing
  • Display some solid color / placeholder ✅
  • Progressive image loading

Why

@lxynox
lxynox / keymaps.json
Created November 13, 2018 18:26
Hyper term keymaps (mac)
{
"window:devtools": "command+alt+i",
"window:reload": "command+r",
"window:reloadFull": "command+shift+r",
"window:preferences": "command+,",
"zoom:reset": "command+0",
"zoom:in": "command+plus",
"zoom:out": "command+-",
"window:new": "command+n",
"window:minimize": "command+m",
@lxynox
lxynox / hackathon-AD.md
Last active September 12, 2019 08:03 — forked from lxyad/intro.md
pwa

Features

  • Add to home screen
  • Install banner
  • Offline support
  • App shell
  • Push notifications?
  • Background sync?
  • Server side rendering (SEO + improve First Meaningful Paint(FMP))
@lxynox
lxynox / log.js
Created November 5, 2018 16:43
life hack: console log function that auto-indents based on the depth of your call stack
//////////// https://twitter.com/sophiebits/status/1058448900460138497
// alternative use `console.group`, `console.groupEnd`, pen: https://codepen.io/zzzzBov/pen/yQLyyG/
function log(format, ...args) {
let indent = ' '.repeat(new Error().stack.match(/\n/g).length - 2);
if (typeof format === 'string') {
console.log(indent + format, ...args);
} else {
console.log(indent, format, ...args);
}
@lxynox
lxynox / Composition.md
Last active June 22, 2019 08:50
React Children, React.cloneElement etc

In fact, React.cloneElement is not strictly associated with this.props.children. It's useful whenever you need to clone react elements(PropTypes.elements) to add/override props(such as attaching event handlers or assigning key/ref attributes) as react elements are immutable.

React.cloneElement( element, [props], [...children] ) is almost equivalent to: <element.type {...element.props} {...props}>{children}</element.type>

However, children prop in react, is specially used for containment(aka composition) of other components, e.g,

@lxynox
lxynox / lodashify.js
Created August 5, 2018 17:07 — forked from khalilovcmd/lodashify.js
to import lodash into chrome dev tools console
var el = document.createElement('script');
el.src = "https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.10/lodash.core.min.js";
el.type = "text/javascript";
document.head.appendChild(el)
const COLORS = {
blue: ['#1E88E5', '#90CAF9'],
brown: ['#6D4C41', '#D7CCC8'],
gray: ['#212121', '#BDBDBD'],
green: ['#388E3C', '#A5D6A7'],
red: ['#E53935', '#EF9A9A'],
orange: ['#F4511E', '#FFAB91'],
purple: ['#8E24AA', '#E1BEE7'],
yellow: ['#FFD600', '#FFF59D'],
}