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 / pthread_once.c
Last active June 27, 2020 00:06
pthread_once emulation...
// best version
// would like to do CreateEvent in static initializer; but that's not a constant expression.
#define PTHREAD_ONCE_INIT { 0, 0 }
struct pthread_once {
HANDLE event;
volatile LONG inited;
};
typedef struct pthread_once pthread_once_t;
@d3x0r
d3x0r / Math.md
Last active June 19, 2020 03:33
a^2 + b^2 / c^2 <=M (=1)
 a^2 + b^2    (1)
 ---------
     c^2

Law of cosines, replace C in terms of A and B and Theta...

@d3x0r
d3x0r / PathTest.js
Created June 15, 2020 12:57
Test Graph
//const JSOX = require( "./jsox.js" );
let nodes = 0;
function node() {
nodes++;
this.id = nodes;
this.mates = [];
}
node.prototype.add = function(n) { this.mates.push(n) }
node.prototype.isEdge = function(x) { return this.mates.find(m=>m===x) }
@d3x0r
d3x0r / lnQuat.js
Last active June 11, 2020 04:30
compute initial log quaternion
// theta - angle in radians, d = {x, y, z } direction/unnormalized
function lnQuat( theta, d ){
// if no rotation, then nothing.
const dl = 1/Math.sqrt( d.x*d.x + d.y*d.y + d.z*d.z ); // 1/ d length = normalize d
const t = theta/2;
const ct2 = Math.cos( t ); // sqrt( 1/2(1 + cos theta)) - half angle subst
const st2 = Math.sin( t ); // sqrt( 1/2(1 - cos theta)) - half angle subst
const w = ct2;
const x = dl * d.x * st2;
@d3x0r
d3x0r / README.md
Last active June 1, 2020 09:55
Uniform length bit mask set (array of N bit items)

MASK SETS & FLAG SETS

MASK Sets are arrays of bit-fields of some bit-width (5, 3, ... ) they are set/returned as unsigned integer values. They are stored-in/accessed via a uint8_t which gives byte-offset calculations. they return their value as uintmax_t from the offset memory address directly; Some platforms(Arm) may SIGBUS because of wide offset accesses spanning word boundaries. This issue may be fixed by rounding, grabbing the word aligned values and shifting manually Declarataion/Instantiation of a mask set is done with MASKSET macro below

@d3x0r
d3x0r / ABOUT.md
Last active May 29, 2020 23:36
Object storage filesystem interface notes
@d3x0r
d3x0r / ComplexNumberTest.html
Last active May 26, 2020 03:17
Testing/Learning DualComplex numbers...
<HTML>
<BODY>
<CANVAS WIDTH=1000 height=1000 ID="testSurface" style="width:500px;height:500px"></CANVAS>
<p> for (A+Be)+(C+De)i
<p> for (<SPAN ID="Aval">A</SPAN>+<SPAN ID="Bval">A</SPAN>e)+(<SPAN ID="Cval">A</SPAN>+<SPAN ID="Dval">D</SPAN>e)i
<p> A <input type="range" min="-100" max="100" id="A"></input>
<p> B <input type="range" min="-100" max="100" id="B"></input>
<p> C <input type="range" min="-100" max="100" id="C"></input>
<p> D <input type="range" min="-100" max="100" id="D"></input>
@d3x0r
d3x0r / test.c
Last active May 18, 2020 00:50
Trust in the Optimizer ???
// test available here
// https://godbolt.org/z/EiXxwW
// This is the basic function
int upTree( int N ) {
int n;
for( n = 0; n < 32; n++ ) if( !(N&(1<<n)) ) break;
return (N & ~((0x1)<<(n+1))) | ( 0x01 << n );
}
@d3x0r
d3x0r / about.md
Last active May 10, 2020 08:55
Get the preferred folding direction for a quad; assuming 'best' is 'contains most inner space'

Determining the fold direction of a quadrilateral.

Fold Comparison

This function calculat(ed) the lengths of the diagonals of the quad p1 -> p3 and p2 -> p4, and resulted with a fold on the shortest of the diagonals. That works in some cases.

The function now calculates the nearest points on the two crossing lines of the quad and picks the line furthest along the normal passed in; this might be called 'the choice enclosing the most area'. The other

@d3x0r
d3x0r / Area-Perimeter-Edge-Ratios.jpg
Last active May 2, 2020 00:33
Compares triangle area vs perimeter
Area-Perimeter-Edge-Ratios.jpg