Skip to content

Instantly share code, notes, and snippets.

View d3x0r's full-sized avatar

Jim B d3x0r

  • Las Vegas
View GitHub Profile
@d3x0r
d3x0r / pcg.js
Last active April 3, 2018 22:26
Javascript port of PCG RNG
// ported from https://github.com/imneme/pcg-c
// http://www.pcg-random.org/using-pcg.html
const _UINTS = 4;
// records
// : 2 : Done in 1321 /ms 75700.2271006813 151400.4542013626
// : 4 : Done in 3538 /ms 28264.55624646693 113058.22498586772(kbpms)
// : 8 : Done in 5671 /ms 17633.574325515783 141068.59460412627
//
@d3x0r
d3x0r / slowdown.js
Created April 6, 2018 22:02
Simplified, Slow version that causes deoptimization
function pcg_setseq_128_srandom_r()
{
//const state = new Uint32Array([0,0,0,0,0,0,0,0]);
const state = [0,0,0,0,0,0,0,0];
const b = [ 0x7F2D, 0x4C95, 0xF42D, 0x5851 ];
const c = [ 0x7F2D, 0x4C95, 0xF42D, 0x5851 ];
const rng = {
state: new Uint32Array([0,0,0,0,0,0,0,0]),
@d3x0r
d3x0r / PlaySounds.js
Created April 11, 2018 07:23
promisfy this?
var lame = require( "lame" )
, Speaker = require('speaker')
var sack = require( "../node_modules/sack-gui" )
var disk = sack.Volume();
["Click-SoundBible.com-1387633738.mp3"
,"Cracking Chest Open-SoundBible.com-2009973824.mp3"
@d3x0r
d3x0r / README.md
Last active April 11, 2018 22:53
Resource; index.html, and server testWssHttp.js

with node > 7

npm install sack.vfs
node testWssHttps.js

opens a server on port 8080, and 8081

#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef struct process_node {
int key;
char process_command[64];
@d3x0r
d3x0r / index.html
Created November 6, 2018 04:22
Service Worker Fetch Handler
<HTML>
<HEAD>
</HEAD>
<BODY>
<DIV class="fullpage">
<IFrame class="fullpage"ID="Login"></IFRAME>
</DIV>
<DIV class="fullpage" style="display:none;">
<IFrame class="fullpage"ID="App"></IFRAME>
</DIV>
@d3x0r
d3x0r / UTF16ToUTF8.c
Last active November 7, 2018 10:35
A routine which will convert utf-16 to utf8 - assumes utf-16 is valid.
#include <wchar.h>
#include <malloc.h>
#include <stdint.h>
// returns pointer to utf8 string;
// the result must be released with free().
//
// length is in count of wide characters passed.
struct malloc_chunk_tag
{
uint16_t dwOwners; // if 0 - block is free
uintptr_t dwSize; // limited to allocating 4 billion bytes...
uint16_t alignment; // this is additional to subtract to get back to start (aligned allocate)
uint16_t to_chunk_start; // this is additional to subtract to get back to start (aligned allocate)
uint8_t byData[1]; // uint8_t is the smallest valid datatype could be _0
};
typedef struct malloc_chunk_tag MALLOC_CHUNK;
@d3x0r
d3x0r / parse-args.c
Created November 16, 2018 17:38
Parses a string into seprate arguments similar to those recieved by main( int argc, char **argv );
#include <stdlib.h>
#include <string.h>
// strdup isn't 'standard'.
//extern char *strdup(char*);
/*
* usage:
* function f( char *argString ) {
* int argc;
@d3x0r
d3x0r / svgToCanvas.html
Last active November 17, 2018 22:51
Draw an SVG Image on a canvas.
<HTML>
<meta charset="utf-8"/>
<BODY>
</BODY>
<SCRIPT>
function makeNode( extra ) {
var svg = document.createElementNS( "http://www.w3.org/2000/svg","svg" );