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 / 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)
public import std.typecons: Yes, No;
struct ClampedNumber(NumericT)
{
import std.traits: isNumeric;
import std.typecons: Flag;
alias Numeric = NumericT;
alias TrackUnclamped = Flag!"trackUnclamped";
@Yoplitein
Yoplitein / compile-scss.js
Last active May 27, 2018 06:20
Use sass.js to compile SCSS stylesheets on-the-fly in the browser
/*
Compiles SCSS files on-the-fly in the browser. Minimal example:
<!DOCTYPE html>
<html>
<head>
<!-- Strips content from the head of imported SCSS files to calculate the logical path. Optional. -->
<meta name="scss-prefix" content="src">
<!-- Dependencies and this script. -->
@Yoplitein
Yoplitein / purify.lua
Created February 23, 2018 12:22
OpenComputers robot script to automatically purify stone and wood into their Botania living variants
local SLOT_PICKAXE = 14
local SLOT_AXE = 15
local SLOT_COAL = 16
local SLOT_LAST = 12
local SLEEP_DELAY = 30
local component = require("component")
local robot = require("robot")
local inv = component.inventory_controller
local geo = component.geolyzer