Skip to content

Instantly share code, notes, and snippets.

View m93a's full-sized avatar
🥔
omw to start a commune

Michal m93a

🥔
omw to start a commune
View GitHub Profile
javascript:if(location.hostname=='prehrajto.cz'||location.hostname=='prehraj.to'){var a=document.createElement('a');if(confirm('OK = Stáhnout\nZrušit = Sledovat nyní')){a.setAttribute('download',document.querySelector('.video-detail-title').textContent+'.mp4');};a.setAttribute('href',(a0=document.querySelector('.jw-video'))?a0.getAttribute(%27src%27):document.querySelector(%27.video-wrap meta[itemprop="contentUrl"]%27).getAttribute(%27content%27));a.textContent=%27download%27;document.body.appendChild(a);a.click();}else if(confirm(%27Přesměrovat na Přehraj.to?%27)){window.location = %27http://prehrajto.cz%27;}
export type nullish = undefined | null;
export type AnyConstructor = new (...x: any) => any;
export function isA(x: unknown, type: "string"): x is string;
export function isA(x: unknown, type: "number"): x is number;
export function isA(x: unknown, type: "bigint"): x is bigint;
export function isA(x: unknown, type: "boolean"): x is boolean;
export function isA(x: unknown, type: "symbol"): x is symbol;
export function isA(x: unknown, type: "undefined"): x is undefined;
export function isA(x: unknown, type: "object"): x is object | null;
@m93a
m93a / timey.ts
Last active January 25, 2024 16:04
const formatDate = (d: Date) =>
d.getFullYear() +
"-" +
(d.getMonth() + 1).toString().padStart(2, "0") +
"-" +
d.getDate().toString().padStart(2, "0");
const isSameDate = (a: Date, b: Date) => formatDate(a) === formatDate(b);
interface DateRange {
@m93a
m93a / en.srt
Created October 16, 2023 13:32
Subtitles for BadEmpanada's video Some People Push Back in Palestine
asdf
@m93a
m93a / map_renderer.md
Last active September 30, 2023 22:40
How to create a map renderer

Creating a map renderer from scratch

These are my notes on how I could implement a vector map renderer similar to the one Mapy.cz use for their mobile app.

1. Source map data

1b. Source elevation data

@m93a
m93a / zvireci-hashe.ts
Created June 7, 2023 14:40
Generování hashů ve tvaru (přídavné jméno)-(zvíře)
export const pickRandomItem = <T>(arr: T[]): T => {
if (arr.length === 0) throw new TypeError('Cannot pick item from empty array');
return arr[Math.floor(Math.random() * arr.length)];
};
enum Rod {
Muzsky = 0,
Stredni = 1,
Zensky = 2
}
@m93a
m93a / nanboxing.ts
Last active May 19, 2023 18:43
Save data into a NaN (only works in V8)
const MSB = 1 << 7;
const nanbox = (message: string): number => {
const float = new Float32Array(1);
const bytes = new Uint8Array(float.buffer);
bytes[3] = ~MSB + (MSB & message.charCodeAt(0));
bytes[2] = MSB + (~MSB & message.charCodeAt(0));
bytes[1] = message.charCodeAt(1);
bytes[0] = message.charCodeAt(2);
@m93a
m93a / mag.md
Last active October 24, 2023 19:44

Mag

Tired? Mag it! Down? Mag time! Liver damage? MAXIMUM MAG! You’re about to become a magnesium-based lifeform. The age of the primitive carbon-man is done.DE

Tier 1

These features are the core of Mag, and need to be implemented to make it usable.

Intro

The academic language Effekt has so-called effects. They are a generalization of throw, yield and await which allow an executed function to "stop" in the middle of its execution, and then optionally continue. This would be a great feature for Gunpowder.

Categorization

  • throw<E>: E → never

    • interrupts with any value – it will act as the error
    • never resumes
    • not consuming is equivalent to a try{} block
  • (suffix after function call) ?: T / throw → T

@m93a
m93a / hasDef.ts
Last active January 2, 2023 12:17
a TypeScript type guard that checks whether an object (whose type is a discriminated union) contains a certain property and its value is not undefined
/**
* Checks if object `obj` has a property `key` and its value is not undefined.
*/
export const hasDef = <T, K extends string | number | symbol>(
obj: T,
key: K
): obj is T & {
[k in K]: Required<Extract<T, { readonly [k in K]?: unknown }>>[K];
} => key in (obj as any) && (obj as any).key !== undefined;