Skip to content

Instantly share code, notes, and snippets.

@bdadam
bdadam / qrcode.sh
Created September 20, 2025 09:13
Generate QR code on Linux
sudo apt install qrencode
printf "Hello world" | qrencode -t utf8
@bdadam
bdadam / index.mjs
Last active March 24, 2025 00:03
Check sertificate validity date
#!/usr/bin/env zx
const x =
await $`echo | openssl s_client -servername bdadam.com -connect "bdadam.com:443" 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2`;
const diff = new Date(x.stdout).getTime() - Date.now();
console.log(diff);
console.log(diff > 30 * 24 * 60 * 60 * 1000);
@bdadam
bdadam / calc.ts
Created October 15, 2024 22:03
Mean, percentiles in JS
// https://stackoverflow.com/questions/48719873/how-to-get-median-and-quartiles-percentiles-of-an-array-in-javascript-or-php
// sort array ascending
const asc = arr => arr.sort((a, b) => a - b);
const sum = arr => arr.reduce((a, b) => a + b, 0);
const mean = arr => sum(arr) / arr.length;
// sample standard deviation
@bdadam
bdadam / simple-cache.ts
Created October 11, 2022 20:40
SWR Cache
// createCache.ts
export default function createCache(fetchFunction: () => Promise<any>, refreshInterval: number, retryAfter: number) {
let fetchPromise: null | ReturnType<typeof fetchFunction> = null;
const doThinInInterval = () => {
fetchFunction().then((data) => {
fetchPromise = Promise.resolve(data);
})
.catch(() => setTimeout(doThinInInterval, retryAfter));
// https://leetcode.com/problems/lru-cache/submissions/
class LRUCache {
obj: Record<number, { val: number; acc: number }>;
capacity: number;
size: number;
acc: number;
cache: Record<number, [val: number, acc: number, key: number]>;
c: Map<number, [val: number, acc: number]>
@bdadam
bdadam / readme.md
Created September 6, 2022 23:40
Change Display Brightness Below Minimum
echo 1 | sudo tee /sys/class/backlight/intel_backlight/brightness 
@bdadam
bdadam / readme.md
Last active February 23, 2023 21:15
Dev Meeting 2022-02-10

Things we are always saying

  • Parts of the code are under-tested
  • Parts of the code are "hard to reason about"
  • Parts of the code are slow

Stateless functions, No side effects, Dependency injection

const state = {
@bdadam
bdadam / interpolate.test.ts
Created July 5, 2021 08:36
String interpolation
import interpolate from './interpolate';
describe('Interpolate for Translations', () => {
// eslint-disable-next-line jest/no-commented-out-tests
// it('blah', () => {
// expect(interpolate('asdf')).toEqual('asdf');
// expect(interpolate('Hello {0}', ['World!'])).toEqual('Hello World!');
// expect(interpolate('Hello {0} {0}', ['World!'])).toEqual('Hello World! World!');
// expect(interpolate('Hello {0} {1} {2}!', ['World!', 'Welcome', 'here'])).toEqual('Hello World! Welcome here!');
// expect(interpolate('Hello {0} {1} {2}! {1} {2}!', ['World!', 'Welcome', 'here'])).toEqual(
@bdadam
bdadam / download.sh
Last active March 6, 2021 21:23
Download open tabs from Chrome Android
# https://android.stackexchange.com/a/199496
adb forward tcp:9222 localabstract:chrome_devtools_remote
wget -O tabs.json http://localhost:9222/json/list
@bdadam
bdadam / fp-in-js.txt
Last active December 12, 2017 00:41
Links to some Functional Programming resources in JavaScript in no particular order
Functional Programming Jargon in simple terms:
https://github.com/hemanth/functional-programming-jargon
Professor Frisby's Mostly Adequate Guide to Functional Programming (book):
https://drboolean.gitbooks.io/mostly-adequate-guide/content/
A series on FP in JS from Eric Elliott:
https://medium.com/javascript-scene/the-rise-and-fall-and-rise-of-functional-programming-composable-software-c2d91b424c8c
Some introduction to Monads: