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 / cfpackdl.py
Created September 17, 2023 20:04
Script to download CurseForge modpacks
from urllib import request
import io
import json
import os
import sys
import zipfile
def main():
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <pack zip URL>")
#![feature(return_position_impl_trait_in_trait)]
trait ComposableOnce<From, To>: FnOnce(From) -> To {
fn compose_once<Final>(self, rhs: impl FnOnce(To) -> Final) -> impl FnOnce(From) -> Final;
}
impl<From, To, Func: FnOnce(From) -> To> ComposableOnce<From, To> for Func {
fn compose_once<Final>(self, rhs: impl FnOnce(To) -> Final) -> impl FnOnce(From) -> Final {
move |v| rhs(self(v))
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct VarInt(u128);
macro_rules! conversions {
($($ty:ty => $unsigned:ty, $signed:expr);*;) => {$(
impl From<$ty> for VarInt {
fn from(v: $ty) -> Self {
let raw = if $signed {
// rotate sign bit to front, and flip value bits if negative
// this encodes small absolute values in the fewest bytes possible
#[derive(Clone, Debug)]
pub struct SurrogateString(String);
impl SurrogateString {
unsafe fn inner(&self) -> &String {
&self.0
}
unsafe fn inner_mut(&mut self) -> &mut String {
&mut self.0
@Yoplitein
Yoplitein / gist:f4b671a2ec70c9e743fa
Created August 25, 2014 15:00
Dark theme for cgit
body {
background-color: #272822;
}
div#cgit {
padding: 0em;
margin: 0em;
font-family: sans-serif;
font-size: 10pt;
color: white;
@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;
@Yoplitein
Yoplitein / counting_alloc.rs
Last active October 10, 2022 06:55
GlobalAllocator that tracks number of allocated bytes
use std::sync::atomic::{AtomicUsize, Ordering};
use std::alloc;
#[global_allocator]
static COUNTING_ALLOC: CountingAlloc = CountingAlloc::new();
struct CountingAlloc {
used: AtomicUsize,
}
@Yoplitein
Yoplitein / builder.d
Created September 5, 2022 22:32
Generic implementation of the builder pattern for any struct/class (though only for public fields)
auto builder(T)(T inst = T.init)
{
enum isClass = is(T == class);
static assert(is(T == struct) || isClass, "builder!T can only build structs and classes");
static if(isClass)
if(inst is null) inst = new T;
static struct Builder
{
@Yoplitein
Yoplitein / ringbuffer.d
Last active August 11, 2022 04:51
Fixed-capacity ring buffer type
struct RingBuffer(T, size_t _capacity)
{
import core.lifetime: move;
private
{
T[capacity] buffer;
size_t read;
size_t write;
size_t len; // keep it simple :^)
@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)
{