Skip to content

Instantly share code, notes, and snippets.

View Yoplitein's full-sized avatar
🔈
[screaming]

Steven Dwy Yoplitein

🔈
[screaming]
View GitHub Profile
@Yoplitein
Yoplitein / writefln.java
Created January 22, 2022 04:41
Scratchpad shortcut for System.out.printf
static void writefln(String fmt, Object... args)
{
System.out.println(
args.length == 0 ?
fmt :
String.format(fmt, args)
);
}
@Yoplitein
Yoplitein / set.d
Last active July 10, 2022 05:19
Basic set type using associative array
struct Set(T)
{
private import std.range: empty, enumerate, takeExactly;
private alias This = typeof(this);
private alias Nil = void[0]; // superior to empty struct, has .sizeof == 0
private Nil[T] set;
void add(T v)
{
@Yoplitein
Yoplitein / seq.d
Created November 10, 2021 19:32
Substructure-preserving seq type, like compile time tuples (AliasSeq)
alias id(alias x) = x;
struct seq(_xs...)
{
alias xs = _xs;
}
enum isSeq(alias x) = is(x: seq!xs, xs...);
template seqAppend(seqs...)
@Yoplitein
Yoplitein / httpserv.py
Last active January 15, 2022 18:53
Python HTTPServer with custom MIME types/headers
from http.server import HTTPServer, SimpleHTTPRequestHandler
from sys import argv
# teach the request handler about common MIME types
# fixes e.g. JS/WASM/etc. failing to load in some browsers
mimeTypes = {}
mimeTypes.update({
".html": "text/html",
".css": "text/css",
".json": "text/json",
/**
Sequentially schedules a series of CompletableFutures, i.e. earlier futures
must complete before subsequent futures are scheduled.
Assumes tasks is a stream which generates futures on demand.
A stream over an existing set of futures will not work as expected,
as they all will have already been scheduled.
*/
static CompletableFuture<Void> chainAsync(Stream<CompletableFuture<?>> tasks, Executor pool)
{
@Yoplitein
Yoplitein / minasync.py
Last active May 1, 2021 02:08
Minimal async event loop implementation in Python, largely intended for educational purposes
import collections, select, socket, sys, time, types
_transient_callbacks = collections.deque()
_timed_callbacks = []
_blocked_callbacks = []
_now = time.time()
_poll = select.epoll()
class _Sleep:
__slots__ = ["delay"]
@Yoplitein
Yoplitein / opensimplex2.rs
Last active December 29, 2022 00:39
Port of OpenSimplex to Rust
// Port of https://github.com/KdotJPG/OpenSimplex2/blob/e09a94744b3d69e4c58ce615445f18712cb50104/java/OpenSimplex2.java
#![allow(non_snake_case)]
/*!
K.jpg's OpenSimplex 2, faster variant
*/
use std::{num::Wrapping, sync::Once};
const PRIME_X: i64 = 0x5205402B9270C86F;
import std.traits;
To quantize(To, From)(From val)
if(isFloatingPoint!From && isIntegral!To && isSigned!To)
in(val >= -1.0 && val <= 1.0)
{
return cast(To)(
(To.max - To.min) // unsigned equivalent's .max
* ((val + 1) / 2) // val from [-1.0, 1.0] -> [0.0, 1.0]
+ To.min // shift back into signed value range
/++dub.sdl:
name "dnstest"
versions "VibeDefaultMain"
dependency "vibe-core" version="~>1.9.3"
+/
import std.socket: AddressFamily;
@Yoplitein
Yoplitein / PKGBUILD
Created August 29, 2019 06:16
Fixed emsdk pkgbuild
# Maintainer: Sanpi <sanpi+aur@homecomputing.fr>
pkgname=emsdk
pkgver=1.35
pkgrel=6
pkgdesc='The Emscripten SDK'
arch=('x86_64')
url='https://kripken.github.io/emscripten-site/'
license=('MIT')
depends=('python2' 'cmake')
source=("https://github.com/emscripten-core/emsdk/archive/master.zip"