Skip to content

Instantly share code, notes, and snippets.

View JTRNS's full-sized avatar
💤

JT JTRNS

💤
  • The Netherlands
  • 10:12 (UTC +02:00)
View GitHub Profile
@JTRNS
JTRNS / parse_markdown.ts
Created August 3, 2023 19:25
GitHub Flavoured Markdown Parsing in Deno
import { unified } from "https://esm.sh/[email protected]";
import remarkParse from "https://esm.sh/[email protected]";
import remarkFrontmatter from "https://esm.sh/[email protected]";
import remarkGfm from "https://esm.sh/[email protected]";
import remarkRehype from "https://esm.sh/[email protected]";
import rehypeStringify from "https://esm.sh/[email protected]";
import rehypeSlug from "https://esm.sh/[email protected]";
import rehypeAutolinkHeadings from "https://esm.sh/[email protected]";
import remarkGemoji from "https://esm.sh/[email protected]";
import rehypeStarryNight from "https://esm.sh/@microflash/[email protected]";
@JTRNS
JTRNS / router.ts
Last active July 19, 2023 22:57
URLPattern Router with basic pattern to parameter type inference
import type { ConnInfo, Handler } from "https://deno.land/[email protected]/http/server.ts";
type RemoveModifier<Pattern> = Pattern extends `${infer P}?` ? P
: Pattern;
type RemoveMatchingRule<Pattern> = Pattern extends `${infer P}(${infer R})` ? P
: Pattern;
type ExtractGroupName<Pattern> = RemoveModifier<RemoveMatchingRule<Pattern>>;
type PatternParamValue<Key> = Key extends `${infer PatternString}?`
? string | undefined
@JTRNS
JTRNS / EventEmitter.ts
Created July 18, 2023 20:24
EventEmitter
/**
* A generic class that allows for the creation of events and listeners.
*
* @template T - An object type that defines the events and their data types.
*/
export default class EventEmitter<T> {
private events: { [K in keyof T]: Array<(data: T[K]) => void> } = {} as unknown as { [K in keyof T]: Array<(data: T[K]) => void> };
/**
* Adds a listener to an event.
@JTRNS
JTRNS / input-area.css
Created June 30, 2023 15:36
InputArea Component
div[data-autogrow]:has(textarea) {
display: grid;
}
div[data-autogrow]:has(textarea)::after {
content: attr(data-autogrow) ' ';
white-space: pre-wrap;
visibility: hidden;
}
@JTRNS
JTRNS / first-names.txt
Created February 11, 2023 09:06
A list of 200 common first names
James
Mary
Robert
Patricia
John
Jennifer
Michael
Linda
David
Elizabeth
@JTRNS
JTRNS / jobs.js
Created February 11, 2023 07:48
An array of occupations
const jobs = [
'Genetic Counselor',
'Mathematician',
'University Professor',
'Occupational Therapist',
'Statistician',
'Medical Services Manager',
'Data Scientist',
'Information Security Analyst',
'Operations Research Analyst',
@JTRNS
JTRNS / tailwind-colours.css
Created November 6, 2022 09:56
Tailwind colours as CSS custom properties
:root {
--slate-50: #f8fafc;
--slate-100: #f1f5f9;
--slate-200: #e2e8f0;
--slate-300: #cbd5e1;
--slate-400: #94a3b8;
--slate-500: #64748b;
--slate-600: #475569;
--slate-700: #334155;
--slate-800: #1e293b;
@JTRNS
JTRNS / rsa-keygen.ts
Created September 3, 2022 08:43
Generate and export RSA-OAEP encryption keys from the browser.
function encodeMessage(message: string) {
const enc = new TextEncoder();
return enc.encode(message);
}
function decodeMessage(buffer: ArrayBuffer) {
const dec = new TextDecoder();
return dec.decode(buffer);
}
@JTRNS
JTRNS / SmartJoin.py
Created April 7, 2022 08:52
Create vertex groups for each mesh before joining objects in Blender
bl_info = {
"name": "Smart Join",
"author": "Jeroen Trines",
"version": (1, 0),
"blender": (3, 1, 0),
"location": "View3D > Object > Smart Join",
"description": "Create vertex groups for each mesh before joining objects in Blender",
"warning": "",
"doc_url": "",
"category": "Object",
@JTRNS
JTRNS / blingbling.js
Created September 25, 2021 11:15
A more shiny variation of the popular bling dot js
/* blingbling.js */
window.$ = document.querySelector.bind(document);
window.$$ = document.querySelectorAll.bind(document);
HTMLElement.prototype.$ = function (selector) {
return this.querySelector(selector);
}
HTMLElement.prototype.$$ = function (selector) {