Skip to content

Instantly share code, notes, and snippets.

View Greenheart's full-sized avatar
🌍
Let's co-create a future that is regenerative and distributive by design

Samuel Plumppu Greenheart

🌍
Let's co-create a future that is regenerative and distributive by design
View GitHub Profile
@Greenheart
Greenheart / getShortId.ts
Last active September 14, 2025 10:56
Generate a short k-sortable ID with a given prefix. Useful for small amounts of IDs. Can generate up to 260 ids per prefix by default, and could be tweaked to support even more if needed.
/**
* Generate a short k-sortable ID with a given prefix. Useful for small amounts of IDs.
* Can generate up to 260 ids per prefix by default, and could be tweaked to support even more if needed.
*/
function getShortId(
prefix: 'd' | 's',
lowercase = 'abcdefghijklmnopqrstuvwxyz',
numbers = '0123456789',
) {
let letterIndex = 0
@Greenheart
Greenheart / generate-flatpak-aliases.sh
Created August 21, 2025 14:48
Generate Flatpak aliases that can be added to the PATH
#!/usr/bin/bash
# List installed flatpaks which have a command specified
# These aliases can then be added to the PATH in for example .bashrc
for bin in /var/lib/flatpak/exports/bin/*; do
appid="$(basename $bin)"
cmd="$(flatpak info -m $appid | awk -F= '/^command=/ {print $2}')"
echo "alias ${cmd}=$bin"
done
@Greenheart
Greenheart / tailwind-4-browser-compatibilty.txt
Created April 18, 2025 16:51
Check browser compatibily for Tailwind 4
Safari>=16.4,Firefox>=128,Chrome>=111,and_chr>=111,and_ff>=128,edge>=111,ios_saf>=16.4,opera>=97
2023-03-27 Safari 16.4+
2023-03-07 Chrome 111+
2024-07-09 Firefox 128+
https://browserslist.dev/?q=U2FmYXJpPj0xNi40LEZpcmVmb3g%2BPTEyOCxDaHJvbWU%2BPTExMSxhbmRfY2hyPj0xMTEsYW5kX2ZmPj0xMjgsZWRnZT49MTExLGlvc19zYWY%2BPTE2LjQsb3BlcmE%2BPTk3
@Greenheart
Greenheart / createCache.ts
Created May 18, 2024 08:49
In memory caching to reduce data usage for frequent API requests, repeated data processing or similar use cases.
const FIVE_MINUTES = 1000 * 60 * 5
function createCache<K, V>({ maxAge }: { maxAge: number }) {
const cache = new Map<
K,
V & { cachedAt: ReturnType<(typeof Date)['now']> }
>()
return {
set(key: K, value: V) {
cache.set(key, { ...value, cachedAt: Date.now() })
@Greenheart
Greenheart / react-native-workaround.md
Last active August 21, 2025 14:58
Fix react-native builds on case sensitive file systems by linking headers

A workaround is to add the following to the post_install step in ios/Podfile. This way it will be automatically applied when you reinstall dependencies.

# Link headers to fix build on case sensitive file systems
# This will only be executed on case sensitive file systems where "pods" doesn't resolve to "Pods"
unless File.exist? "pods"
  # For files, create a symlink with `ln -s`
  system('cd Pods/Headers/Public; ln -s Protobuf protobuf')
  
  # For directories, create a symlink with `ln -sfh`
const queue = [];
const execute = () => {
const action = queue[0];
if (action) {
action().finally(() => {
queue.shift();
execute();
});
}
};
@Greenheart
Greenheart / reverseParentheses.js
Created February 27, 2018 12:07
My solution to a challenge from https://codefights.com
/*
Samuel Plumppu - 2018-02-27
You have a string s that consists of English letters, punctuation marks, whitespace characters, and brackets. It is guaranteed that the parentheses in s form a regular bracket sequence.
Your task is to reverse the strings contained in each pair of matching parentheses, starting from the innermost pair. The results string should not contain any parentheses.
Example
For string s = "a(bc)de", the output should be
@Greenheart
Greenheart / curriculum.md
Last active May 14, 2020 23:45
FCC InfoSec Curriculum Outline

The Applied Information Security Curriculum

Sections & their challenges:

1. What is Security? Why is it Important?

1.1 Introduction to Security

  • Security is a fundamental topic when creating sustainable software.
  • Protect your users, your organization or even yourself in mainly two ways:
  1. Protect their personal data
@Greenheart
Greenheart / cache.py
Created December 9, 2015 09:16
A decorator that works as a simple cache
from math import sqrt
def cache(F):
"""A simple cache decorator"""
cache = dict()
def wrapper(*args):
try:
return cache[args]
except KeyError:
# Result not in cache --> Calculate and store it