Skip to content

Instantly share code, notes, and snippets.

View ThatOneBro's full-sized avatar

Derrick Farris ThatOneBro

View GitHub Profile
@ThatOneBro
ThatOneBro / for-loop-comparison.mts
Created September 1, 2023 21:12
Comparison of performance of different types of `for` loops
import { bench, group, run } from "mitata";
const ENTRIES = 100000;
const OBJ_TEST = new Array(ENTRIES).fill(0).map((_) => ({
id: "Appointment.priority",
path: "Appointment.priority",
short: "Used to make informed decisions if needing to re-prioritize",
definition:
"The priority of the appointment. Can be used to make informed decisions if needing to re-prioritize appointments. (The iCal Standard specifies 0 as undefined, 1 as highest, 9 as lowest priority).",
const isPositionWithinBox = (point1, point2, coords) => {
if (point1.x < coords.x && point2.x > coords.x && point1.y > coords.y && point2.y < coords.y)
return true;
return false;
};
const getBoundingBox = (origin, width, height) => {
const x1 = origin.x - width / 2;
const y1 = origin.y + height / 2;
const x2 = origin.x + width / 2;

Keybase proof

I hereby claim:

  • I am thatonebro on github.
  • I am thatonebro (https://keybase.io/thatonebro) on keybase.
  • I have a public key ASCO6Mrm8wq7VAvWmILmFitEJYvL0lUJc0L4g99_KCZj3Qo

To claim this, I am signing this object:

@ThatOneBro
ThatOneBro / robustPromiseAll.js
Last active March 20, 2020 19:28
robustPromiseAll
// Returns an array of two arrays, one will all resolved promises, and one with all rejected promises
const robustPromiseAll = async (promises) => {
// This is how we wrap a promise to prevent it from rejecting directly in the Promise.all and causing a short circuit
const wrapPromise = async (promise) => {
// We are trying to await the promise, and catching any rejections
// We return an array, the first index being resolve, and the second being an error
try {
const result = await promise
return [result]
} catch (e) {
@ThatOneBro
ThatOneBro / merge-sort.go
Created January 27, 2017 19:59
A simple merge sort algorithm implemented in Go
import "time"
import "fmt"
import "math/rand"
func merge(arr []int, low int, center int, high int) {
var i, j, k int
leftLen := center - low + 1
rightLen := high - center
@ThatOneBro
ThatOneBro / merge-sort.cpp
Last active January 25, 2017 03:40
A simple merge sort algorithm implemented in C++
#include <ctime>
#include <stdlib.h>
#include <stdio.h>
#include <Windows.h>
using namespace std;
void fillArray(int* , int);
void printArray(int*, int);
void merge(int*, int, int, int);
@ThatOneBro
ThatOneBro / merge-sort.py
Last active January 25, 2017 03:41
A simple merge sort algorithm
import random
from timeit import Timer
def merge(arr1, arr2):
out = []
i = 0
j = 0
while i < len(arr1) and j < len(arr2):
if arr1[i] > arr2[j]:
out.append(arr1[i])
@ThatOneBro
ThatOneBro / red-black.py
Last active January 7, 2017 02:15
Exploratory implementation of red-black tree insertion in Python
RED = 'red'
BLACK = 'black'
class IterMixin(object):
def __iter__(self):
for attr, value in self.__dict__.iteritems():
yield attr, value
class Tree:
def __init__(self, root=None, nodes=set()):