Skip to content

Instantly share code, notes, and snippets.

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

Steven Dwy Yoplitein

🔈
[screaming]
View GitHub Profile
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 <[email protected]>
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"
@Yoplitein
Yoplitein / async_websocket.js
Last active August 22, 2019 00:41
WebSocket API wrapped with promises
class AsyncWebSocket
{
constructor()
{
this.socket = null;
this.resolvers = [];
}
connect(remote)
{
@Yoplitein
Yoplitein / vec_project.d
Created May 12, 2019 03:51
gfm vector projection functions
import gfm.math;
Vec project(Vec: Vector!(T, N), T, size_t N)(Vec a, Vec b)
{
return b * scalarProject(a, b);
}
T scalarProject(Vec: Vector!(T, N), T, size_t N)(Vec a, Vec b)
{
import std.math: cos;
@Yoplitein
Yoplitein / construct_nested.d
Last active September 3, 2018 17:20
D function to easily construct nested structs
import std.traits;
Type construct(Type)(RepresentationTypeTuple!Type args)
{
static union Conv
{
Type obj;
struct { typeof(args) fields; }
}
@Yoplitein
Yoplitein / load-binary.js
Created August 26, 2018 08:47
Webpack loader for binary files (doesn't munge content by storing in strings)
const fs = require("fs");
module.exports = function(source)
{
const buffer = fs.readFileSync(this.resourcePath)
return `module.exports = Uint8Array.from([${buffer.toJSON().data}]);`;
}
@Yoplitein
Yoplitein / chunks.js
Created August 14, 2018 09:13
quick n' dirty function to split an array into fixed-length chunks
const chunks = (
(array, size) =>
Array.from(
Array(array.length / size),
(_, x) =>
Array.from(
Array(size),
(_, y) => array[size * x + y]
)
)
const cache = {};
const queue = [];
export function enqueueImage(path)
{
if(cache.hasOwnProperty(path))
return;
queue.push(path);
}
@Yoplitein
Yoplitein / shlex.d
Created June 26, 2018 10:09
Shell lexing function splitting strings on unquoted spaces
string[] shlex(string line)
{
string[] result;
string current;
char quoteChr = 0;
bool escape;
foreach(chr; line)
{
switch(chr)