Skip to content

Instantly share code, notes, and snippets.

View Jimbly's full-sized avatar

Jimb Esser Jimbly

View GitHub Profile
'use strict';
// Use path PATH=bin\;F:\Python27\;F:\Python27\Scripts;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;F:\bin
// Run with node stdio.js < A-small.in
const assert = require('assert');
const fs = require('fs');
function err() {
process.stderr.write(Array.prototype.join.call(arguments, ' ') + '\n');
}
@Jimbly
Jimbly / pointer_lock_wrap_safari.html
Last active July 11, 2019 21:41
Deal with pointerlockerror on Safari
<!DOCTYPE html>
<!-- Modified version of pointer lock code to lock on click from the main loop, works on Safari -->
<html lang="en"><head>
<title>Pointer Lock Test</title>
</head>
<body onload="startup()">
<div id="status-element" style="background-color: #FEE; white-space: pre-wrap;">dragx=0, dragy=0
double clicks: 0</div>
<script>
@Jimbly
Jimbly / packet_perf.js
Last active March 21, 2020 18:07
Performance comparison of raw buffer access
/* eslint no-bitwise:off */
/* Results:
Plain DataView / Native mapped Buffers
Node 0.4.12 / 5276ms (not quite the same test)
Node 0.6.21 8275ms / 1070ms (12%) (not quite the same test)
Node 0.8.28 6739ms / 986ms (14%) (not quite the same test)
Node v4.8.2: 4500ms / 1939ms (43%)
Node v6.9.1: 3900ms / 1090ms (28%)
Node v8.11.3: 2111ms / 2928ms (138%)
Node v10.16.0: 2200ms / 260ms (12%)
const { random, floor } = Math;
function tryit() {
let count = 0;
while (true) {
++count;
if (random() < 1 / (2000 - count)) {
return count;
}
}
}
const { round, floor, ceil } = Math;
let correct = [0,0,0];
function test(dpr, dim) {
let clientWidth = round(dim / dpr);
let scaled = clientWidth * dpr;
if (round(scaled) === dim) {
correct[0]++;
}
if (floor(scaled) === dim) {
correct[1]++;
@Jimbly
Jimbly / in.js
Last active January 18, 2021 17:03
Uglify sourcemap test
"use strict";
var _window$foo = window.foo,
a = _window$foo[0],
b = _window$foo[1];
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluLmpzIl0sIm5hbWVzIjpbIndpbmRvdyIsImZvbyIsImEiLCJiIl0sIm1hcHBpbmdzIjoiOztrQkFBYUEsTUFBTSxDQUFDQyxHO0lBQWZDLEM7SUFBR0MsQyIsImZpbGUiOiJpbi5qcyIsInNvdXJjZXNDb250ZW50IjpbImxldCBbYSwgYl0gPSB3aW5kb3cuZm9vO1xuIl19
@Jimbly
Jimbly / WindowStyles.lua
Created June 1, 2021 03:25
Modifying Window Styles in Automato
dofile("common.inc");
dofile("screen_reader_common.inc");
dofile("ui_utils.inc");
local styles = {
WS_BORDER=0x00800000,
WS_DLGFRAME=0x00400000,
-- WS_CAPTION=0x00C00000, WS_BORDER | WS_DLGFRAME
-- WS_CHILD=0x40000000, not relevant
@Jimbly
Jimbly / explore_to.cpp
Created June 20, 2022 23:22
libGLOV exploreTo implementation example
// Path to directory, or file, but not to a "." (e.g. c:/foo/.)
void exploreTo(const char *localfname) {
wchar_t *path = utf8ToWideAlloc(localfname);
for (wchar_t *s = path; *s; ++s)
if (*s == '/')
*s = '\\';
// Remove trailing backslash, FindFirst will fail
if (path[wcslen(path) - 1] == '\\') {
path[wcslen(path) - 1] = '\0';
}
@Jimbly
Jimbly / EntityManagerHierarchy.ts
Created September 27, 2022 15:31
Multiple inheritence class hierarchy for an entity manager
/**
* Conceptual/Code-time hierarchy:
*
* Sever Code Common Code Client Code
*
*
* EntityGameServer EntityGameClient
* Game Code | \ / |
* | EntityGameCommon |
* | | |
@Jimbly
Jimbly / allowDeclareFields.ts
Last active October 19, 2022 21:35
allowDeclareFields example and commentary
// The setup: I have an Entity class hierarchy for server/common/client, and each entity has
// a reference to an entity_manager, which should be templated to the appropriate type so
// that an entity getting other entities from the manager always get the correct type of
// entity back.
// The common code:
interface EntityManager<Entity extends EntityCommon = EntityCommon> {
entities: Partial<Record<number, Entity>>;
}