Skip to content

Instantly share code, notes, and snippets.

View toji's full-sized avatar
🔺
Can't see the triangles because they're behind him

Brandon Jones toji

🔺
Can't see the triangles because they're behind him
View GitHub Profile
@toji
toji / CMWCRand.js
Created June 15, 2012 17:50
Simple Javascript implementation of CMWC Psuedorandom algorithm
// This was basically ripped straight from http://en.wikipedia.org/wiki/Multiply-with-carry, just javscriptified.
var CMWCRand = function(seed) {
var i, PHI = 0x9e3779b9;
if(!seed) { seed = Date.now(); }
var Q = this.Q = new Uint32Array(4096);
this.c = 362436;
this.i = 4095;
Q[0] = seed;
@toji
toji / finalization-registry-test.js
Created December 30, 2022 03:58
FinalizationRegistry test
let nextId = 0;
const allocatedObjects = new Map();
const refLossTimes = new Map();
let reportCount = 0;
let reportTime = 0;
const finReg = new FinalizationRegistry((id) => {
const lossTime = performance.now() - refLossTimes.get(id);
refLossTimes.delete(id);
@toji
toji / triangle-collision.js
Created May 27, 2012 05:37
Javascript Swept-Sphere/Triangle Collision Detection
/*
* Copyright (c) 2012 Brandon Jones
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
@toji
toji / motion-controllers-example.js
Created January 23, 2020 18:36
Using motion-controllers.modules.js
// A barebones example of how to use the motion-controllers library and assets repository to load controller models in yor WebXR app
// This gist will not go into the details of how to set up a WebXR app (See https://immersive-web.github.io/webxr-samples/ for that)
// but will instead focus on the parts needed to find and load the appropriate controller.
// The motion-controllers library is small enough that it can easily be dropped into your own codebase if you wish, but loading it
// directly from a CDN like jsdelivr is an even easier route to getting up and running.
import { fetchProfile } from 'https://cdn.jsdelivr.net/npm/@webxr-input-profiles/motion-controllers@1.0.0/dist/motion-controllers.module.js';
// The assets package (https://www.npmjs.com/package/@webxr-input-profiles/assets) is larger, about 67Mb at time of writing,
// so it may be more beneficial to always use a CDN for it, especially since that will enable your app to pick up new controllers
@toji
toji / canvascapture.js
Created March 8, 2017 19:39
Canvas screenshot bookmarklet
javascript:(function()%7Bw%3Dwindow%3Bs%3D%22requestAnimationFrame%22%3Br%3Dw%5Bs%5D%3Bw%5Bs%5D%3Df%3D%3E%7Bw%5Bs%5D%3Dr%3Br(t%3D%3E%7Bf(t)%3Bl%20%3D%20document.querySelectorAll(%22canvas%22)%3Bfor%20(c%20of%20l)%20%7Bi%3Dnew%20Image()%3Bdocument.body.appendChild(i)%3Bi.src%3Dc.toDataURL()%3B%7D%7D)%3B%7D%7D)()
@toji
toji / gist:4a995452aa219e6f279ae4953e4f536c
Created October 22, 2016 03:51
Pixel XL supported extensions
XTENSIONS GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_EGL_sync GL_OES_vertex_half_float GL_OES_framebuffer_object GL_OES_rgb8_rgba8 GL_OES_compressed_ETC1_RGB8_texture GL_AMD_compressed_ATC_texture GL_KHR_texture_compression_astc_ldr GL_KHR_texture_compression_astc_hdr GL_OES_texture_compression_astc GL_OES_texture_npot GL_EXT_texture_filter_anisotropic GL_EXT_texture_format_BGRA8888 GL_OES_texture_3D GL_EXT_color_buffer_float GL_EXT_color_buffer_half_float GL_QCOM_alpha_test GL_OES_depth24 GL_OES_packed_depth_stencil GL_OES_depth_texture GL_OES_depth_texture_cube_map GL_EXT_sRGB GL_OES_texture_float GL_OES_texture_float_linear GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_EXT_texture_type_2_10_10_10_REV GL_EXT_texture_sRGB_decode GL_OES_element_index_uint GL_EXT_copy_image GL_EXT_geometry_shader GL_EXT_tessellation_shader GL_OES_texture_stencil8 GL_EXT_shader_io_blocks GL_OES_shader_image_atomic GL_OES_sample_variables GL_EXT_texture_border_clamp GL_EXT_multisampled_render_to_texture GL
@toji
toji / gist:66128d27662950e335de916bccbdb1ef
Last active April 15, 2016 18:01
Local python server that only allows connections from localhost
http() {
python -c "import BaseHTTPServer as bhs, SimpleHTTPServer as shs; bhs.HTTPServer(('127.0.0.1', $1), shs.SimpleHTTPRequestHandler).serve_forever()" &
}
(Called like: "http 8000")
### Keybase proof
I hereby claim:
* I am toji on github.
* I am toji (https://keybase.io/toji) on keybase.
* I have a public key whose fingerprint is 58B8 A064 C3EF E15A E7EA 976A 6B3C 9E34 B948 FFFC
To claim this, I am signing this object: