Skip to content

Instantly share code, notes, and snippets.

@MikelArnaiz
MikelArnaiz / hooks.ts
Created November 15, 2022 10:19
Use useWarningOnRefChangedButEqualDeepCompare
import { useEffect } from 'react';
import isEqual from 'lodash-es/isEqual';
export const usePrevious = <T>(value: T) => {
const ref = useRef<T>();
useEffect(() => {
ref.current = value;
});
return ref.current;
};
@MikelArnaiz
MikelArnaiz / download.sh
Last active July 28, 2022 14:38
test imgproxy sizes
!/bin/bash
id=c6cde936-ae71-4c3e-9ed6-9f65e225f001
sizes=( 285 700 1000 1200 1500 2000 )
formats=( "jpg" "webp" "avif" )
datafile="$id.csv"
echo "Creating $id.csv"
echo "width,quality,jpg,webp,avif" > $datafile
for w in "${sizes[@]}"
@MikelArnaiz
MikelArnaiz / demo.ts
Created June 8, 2022 07:12
ts-pattern v3 bug
type Foo =
| "Nope"
| ["a", "b", "c", "d", 'e', { x: string }]
function fn(foo: Foo) {
return match<Foo, string>(foo)
.with('Nope', () => 'no')
.with(['a', 'b', 'c', 'd', 'e', __], () => 'yes')
.exhaustive()
}
@MikelArnaiz
MikelArnaiz / loggit.txt
Created June 3, 2022 15:11
Git. Log commits, branch filtered by author and date
Based on https://stackoverflow.com/a/44494345/1355416
echo "Branch | Message | Author | Date"
git for-each-ref \
--sort=committerdate refs/heads/ \
--format='%(HEAD) %(refname:short) | %(contents:subject) | %(authorname) | %(committerdate:short)' \
| grep "Mikel Arnaiz | 2022-04-06"
@MikelArnaiz
MikelArnaiz / console.js
Created April 14, 2022 08:54
lighthose to cvs
Array
.from(document.querySelectorAll('.tabulator-row'))
.map(row => {
return Array
.from(row.querySelectorAll('.tabulator-cell'))
.slice(0, 3)
.map(cell => cell.innerText )
.join(',')
})
.join('\n')
@MikelArnaiz
MikelArnaiz / parseSizes.js
Last active April 13, 2022 15:42
parse and increase size-limit.json.
const fs = require('fs');
const sizeLimitIncreaseRate = 1.05
const chunkKBThreshold = 5
// Copy & paste data from "ANALYZE=true yarn build:prod" sidebar
const data =
[
"js/vendor1.d65be6d62f367668194a.chunk.js (145.48 KB)",
"js/vendor2.4421506493bc269f1ec0.chunk.js (69.44 KB)",
@MikelArnaiz
MikelArnaiz / test.ts
Last active February 16, 2022 10:42
Mock Date in jest
// https://github.com/facebook/jest/issues/2234#issuecomment-731451275
beforeAll(() => {
jest.useFakeTimers('modern'); // tell Jest to use a different timer implementation.
jest.setSystemTime(new Date('2022-02-15T22:30:00.000+01:00').getTime());
});
afterAll(() => {
// Back to reality...
jest.useRealTimers();
});
@MikelArnaiz
MikelArnaiz / input.scss
Created November 18, 2021 10:03
Generated by SassMeister.com.
@mixin byPlatform($type) {
@if $type == 'mobile' {
font-size: 8px;
line-height: 10px;
}
@if $type == 'table' {
font-size: 12x;
line-height: 15px;
}
@MikelArnaiz
MikelArnaiz / input.scss
Last active November 18, 2021 10:02
Generated by SassMeister.com.
@mixin byPlatform($type) {
@if $type == 'mobile' {
font-size: 8px;
line-height: 10px;
}
@if $type == 'table' {
font-size: 12x;
line-height: 15px;
}
@MikelArnaiz
MikelArnaiz / input.scss
Created November 18, 2021 09:59
Generated by SassMeister.com.
@mixin byPlatform($type) {
@if $type == 'mobile' {
font-size: 8px;
line-height: 10px;
}
@if $type == 'table' {
font-size: 12x;
line-height: 15px;
}