Skip to content

Instantly share code, notes, and snippets.

View edgarogh's full-sized avatar

Edgar Onghena edgarogh

View GitHub Profile

Keybase proof

I hereby claim:

  • I am edgarogh on github.
  • I am edgaronghena (https://keybase.io/edgaronghena) on keybase.
  • I have a public key ASC4Nz7OVdQrgtsL94sOHVs_gl3YODNQ-n-wzZ8juHq8Owo

To claim this, I am signing this object:

import { Req, Res } from "./express.types";
import { NextFunction } from "express";
/**
* This middleware adds two functions to the response object to make it easier
* to build a JSON API.
*/
export default function jsonApiMiddleware() {
return (req: Req, res: Res, next: NextFunction) => {
res.jsonData = (json) => {
{
"type": "object",
"additionalProperties": true,
"dependencies": {
"slot": {
"type": "object",
"required": [
"features"
],
"properties": {
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;
}
@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;
}
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
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;
/**
* @param {HTMLTableRowElement} tr
*/
const stringOfTr = (tr) => Array.from(tr.children)
.map((el) => JSON.stringify(el.innerText))
.join(',')
/**
* @param {HTMLTableElement} table
*/
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

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.