Skip to content

Instantly share code, notes, and snippets.

View chestozo's full-sized avatar

chestozo

  • Portugal
  • 10:11 (UTC +01:00)
View GitHub Profile
@chestozo
chestozo / touch-scroll-minix.jsx
Last active October 7, 2023 13:51
react.js mixin for inertial scroll (momentum scroll) on touch devices
/**
On touch devices we have an intertial scroll effect (also called momentum scroll)
that is hard to detect (with scrollTop property for example).
See this article for problem details http://andyshora.com/mobile-scroll-event-problems.html
Still it is possible to detect inertial scroll by calculating velocity
with which user is scrolling element.
In this gist we use velocity formula from this article:
http://ariya.ofilabs.com/2013/11/javascript-kinetic-scrolling-part-2.html
# Based on http://stackoverflow.com/a/1260982/449345
# The most mneeeeee part is this one: `rm -rf .git/modules/mmmodule`
# This script can be useful in case you are changing origin for your
# nice and cool mmmodule.
git submodule deinit -f mmmodule
rm -rf .git/modules/mmmodule # kind of WAAAAT?!
git submodule init mmmodule
git submodule update --recursive
const added = [ 5, 6, 4 ]
const ar = [
{ id: 6, name: 'zzz' },
{ id: 1, name: 'aaa' },
{ id: 2, name: 'ccc' },
{ id: 5, name: 'yyy' },
{ id: 3, name: 'bbb' },
{ id: 4, name: 'xxx' },
]
@chestozo
chestozo / test.md
Last active May 28, 2021 17:43
How to fix react-dnd "Invariant Violation: Cannot call hover while not dragging." issue

In our case were getting this issue before we moved the data-testid attribute onto Dropzone input props like this:

<Dropzone
  onDrop={onDrop}
  accept={accept}
  style={{}}
  onClick={onClick}
  inputProps={{
 'data-testid': 'drop-file-input',
@chestozo
chestozo / storybook-router-params.js
Created April 15, 2020 15:07
Router params access from storybook story
import React from 'react'
import { MemoryRouter, Route } from 'react-router'
export default {
title: 'UserCard',
decorators: [],
}
const UserCard = ({
match: {
@chestozo
chestozo / settings.json
Created June 6, 2020 14:16
How to disable prettier formatting for HTML files in VSCode
{
"files.autoSave": "onFocusChange",
"prettier.requireConfig": true,
"prettier.disableLanguages": [
"HTML"
],
"editor.formatOnSave": true,
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
@chestozo
chestozo / ShowProps.tsx
Last active May 15, 2020 16:13
Quick print props for component component =) Useful for Formik
import React from 'react'
import styled from 'styled-components'
import { Box, TextBox } from 'ui-kit'
const Wrapper = styled(Box)`
position: fixed;
top: 0;
right: 0;
overflow: auto;
font-size: 80%;
(function() {
const methods = [ 'pushState', 'replaceState', 'back', 'forward', 'go' ]
const _originals = {}
methods.forEach((m) => {
_originals[m] = window.history[m]
window.history[m] = function() {
console.log('XXX', m, arguments)
return _originals[m].apply(window.history, arguments)
}
steps:
- name: node:10.16.3
entrypoint: yarn
args: ['build']
@chestozo
chestozo / timer.js
Created June 5, 2019 10:27
Measure time after click
document.addEventListener('click', () => {
const dt = Date.now();
const clockElement = document.createElement('div');
Object.assign(clockElement.style, {
position: 'absolute',
top: 0,
right: 0,
background: '#FAA',
'z-index': 9999,
padding: 5