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 / mappingutil.as
Last active March 25, 2022 22:14
Commands to aid in developing Sven Co-Op maps
void PluginInit()
{
g_Module.ScriptInfo.SetAuthor("Yoplitein");
g_Module.ScriptInfo.SetContactInfo("[email protected]");
}
void dbgDrawLine(const Vector&in pt1, const Vector&in pt2, uint16 lifetimeDs = 25, uint8 r = 255, uint8 g = 127, uint8 b = 0)
{
NetworkMessage msg(MSG_BROADCAST, NetworkMessages::SVC_TEMPENTITY, null);
msg.WriteByte(TE_LINE);
#!/usr/bin/env python3
import sys, os, argparse
import os.path as p
from functools import cmp_to_key
from locale import strcoll
exampleCommands = """
Typical operation:
$ %(prog)s $CLEAN/basedir >clean.txt
$ %(prog)s -c clean.txt $DIRTY/basedir >dirty.txt
@Yoplitein
Yoplitein / serv.d
Created January 26, 2022 05:49
Simple static fileserver
/++dub.sdl:
name "serv"
dependency "vibe-core" version="*"
dependency "vibe-d:http" version="~>0.9.4"
versions "VibeDefaultMain"
+/
import core.time: hours;
import std.algorithm: countUntil;
import std.exception: assumeUnique;
@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 November 10, 2024 02:11
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;