Skip to content

Instantly share code, notes, and snippets.

View Tymek's full-sized avatar

Tymoteusz Czech Tymek

View GitHub Profile
@Tymek
Tymek / indexed.ts
Last active September 16, 2024 19:15
TS type with indexed object and version property
// TypeScript type for an object with 1 property that is required but different then other properties
type Todo = { id: string; text: string; done: boolean }
type Table = Array<Record<string, unknown>>
type Schema = (
| {
[key: string]: Table
}
@Tymek
Tymek / imgsize.ts
Created August 21, 2024 17:20
ts image size handler
import http from 'node:http'
import https from 'node:https'
import sizeOf from 'image-size'
const MAX_REDIRECTS = Number.parseInt(
process.env.IMGMETA_MAX_REDIRECTS || '10',
10,
)
const ALLOWED_DOMAINS = process.env.IMGMETA_ALLOWED_DOMAINS || '*'
const TIMEOUT =
type CacheType<T> = {
has: (key: string) => boolean;
get: (key: string) => T | undefined;
set: (key: string, result: T, now?: number) => void;
clear?: () => void;
};
const createCache = <T>(maxAge = 60_000): CacheType<T> => {
const values = new Map<string, T>();
const expiry = new Map<string, number>();
@Tymek
Tymek / gist:170c5e6f14f580c069a0d1bc71419095
Created January 16, 2023 19:13
ZSH - list colors for p10k (powerlevel10k)
for i in {0..255}; do print -Pn ' '%K{$i} %k%F{$i}${(l:3::0:)i}%f ' ' ${${(M)$((i%6)):#3}:+$'\n'}; done
version: '3'
services:
mysql:
image: docker.io/bitnami/mysql:8.0
volumes:
- ./mysql_data:/bitnami/mysql
environment:
- ALLOW_EMPTY_PASSWORD=yes
- MYSQL_USER=bn_wordpress
- MYSQL_DATABASE=bitnami_wordpress
@Tymek
Tymek / seed.ts
Last active May 25, 2022 08:45
Unleash features - seed db
const readline = require("readline");
const { default: faker } = require("@faker-js/faker");
require("isomorphic-fetch");
const API_URL = "http://localhost:4242/api/admin/projects/default/features";
const API_KEY = "<YOUR_ADMIN_TOKEN>";
const pastDate = (min = 0) => new Date(Date.now() - 1000 * 60 * min);
const FgGreen = "\x1b[32m";
import { compile } from 'svelte/compiler'
/**
* @returns {import('vite').Plugin}
*/
const vitePluginSvelteDocs = () => {
const virtualModuleId = '@virtual:svelte-docs'
return {
name: 'vite-plugin-svelte-docs',
@Tymek
Tymek / vercel.json
Created April 16, 2021 07:46
Vercel Opt-out from Google's FLoC Network
{
"headers": [
{
"source": "/(.*)",
"headers": [
{
"key": "Permissions-Policy",
"value": "interest-cohort=()"
}
]
@Tymek
Tymek / useNavigationLock.ts
Last active May 25, 2023 22:38
Next.js block navigation on unsaved changes
import { useEffect, useState } from 'react';
import { useRouter } from 'next/router';
/** Ask for confirmation before changing page or leaving site.
*
* @see https://git.io/JOskG
*/
const useNavigationLock = (
isEnabled = true,
warningText = 'You have unsaved changes – are you sure you wish to leave this page?',
@Tymek
Tymek / headless-pi.sh
Last active March 8, 2021 20:21
Headless Raspbian setup – WiFi and SSH
#!/bin/bash
clear
echo ""
echo -e "\e[44mHEADLESS RASPBIAN\e[0m"
echo "WiFi & SSH setup"
echo ""
echo "Available partitions:"
lsblk -e7
echo ""