Skip to content

Instantly share code, notes, and snippets.

View sobstel's full-sized avatar
⚛️

sobstel

⚛️
  • 07:55 (UTC +01:00)
View GitHub Profile
@sobstel
sobstel / main.js
Created February 20, 2024 16:40
Background non-stopping setTimeout
const worker = null;
const start = (callback, delay) => {
const args = { foo: "abc" };
worker = new Worker('/timeoutWorker.js');
worker.onmessage = (event) => {
if (event.isTrusted && event.data === "timeout") {
callback();
}
@sobstel
sobstel / redis.mock.js
Created November 29, 2023 12:59
Partial node-redis mock
const now = () => new Date().getTime() / 1000;
let values = {};
let ttls = {}
const client = {
    del: async (key) => {
        delete values[key];
    },
    expire: async (key, ttl) => {
@sobstel
sobstel / autofill.ts
Last active September 30, 2022 09:26
React: handle browser-autofilled password in Chrome
// Problem: when remembered, Chrome auto-fills the password input, but in fact it doesn't
// set the value and doesn't fire onChange event until there's any kind of interaction.
// If password value is empty, then submit button is still disabled yet password looks filled,
// which looks bad. See: https://bugs.chromium.org/p/chromium/issues/detail?id=813175
const [isAutofilled, setIsAutofilled] = useState(false);
const passwordElRef = useRef<HTMLInputElement | null>(null);
useEffect(() => {
const element = passwordElRef.current;
@sobstel
sobstel / shapeup-pitch.md
Last active September 30, 2022 09:24
Shape Up: Write the Pitch

Problem

The raw idea, a use case, or something we’ve seen that motivates us to work on this

Appetite

How much time we want to spend and how that constrains the solution

Solution

@sobstel
sobstel / CODE_delorean_clock.ino
Last active July 11, 2023 15:28
CODE_delorean_clock_V4_SUMMER.ino [UPDATED]
#include "SevenSegmentTM1637.h"
#include "SevenSegmentExtended.h"
#include "RTClib.h"
// Sortie horloge Rouge
const byte PIN_CLK_Red = A0; // define CLK pin
// Sortie horloge Verte
const byte PIN_CLK_Green = A1; // define CLK pin
// Sortie horloge Orange
const byte PIN_CLK_Orange = A2; // define CLK pin
@sobstel
sobstel / mapDuplicates.test.ts
Created April 4, 2021 10:02
Remeda mapDuplicates
import mapDuplicates from "./mapDuplicates";
describe("mapDuplicates", () => {
it("addresses duplicate surnames", () => {
const surnames = ["González", "González", "Martínez", "González"];
expect(
mapDuplicates(surnames, (name, index) => `${name} ${index}`)
).toEqual(["González 0", "González 1", "Martínez", "González 3"]);
});
@sobstel
sobstel / unmount_animation_example.js
Created March 8, 2021 09:57
react-native-animatable unmount animation with hooks
// https://github.com/oblador/react-native-animatable/issues/132#issuecomment-786870602
const MyComponent = (props) => {
const ref = React.useRef();
React.useEffect(() => {
ref?.current?.fadeIn();
return () => ref?.current?.fadeOut(); // as you know, this is the same as unmount ;)
}, [props.id]); // track some prop that changes
@sobstel
sobstel / deploy.yml
Created October 1, 2020 16:27
Deploy Ruby AWS lambda with github action
on:
push:
branches:
- "master"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
@sobstel
sobstel / win10vm_apple_keyboard.txt
Last active November 2, 2020 09:51
win10vm_apple_keyboard
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetScrollLockState, AlwaysOff
;following section remaps alt-arrow and command-arrow
;keys to mimic OSX behaviour
#Up::SendInput {Lctrl down}{Home}{Lctrl up}
@sobstel
sobstel / page-speed-report.md
Last active May 7, 2020 11:30
Google page speed report 2018

Google page speed report 2018

  • Time spent on mobile vs desktop 
    • 2015 -> Google started getting more search queries from mobile than desktop
    • 2018 -> Time spent on mobile 2-3x bigger than on desktop (and growing...)
  • Users reaction
    • 46% dislike waiting for slow pages to load 
    • 53% abandon a site that loads in more than 3 seconds
  • As of July 2018, page speed will become an important ranking factor for mobile searches 
  • Page speed will also influence ad rank and the CPC that you pay