Skip to content

Instantly share code, notes, and snippets.

View Ustice's full-sized avatar

Jason Kleinberg Ustice

  • Mobiquity
  • Gainesville, FL
View GitHub Profile
@Ustice
Ustice / Boolean Algebra for Programmers in a Nutshell.md
Last active January 9, 2024 20:16
Boolean Algebra in a nutshell for JS/TS programmers

Boolean Algebra in a nutshell for JS/TS programmers

There are a lot of strategies that you will hear about in the Javascript community for keeping your conditionals from becoming a tangled mess. This isn't like them. This is someting different. MATH! Boolean Algebra to be exact. I use it all the time to simplify complex conditionals. There are two things that you need to know: de Morgan's Theorem, and Karnaugh (pronounced CAR-no) Maps. (Don't worry, there is no test)

de Morgan's Theorem

De Morgan's Theorem is great distributing nots (!), and for when you want to convert an && to an ||, or back. This is it:

 !(A && B) = !A || !B
@Ustice
Ustice / longest_sequence.py
Created October 2, 2020 18:27
A longest_sequence implementation in python
def larger_of(a, b):
return a if a[1] > b[1] else b
def reset_to(index):
return [index, 1]
def is_sequential(a, b):
return a == b - 1
def grow(vector):
@Ustice
Ustice / dndbeyond-fix-sidebar.user.js
Last active April 19, 2021 15:20
D&D Beyond automatic fixed sidebar
// ==UserScript==
// @name D&D Beyond fixed sidebar
// @version 6
// @grant none
// @include /^(https://www.dndbeyond.com/profile/[^/]*/characters/.*|https://www.dndbeyond.com/characters/.*)$/
// ==/UserScript==
const clickElement = (query) => {
console.log('Clicking ' + query)
const element = document.querySelector(query)
element?.click()
@Ustice
Ustice / collect-different-properties.js
Last active November 30, 2016 21:26
Compares the properties of two objects and returns an array of paths to the properties of the baseObject that are different or nonexistent in the compareObject.
/**
* Compares the properties of two objects and returns an array of paths to the
* properties of the baseObject that are different or non-existant in the
* compareObject.
*
* person0 = {
* name: {
* first: 'Eve'
* }
* };