Skip to content

Instantly share code, notes, and snippets.

View arekko's full-sized avatar
🎯
Focusing

Andrei Vasilev arekko

🎯
Focusing
  • Smartly.io
  • Helsinki, Finland
View GitHub Profile
import { useCallback, useEffect, useRef } from 'react';
/**
* A callback that stays stable between renders even as the dependencies change.
*
* @see https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
*/
export function useStableEventHandler<T extends (...args: any[]) => any>(fn: T): T {
const ref = useRef<T>();
module.exports = {
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
extends: [
"plugin:@typescript-eslint/recommended" // Uses the recommended rules from the @typescript-eslint/eslint-plugin
],
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: "module" // Allows for the use of imports
},
rules: {
@benawad
benawad / Resolver.ts
Last active June 1, 2021 15:59
middleware role
@UseMiddleware(hasRole("admin"))
@Query(() => String)
async hello() {
return "Hello World!";
}
@busypeoples
busypeoples / MonolithicComponentsComposableComponents.md
Last active September 24, 2022 17:14
Monolithic Components, Composable Components

Monolithic Components, Composable Components

Introduction

Building reusable UI components is a non trivial task, as we need to anticipate a number of things when planing for reuseability. On the one end of the spectrum we want to enable customization and on the other side we want to avoid developers doing the wrong thing, like breaking the component or displaying invalid states.

To get a better understanding of what we need to think about and consider upfront, we will build a non-trivial UI component, that displays tags. Our Tags component will take care of managing and displaying tags.

The following examples are all built with Tachyons and React, but these ideas apply to any UI component and any general styling approach.

@busypeoples
busypeoples / ExplicitStatesInReact.md
Last active June 22, 2019 18:02
Making unrepresentable UI representations unrepresentable!

Making Unrepresentable UI Representations Unrepresentable!

When building components, we mostly start out with a minimal API, as we mostly have a clear initial idea of what the Component should do. But as requirements start to change, our API might start to evolve a long the way too. We start adding more props to cover conditional or special cases etc. Sometimes we use optional props, as in not required, or we might start using flags, as in boolean props or enums, to handle variants. Let's take a closer look at optional props and what effects these can have on our UI representation.

Optional props

@bradtraversy
bradtraversy / docker-help.md
Last active October 15, 2025 19:19
Docker Commands, Help & Tips

Docker Commands, Help & Tips

Show commands & management commands

$ docker

Docker version info

@hagemann
hagemann / database.js
Last active July 12, 2025 22:06
Promisified MySQL middleware for Node.js
const util = require('util')
const mysql = require('mysql')
const pool = mysql.createPool({
connectionLimit: 10,
host: 'localhost',
user: 'root',
password: 'password',
database: 'my_database'
})
//-----------------------------------------------//
//On page load
// - Browser -
//-----------------------------------------------//
AWS.config.update({
region: "eu-west-1"
});
var credConfig = {
@datchley
datchley / react-redux-style-guide.md
Last active October 2, 2025 20:13
React + Redux Style Guide
@jamesbar2
jamesbar2 / postal-codes.json
Last active September 13, 2025 06:11 — forked from matthewbednarski/postal-codes.json
Global postal codes regex formats
[{
"Note": "The first two digits (ranging from 10–43) correspond to the province, while the last two digits correspond either to the city/delivery zone (range 01–50) or to the district/delivery zone (range 51–99). Afghanistan Postal code lookup",
"Country": "Afghanistan",
"ISO": "AF",
"Format": "NNNN",
"Regex": "^\\d{4}$"
}, {
"Note": "With Finland, first two numbers are 22.",
"Country": "Åland Islands",
"ISO": "AX",