Skip to content

Instantly share code, notes, and snippets.

View Jimbly's full-sized avatar

Jimb Esser Jimbly

View GitHub Profile
const { random, floor } = Math;
function tryit() {
let count = 0;
while (true) {
++count;
if (random() < 1 / (2000 - count)) {
return count;
}
}
}
@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%)
@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>
'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 / sky.js
Created April 18, 2019 22:33
Calcuate direction to sun based on time of day, latitude, axial tilt
const { cos, PI, sin } = Math;
let time = 5; // 0-24
const LAT = 45 * PI / 180;
const AXIAL_TILT = 23.5 * PI / 180;
const SOLAR_ORBIT = PI/2; // 0 - tilted towards the sun = summer solstice, PI = winter solstice
export function update() {
//////////////////////////////////////////////////////////////////////////
@Jimbly
Jimbly / gif_to_png_test.js
Created March 27, 2019 20:25
Testing gifwrap
const fs = require('fs');
const { GifCodec, BitmapImage } = require('./');
const Jimp = require('jimp');
let gif = fs.readFileSync('test/fixtures/rnaples-offsets-public.gif');
const codec = new GifCodec();
codec.decodeGif(gif).then((sourceGif) => {
const w = sourceGif.width;
const h = sourceGif.height;
@Jimbly
Jimbly / discord_rich_presence_test.c
Last active July 6, 2022 16:26
Testing discord SDK rich presence
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdint.h>
#include <stdio.h>
#include <assert.h>
#include "discord_game_sdk.h"
#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#include <string.h>
@Jimbly
Jimbly / Discord_PromoteToMaster.bat
Last active June 24, 2021 06:24
Discord Build Scripts
@echo off
@REM You Discord APP ID
SET APP_ID=451234567890123456
@REM Path to `dispatch` executable - if it's in your global path, just "dispatch" is fine.
SET DISPATCH=bin\dispatch
SETLOCAL ENABLEDELAYEDEXPANSION
pushd
@Jimbly
Jimbly / Discord_PromoteToMaster.bat
Last active March 20, 2019 14:44
Discord Build Scripts
@echo off
@REM You Discord APP ID
SET APP_ID=451234567890123456
@REM Path to `dispatch` executable - if it's in your global path, just "dispatch" is fine.
SET DISPATCH=bin\dispatch
SETLOCAL ENABLEDELAYEDEXPANSION
pushd
@Jimbly
Jimbly / asyncThreadPoolTest.cpp
Last active January 22, 2025 09:25
condition_variable deadlock
#define dbgprint(...) async_mem_log.print(__VA_ARGS__)
#include "utilUtils.h"
#include "utilRand.h"
#include "utilTime.h"
void asyncThreadPoolTest()
{
static auto one_ms = std::chrono::milliseconds(1);
int threads = 6;
std::vector< std::thread > workers;
int queued_tasks = 0;