Skip to content

Instantly share code, notes, and snippets.

View andrewbruner's full-sized avatar

Andrew Bruner andrewbruner

View GitHub Profile
@andrewbruner
andrewbruner / indexedDB.js
Created March 16, 2024 23:32
General guide for using the IndexedDB API
const request = indexedDb.open(name: string, ?version: number);
request.onupgradeneeded = () => {
const database = request.result;
const store = database.createObjectStore(name: string, ?options: { ?keyPath: string, ?autoIncrement: boolean });
const index = store.createIndex(indexName: string, keyPath: string, ?options: { ?unique: boolean, ?multiEntry: boolean });
store.transaction.oncomplete = () => {
const transaction = database.transaction(storeNames: string[] | string, ?mode: enum = 'readonly' | 'readwrite' );
const store = transaction.objectStore(name: string);
@andrewbruner
andrewbruner / index.html
Created March 5, 2024 23:00
My personal index.html file boilerplate
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="" />
<link rel="stylesheet" type="text/css" href="" />
<link rel="icon" href="favicon.png">
</head>
@andrewbruner
andrewbruner / split.js
Created December 30, 2022 16:08
Clone of String.prototype.split()
function split(input, char) {
let arr = [ ];
let prevIdx = 0;
for (let i = 0; i < input.length; i++) {
if (input[i] === char) {
let item = '';
for (let j = prevIdx; j < i; j++) {
item += input[j];
}
arr = [ ...arr, item, ];
@andrewbruner
andrewbruner / isbn13.js
Created October 11, 2021 21:06
Returns if ISBN-13 is valid
/**
* Returns if ISBN-13 is valid
*
* @param {string} isbn
* @returns {boolean}
*/
function isbn13IsValid(isbn) {
// split isbn into an array
let isbnArr = isbn.split('');
@andrewbruner
andrewbruner / isbn10.js
Created October 11, 2021 21:04
Returns if ISBN-10 is valid
/**
* Returns if ISBN-10 is valid
*
* @param {string} isbn
* @returns {boolean}
*/
function isbn10IsValid(isbn) {
// split isbn into an array
let isbnArr = isbn.split('');
@andrewbruner
andrewbruner / blockchain.js
Created August 15, 2021 15:30
Simple JavaScript Blockchain
// Block Object
function Block(previousHash, data) {
this.previousHash = previousHash;
this.data = data;
this.hash = SHA256(JSON.stringify(this));
}
// Blockchain Object
function Blockchain() {