Skip to content

Instantly share code, notes, and snippets.

View edgarogh's full-sized avatar

Edgar Onghena edgarogh

View GitHub Profile
// GPL-3.0 Edgar Onghena
// Last mod: Sun 06 Dec 2020 08∶49∶15 PM CET
trait AllValues: Sized {
fn get_all_values() -> Vec<Self>;
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
enum Direction {
Devant = 0b0001isize,
@edgarogh
edgarogh / async_diesel.rs
Created April 13, 2021 12:05
[MIT License 2021 Edgar ONGHENA] Extension trait to use Diesel ORM asynchronously with rocket 0.5 and rocket_contrib 0.5
/* Copyright Edgar ONGHENA 2021. All Rights Reserved.
This file is licensed under the MIT License.
License text available at https://opensource.org/licenses/MIT
This header may be removed if the terms of the license are still respected
(including, but not limited to, giving proper credit somewhere else) */
use diesel::dsl::Limit;
use diesel::query_dsl::limit_dsl::LimitDsl;
use diesel::query_dsl::LoadQuery;
use diesel::{QueryResult, RunQueryDsl};

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 / 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)