Skip to content

Instantly share code, notes, and snippets.

View lancejpollard's full-sized avatar
😍
Lots of coding

Lance Pollard lancejpollard

😍
Lots of coding
View GitHub Profile
@lancejpollard
lancejpollard / generate.js
Last active April 20, 2022 08:19
Generate count leading zeroes table
function makeLeadingZeroTable() {
let i = 0
const table = new Uint8Array(256)
while (i < 256) {
let count = 8
let index = i
while (index > 0) {
index = (index / 2) | 0
count--
}
/** By_Sean_Eron_Anderson seander@cs.stanford.edu */
#include <stdbool.h>
#include <stdint.h>
#include <endian.h>
#define CHAR_BIT 8
void Compute_the_sign_of_an_integer() {
/*Compute the sign of an integer*/
@lancejpollard
lancejpollard / logic-gates.js
Created April 17, 2022 03:34 — forked from ianstarz/logic-gates.js
Build up all the logic gates from nand in js
const logicGates = {
nand (a, b) { return !(a && b); },
not (a) { return this.nand (a, a); },
and (a, b) { return this.not (this.nand (a, b)); },
or (a, b) { return this.nand (this.not (a), this.not(b)); },
nor (a, b) { return this.not (this.or (a, b)); },
xor (a, b) { return this.and (this.nand (a, b), this.or(a, b)); },
xnor (a, b) { return this.not (this.xor (a, b)); }
};
@lancejpollard
lancejpollard / unixtime.c
Created April 15, 2022 18:16 — forked from t3hk0d3/unixtime.c
Naive implementation of Unix Timestamp to DateTime conversion
typedef struct _DateTime {
uint16_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
} DateTime;
uint8_t monthDays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
@lancejpollard
lancejpollard / ANSI.md
Created April 11, 2022 22:58 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@lancejpollard
lancejpollard / BTree.js
Created February 12, 2022 03:14 — forked from sebastianfdez/BTree.js
FINAL COMPLETE BTREE CLASS
export class BTreeNode {
constructor(isLeaf) {
/**
* @type {number[]} list of values in the node
*/
this.values = [];
/**
* @type {boolean} is a leaf
*/
this.leaf = isLeaf;
@lancejpollard
lancejpollard / Node.java
Created February 12, 2022 02:49 — forked from EvaGL/Node.java
Concurrent T-Tree
import java.util.Arrays;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class Node {
static final int MIN_ELEMENTS = 30, MAX_ELEMENTS = 2 * MIN_ELEMENTS;
private int[] data;
private int len;
@lancejpollard
lancejpollard / json2.js
Created February 6, 2022 18:56
json2.js
// original-ish implementation https://en.wikipedia.org/wiki/Douglas_Crockford
(function() {
"use strict";
var rx_one = /^[\],:{}\s]*$/;
var rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g;
var rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
var rx_four = /(?:^|:|,)(?:\s*\[)+/g;
var rx_escapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
var rx_dangerous = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
@lancejpollard
lancejpollard / readme.md
Last active February 6, 2022 10:05
Proof Techniques

Proof Techniques

There are only about 10-12 general proof techniques you need to consider, with only 2 or 3 being most common.

Proof by Logical Transformation

This can prove the conclusion by combining chains/trees of axioms, definitions, and earlier theorems.

Proof by Mathematical Induction

@lancejpollard
lancejpollard / readme.md
Last active March 20, 2024 10:00
.keylayout file cheat sheet