Skip to content

Instantly share code, notes, and snippets.

@codenickycode
codenickycode / react-dont-nest-components.md
Last active January 30, 2023 15:51
[React: Don't nest component definitions] React docs warning about nested component definitions #react #components #nesting
@codenickycode
codenickycode / eslint-vs-prettier.md
Last active January 29, 2023 18:53
[React: ESLint vs. Prettier] React docs best practice when ESLint conflicts with Prettier #eslint #lint #prettier #formatting #react
@codenickycode
codenickycode / path.js
Last active January 29, 2023 18:56
[Node.js: Path Resolution] path module resolution #node #javascript #path #url #module #import
import path from 'path';
import { fileURLToPath } from 'url';
const currentModuleURL = import.meta.url;
const pathToFile = fileURLToPath(currentModuleURL);
console.log(pathToFile);
//=> /Users/nick/Repos/node-test/path.js
console.log(path.dirname(pathToFile));
@codenickycode
codenickycode / react-state-management.md
Created January 3, 2023 17:24
[React: State Management Cheat Sheet] A rule of thumb for state management in React #react #state-management

Adapted from RemcoProgrammer's answer here:

Use Case Solution Example
Backend Cache React Query, Apollo Client fetch response
Navigation State React Router URL, params, history state
Component State (and subtree) useState, custom hooks is this thing currently open, what are the form contents and errors, what page of the table are we looking at
Unchanging Global State useContext auth, theme, language choice
Changing Global State Redux, Zustand dashboard data
@codenickycode
codenickycode / Dockerfile
Created January 3, 2023 13:38
[Docker: Dockerfile] Syntax to build an image #docker
# Argument outside the build stage
# To be used in first FROM
ARG <key>=<value>
# Parent image
FROM [--platform=<platform>] <image> [AS <name>]
# or
FROM [--platform=<platform>] <image>[:<tag>] [AS <name>]
# or
FROM [--platform=<platform>] <image>[@<digest>] [AS <name>]
@codenickycode
codenickycode / docker-cli.bash
Last active January 2, 2023 19:43
[Docker: CLI] Common Docker CLI Commands #docker #cli
# List all running containers
docker ps
# List all running and stopped containers
docker ps -a
# List all local images
docker images
# List all volumes
@codenickycode
codenickycode / ipv4.bash
Created December 30, 2022 22:21
[CLI: IPv4 Address] CLI command to get your IPv4 address #cli #bash #ip
# MacOs
ipconfig getifaddr en0
# Windows
ipconfig /all
# Linux
hostname -I
@codenickycode
codenickycode / xss.txt
Created December 30, 2022 22:19
[Security: XSS] Cross-Site Scripting #security #xss
https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html
@codenickycode
codenickycode / csrf.txt
Created December 30, 2022 22:03
[Security: CSRF] Cross Site Request Forgery #csrf #security
https://www.youtube.com/watch?v=eWEgUcHPle0
___
https://dev.to/hemanth/explain-csrf-like-im-five
CSRF (Cross Site Request Forgery) is also known as Sea-Surf or Session Riding. It's is a form of trick that bad folks play on the browser in order to get it to do unexpected things in applications that you're already logged in.
For example, imagine you were logged into your Supercell game on the internet. You get an e-mail saying "Click here to get 500 gems for free!". Clicking on the text, on the contrary, will actually initiate a request to Supercell to transfer all your gems to the hacker's account. Now, along with the request, the browser always sends the cookies to Supercell as well. Supercell verifies if the cookies are valid (which they are because you just logged in!), Supercell will trust the browser and the request and doesn't know that this is not what you wanted. They will go ahead and execute this instruction thinking this is what you wanted to do.
@codenickycode
codenickycode / satisfies.ts
Created December 30, 2022 21:36
[TS: Satisfies Operator] Example of the satisfies operator in TypesScript #typescript
type City = CityName | CityCoordinates;
type CityName = 'New York' | 'Mumbai' | 'Lagos';
type CityCoordinates = {
x: number;
y: number;
};
type User = {