Skip to content

Instantly share code, notes, and snippets.

View sobstel's full-sized avatar

sobstel

  • 23:42 (UTC +02: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 / conv_base16_to_base36.sql
Last active November 11, 2023 09:14
MySQL: Converting from base-16 to base-36 number (with 128bit precision)
-- convert from base-16 to base-36 (128bit precision)
CREATE FUNCTION conv(_hex TEXT)
RETURNS TEXT
BEGIN
DECLARE _hex_len TINYINT;
DECLARE _dec DECIMAL(65);
DECLARE _chars CHAR(36);
DECLARE _base36 TEXT;
DECLARE _mod TINYINT;
@sobstel
sobstel / effective_ruby.md
Last active November 10, 2023 20:20
Effective Ruby

Effective Ruby

#1 (Almost) Everything is true

  • Every value is true except false and nil.
  • The number zero is true in Ruby.
  • Use the nil? method to differentiate between false and nil.

#2 All objects could be nil

@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 / datetime_timezones.php
Created September 9, 2011 16:52
PHP: Converting DateTime between timezones
<?php
// now
$date = date_create('2010-12-31 22:00:01', timezone_open('Europe/Amsterdam'));
// Buenos Aires
date_timezone_set($date, timezone_open('America/Argentina/Buenos_Aires'));
echo $date->format('Y-m-d H:i:s');
// 2010-12-31 18:00:01
// UTC
@sobstel
sobstel / over-engineering-mistakes.md
Created August 12, 2016 13:06
10 Modern Software Over-Engineering Mistakes

10 Modern Software Over-Engineering Mistakes

  1. Engineering is more clever than Business? The House (Business) Always Wins.
  2. Reusable Business Functionality? Prefer Isolating Actions than Combining.
  3. Everything is Generic? Duplication is better than the wrong abstraction.
  4. Shallow Wrappers? Wrappers are an exception, not the norm. Don’t wrap good libraries for the sake of wrapping.
  5. Applying Quality like a Tool? Always take a step back and look at the macro picture. Concepts need shift in Mindset. Cannot be applied blindly like tools.
  6. Overzealous Adopter Syndrome? TL;DRs should not be used everywhere.
  7. –ity? Don’t let -ities go unchallenged. Clearly define and evaluate the Scenario/Story/Need/Usage.
  8. In House “Inventions”? Reuse. Fork. Contribute. Reconsider.
@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 / import_from_db.sh
Created December 4, 2017 14:28
Heroku prod database export to Docker database container
#!/bin/bash
# stop on first error
set -e
command -v heroku >/dev/null 2>&1 || { echo >&2 "heroku command is required"; exit 1; }
command -v docker-compose >/dev/null 2>&1 || { echo >&2 "docker-compose command is required"; exit 1; }
DUMPFILE="/tmp/_FILENAME_.dump"