Skip to content

Instantly share code, notes, and snippets.

View lucis's full-sized avatar
🇧🇷
I can't describe what's happening

Lucis lucis

🇧🇷
I can't describe what's happening
View GitHub Profile
@slikts
slikts / advanced-memo.md
Last active September 12, 2024 18:33
Advanced memoization and effects in React

nelabs.dev

Advanced memoization and effects in React

Memoization is a somewhat fraught topic in the React world, meaning that it's easy to go wrong with it, for example, by [making memo() do nothing][memo-pitfall] by passing in children to a component. The general advice is to avoid memoization until the profiler tells you to optimize, but not all use cases are general, and even in the general use case you can find tricky nuances.

Discussing this topic requires some groundwork about the technical terms, and I'm placing these in once place so that it's easy to skim and skip over:

  • Memoization means caching the output based on the input; in the case of functions, it means caching the return value based on the arguments.
  • Values and references are unfortunately overloaded terms that can refer to the low-level implementation details of assignments in a language like C++, for example, or to memory
@palaniraja
palaniraja / merge-mp4.sh
Last active May 7, 2023 17:49
Bash script to merge all mp4 videos in current directory (recursively 2 levels). It also updates the chapter marks to retain the folder/filename of source dir
#!/bin/bash
## Script to merge all mp4 videos in current directory (recursively 2 levels)
## And update chapter marks to retain the folder/filename
## Script for merging videos
filename=`basename pwd`
current=`pwd`
@Almenon
Almenon / throttle.ts
Created March 11, 2018 04:29
typescript throttling / ratelimiting
/**
* class for limiting the rate of function calls.
* Thanks to Pat Migliaccio.
* see https://medium.com/@pat_migliaccio/rate-limiting-throttling-consecutive-function-calls-with-queues-4c9de7106acc
* @example let l = new limit(); let logMessageLimited = l.throttleAndQueue(msg => { console.log(msg); }, 500);
*/
class limit{
public callQueue = []
/**
@andyrbell
andyrbell / scanner.sh
Last active November 3, 2024 13:42
Make a pdf look scanned using ImageMagick
# use ImageMagick convert
# the order is important. the density argument applies to input.pdf and resize and rotate to output.pdf
convert -density 90 input.pdf -rotate 0.5 -attenuate 0.2 +noise Multiplicative -colorspace Gray output.pdf
@kavalcante
kavalcante / estados.js
Last active August 6, 2024 14:40
Estados do Brasil em um Array - Javascript
states: [
{ 'AC': 'Acre' },
{ 'AL': 'Alagoas' },
{ 'AP': 'Amapá' },
{ 'AM': 'Amazonas' },
{ 'BA': 'Bahia' },
{ 'CE': 'Ceará' },
{ 'DF': 'Distrito Federal' },
{ 'ES': 'Espírito Santo' },
{ 'GO': 'Goías' },
@ColCh
ColCh / README.md
Last active September 26, 2024 08:12
Git pre-push hook to confirm pushing to master