Skip to content

Instantly share code, notes, and snippets.

View edgarogh's full-sized avatar

Edgar Onghena edgarogh

View GitHub Profile

Wow Rust so great at optimizing stuff

Basically this

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum Orientation {
    North,
    East,
 South,

Minecraft worldgen – Reverse-engineering (in progress)

Terrain

The generation of terrain is done using Add*Layer classes, composed together. The following table comes from an old forge version where they're mapped as GenLayer*.

Layers return an int/i32 for every (x, z) that have different possible interpretations depending on the layer. For some, it's completely abstract, others return biome ids, others return other values. This is the second column.

Constructor parameters are the effective parameters that are used by the layer. base is the "base seed", used in the PRNG.

function o(p) {
const NO_ARG = Symbol();
p = p.toString().replace(/\(|\)/g, '');
try { var unary = new Function('a', `return (${p} a)`); } catch (e) { }
try { var binary = new Function('a', 'b', `return (a ${p} b)`); } catch (e) { }
return (a, b = NO_ARG) => (b != NO_ARG) ? binary(a, b) : unary(a);
}
// Usage:
// o`+`(1, 2) = 3
/**
* @param {HTMLTableRowElement} tr
*/
const stringOfTr = (tr) => Array.from(tr.children)
.map((el) => JSON.stringify(el.innerText))
.join(',')
/**
* @param {HTMLTableElement} table
*/
const { readFileSync, writeFileSync } = require('fs');
const lines = readFileSync('/dev/stdin', 'utf8').split('\n');
/**
* @param {string} line
*/
function indent(line) {
try {
const indent = /^( *).*$/g.exec(line)[1].length;
@edgarogh
edgarogh / README.md
Created March 2, 2020 19:34
Algebraic Data Type TypeScript implementation -- c.f. OCaml / Rust / ...

Algebraic Data Type TypeScript implementation

  • ADT "constructor"
  • Very elementary type-safe function-based "match"
This file has been truncated, but you can view the full file.
echo "H4sIAEn/rFsAA3R9BVhUz/f33WXBBRGXFMRYSspALOwFSVFcg1BEV0BMFFEUC5ZQKXFtDBADO1CxA2xUUFDEwMDAbgzs98Cc+f2/l5fheT7M3rOzc2fOnJozc3dj3Qa4CwUCjv6pcX242iv5cbO6axnSS2Z5/q+OjHPiNOF/K64lpwHX6v+pV7+sEfBL8f/uw3EigJOQXNcvW3D8UvCfUp1j/w2o6cMrOU76v8/V9lX8g9DFP0bxSuV8zbpSlaTN+5wQPyfX6lt3LdcazStl2F9a0vGJEMOQXr905filCEt51YzQ2tehjt3rruuXvb5xvJJ+bjB8TqMBfrD+JFgOwfux+FJjxPFKOg8dJk8I7tq5w+TQdpMnTImKbhft1LVd187tp09t71jXJwnW9fDxratP+SjFPhtwRAZq37dW2rvujlPrar5/u1/HvEMzVm9+d/QjvPlKQBrRqf3MnbTBjUUDxZxcJOM2JbnHJ8kkIs6KkxSIxWbZUEEZL4kTmtfeSlcudpEoJQaaMsFGoczcWJLMXRwqdI4TNRbtGMxJFifFmakp19jpaqwYLJBrcWItgRK6q1krVmIVFyfj/ogqCwQGEk4g0eIMXRI5F5kgnXMSBARIlf0knlKxhEs0FSuVUk5oLNSTKqVSSxelVCgQcYvVbcSctG5KZEqBhkwuEyQVchGcsbMWDERTVvuGlp5QKdbWBU6IPkkkQuUIQXypWoIcFAY+Z84lGcg4Q3Ec11bMiQ3sNqosFkyMU6UUGAiEUKOAk2ZLz4gkUs5ZLMr19FzBCdMkcqlSUyzSS5KOhzZ1ZRIl59DGwGU2J5Uu0hWLgX1CPWW8lFMppWJOZiCRSCVKV6VI0zKOWxBtqYyTlDvoca7KsPUioXQhzI5LgFDpLOrEKTillrkgUSRy1nCVO5xJdxGViBr3s9A0VsqHKJWJYt0CmGJhIjBJJRNLBPHq7WULlUJlnUwKxKIQG22JSKar3uaAjZssiRPruUhlEk7OKZNklUqHbInEsx
@edgarogh
edgarogh / ScopedState.tsx
Created October 13, 2019 16:03
Scoped useState in React - Share useState values between a component's children - Never ever tested, probably doesn't even work
import React, { createContext, Dispatch, ReactNode, SetStateAction, useContext, useState } from 'react';
export interface ScopeValue<V> {
value: V;
setValue(value: V): void;
}
export interface Scope {
(props: { children: ReactNode }): JSX.Element;
}
@edgarogh
edgarogh / spotifyPause.md
Last active February 1, 2024 18:12
Start Spotify w/ Play/Pause key

spotifyPause.sh

This short script allows the Play/Pause keyboard key to be also used to start Spotify (or any player of your choice with a bit of tweaking). I'm using Cinnamon's settings to reassign keys, but other distros may also have this feature

Setup

  • Download/copy the script somewhere on your system
  • chmod +x ./spotifyPause.sh to make it runnable
  • Add the new keybinding [Cinnamon only]
  • Open cinnamon-settings keyboard (you can search for "Keyboard" in the start menu search if you don't like terminals)
type MessageDefs = {
// This whole object will be passed as the first argument of the socket.io packet
'user.get': {
id: string;
// Except for the optional `ack`, which itself represents the first argument of the acknowledgment
ack: User;
}