Skip to content

Instantly share code, notes, and snippets.

Avatar
🦀
Carcinisation in progress, please be patient...

Michal Grňo m93a

🦀
Carcinisation in progress, please be patient...
View GitHub Profile
@m93a
m93a / nanboxing.ts
Last active May 19, 2023 18:43
Save data into a NaN (only works in V8)
View nanboxing.ts
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 May 19, 2023 13:07
View mag.md

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.

View meditation on effects.md

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
View hasDef.ts
/**
* 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;
@m93a
m93a / stores_toolkit.md
Last active February 22, 2023 18:24
Svelte Stores Toolkit
View stores_toolkit.md
View svelte-grid.d.ts
// type definitions for the NPM package svelte-grid
declare module "svelte-grid" {
import type { SvelteComponentTyped } from "svelte";
export interface Size {
w: number;
h: number;
}
@m93a
m93a / example.svelte
Last active May 18, 2022 19:57
Code snippets for Svelte projects
View example.svelte
<script lang="ts">
let foo = 1;
let lastFoo: typeof foo;
$: {
fooChanged(foo, lastFoo);
lastFoo = foo;
}
function fooChanged(current: typeof foo, previous?: typeof foo) {
console.log(current, previous);
@m93a
m93a / overview.md
Last active May 8, 2022 17:20
Replicant Language
View overview.md

Variables and scopes

You can define a variable in the current scope using a let keyword and an equal sign.

> let foo = 42
> echo! foo
42
View NMAF038 Pokročilé partie z teorie grup pro fyziky.md

Pokročilé partie z teorie grup

Obsah

  1. Základy variet ($C^\infty$), topologie a teorie míry
  2. Lieovy grupy: definice věty a věty o implicitních funkcích
  3. Základy teorie reprezentací
  4. Konečněrozměrné reprezentace $\mathrm O(n)$ a $\mathrm{SU}(2)$
  5. Cliffordovy algebry a spin-grupy
  6. Superprostory a superalgebry
  7. Reprezentace polopřímých součinů: Wignerova klasifikace částic
  8. Heisenbergova grupa a Stone-von Neumannova věta
@m93a
m93a / gunpowder.md
Last active February 10, 2023 12:50
View gunpowder.md

Gunpowder

A fictional language inspired by TypeScript, Rust, FrTime, CoffeeScript, Svelte and Dart, that compiles to JavaScript, WebAssembly and Rust and that I will totally make once I have the time.

Runtime constants

Like Rust, Gunpowder uses runtime constants by default, instead of variables. You can declare them using the let keyword.

let a = 4;
a = 5; // err

Shadowing is fully supported.