Skip to content

Instantly share code, notes, and snippets.

View theangelsofwar's full-sized avatar
💭
Art of Code

Angie Chang theangelsofwar

💭
Art of Code
View GitHub Profile
@dimitrinicolas
dimitrinicolas / README.md
Last active December 18, 2023 11:42
Handle mouse down/up and click events once with React Hooks

Handle mouse down/up and click events once with React Hooks

The issue

Sometimes you need to make a button clickable with click and mouse down or mouse up actions.

The first solution that comes to mind would be to add only one event listener onMouseDown/onMouseUp but without an onClick event listener the element is not accessible anymore. It's now hard to click for people with disabilities or with keyboard navigation.

If we set both onMouseDown/onMouseUp and onClick event listeners, the common click handler function would be called twice with a mouse. So we have

@andrzejewsky
andrzejewsky / Slider.js
Created March 2, 2019 13:35
Netflix Slider.js
import React, { useState } from 'react';
import cx from 'classnames';
import SliderContext from './context'
import Content from './Content'
import SlideButton from './SlideButton'
import SliderWrapper from './SliderWrapper'
import useSliding from './useSliding'
import useSizeElement from './useSizeElement'
import './Slider.scss'
# Insomnia Configuration
## Run the test query
{
shop {
id
name
}
}
# Query Structure Examples
it('renders random advice', () => {
const app = shallow(<App advice='Random Advice' fetching={false} />);
console.log("HERE", app.debug());
expect(app.instance().defineLabelAdvice()).toEqual('This is a random advice');
expect(app).toMatchSnapshot();
});
it('renders input based advice', () => {
const app = shallow(<App advice='Input Advice' fetching={false} />);
@jackawatts
jackawatts / ts-jest.md
Last active June 14, 2023 08:09
Getting started with Typescript, React and Jest

Getting Started

  1. Install:
  • jest: npm install --save-dev jest
  • ts-jest: npm install --save-dev ts-jest @types/jest
  1. Modify package.json
"jest": {
  "transform": {
 "^.+\\.tsx?$": "ts-jest"
@wschenk
wschenk / navbar.js
Created November 29, 2017 19:52
create-react-app material-ui navbar example
import React, {Component} from 'react'
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import AppBar from 'material-ui/AppBar';
import Toolbar from 'material-ui/Toolbar';
import Typography from 'material-ui/Typography';
import IconButton from 'material-ui/IconButton';
import MenuIcon from 'material-ui-icons/Menu';
import AccountCircle from 'material-ui-icons/AccountCircle';
@heygrady
heygrady / mapDispatchToProps.md
Last active September 16, 2023 19:19
Redux containers: mapDispatchToProps

Redux containers: mapDispatchToProps

This document details some tips and tricks for creating redux containers. Specifically, this document is looking at the mapDispatchToProps argument of the connect function from [react-redux][react-redux]. There are many ways to write the same thing in redux. This gist covers the various forms that mapDispatchToProps can take.

@thegitfather
thegitfather / vanilla-js-cheatsheet.md
Last active July 16, 2024 15:33
Vanilla JavaScript Quick Reference / Cheatsheet
@vasanthk
vasanthk / System Design.md
Last active July 22, 2024 05:05
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@bahmutov
bahmutov / Docker shell commands.sh
Last active February 9, 2024 07:55
A personal cheat sheet for running local Node project in a Docker container
# See list of docker virtual machines on the local box
$ docker-machine ls
NAME ACTIVE URL STATE URL SWARM DOCKER ERRORS
default * virtualbox Running tcp://192.168.99.100:2376 v1.9.1
# Note the host URL 192.168.99.100 - it will be used later!
# Build an image from current folder under given image name
$ docker build -t gleb/demo-app .