Skip to content

Instantly share code, notes, and snippets.

View mike-pete's full-sized avatar

Mike Peterson mike-pete

  • San Francisco, CA
View GitHub Profile
@mike-pete
mike-pete / 0patterns.md
Last active February 28, 2023 23:54
Design Patterns

Terms

Composition

  • Delegate work to helper objects.
  • Use objects from different concrete classes to get different implementations for helper methods.
  • strategy, state, etc.

Aggregation

  • (from refactoring.guru) object A contains objects B; B can live without A.
@mike-pete
mike-pete / recursion.py
Created July 27, 2022 15:47
example of recursion
def addAllNumbersFromZeroToN(n):
if n > 0:
return n + addAllNumbersFromZeroToN(n-1)
return n
print(addAllNumbersFromZeroToN(3)) #6
print(addAllNumbersFromZeroToN(2)) #3
print(addAllNumbersFromZeroToN(5)) #15
const x = {
a:{
b:{
c:'neat'
}
}
}
const loop = (object, path) => {
let index = 0
class Solution:
def intToRoman(self, num: int) -> str:
numerals = {
1: 'I',
4: 'IV',
5: 'V',
9: 'IX',
10: 'X',
40: 'XL',
50: 'L',
class Solution:
def romanToInt(self, s: str) -> int:
numerals = {
'I': 1,
'V': 5,
'X': 10,
'L': 50,
'C': 100,
'D': 500,
'M': 1000
@mike-pete
mike-pete / bakingConversions.py
Created June 7, 2022 06:21
Baking conversions in Python
conversions = {
'cup': 1,
'ml': 236.588,
'tbsp': 16,
'tsp': 48
}
unitAlias = {
'cups': 'cup',
'mls': 'ml',
@mike-pete
mike-pete / README.md
Created May 31, 2022 23:46
D&D Stat Roller
  1. Roll a 6 sided die 4 times.
  2. Remove the lowest dice result.
  3. Add up the remaining numbers to get an ability score.
  4. Write down this ability score on note paper.
  5. Repeat these steps until you have 6 ability scores.
@mike-pete
mike-pete / getRedditCommenters.js
Created May 16, 2022 00:13
get a list of all reddit users that commented on a post
let commenters = document.querySelectorAll('[data-testid="comment_author_link"]')
let commenterData = {}
commenters.forEach(commenter => commenterData[commenter.text] = commenter.href)
console.log(commenterData)
@mike-pete
mike-pete / verifyJWT.js
Created April 11, 2022 16:13
An example of verifying JWTs from a Cloudflare Function.
// the origonal gist that this code is based off of:
// https://gist.github.com/bcnzer/e6a7265fd368fa22ef960b17b9a76488
// these are refrences for firebase stuff:
// https://www.googleapis.com/service_accounts/v1/jwk/[email protected]
// https://www.googleapis.com/robot/v1/metadata/x509/[email protected]
export default async function verifyJWT(request) {
const encodedToken = getJwt(request)
if (encodedToken === null) {
@mike-pete
mike-pete / mouseMover.ino
Created January 15, 2022 03:44
Move the mouse back and forth to keep a computer awake
#include <DigiMouse.h>
#include <oddebug.h>
#include <osccal.h>
#include <osctune.h>
#include <usbconfig-prototype.h>
#include <usbconfig.h>
#include <usbdrv.h>
#include <usbportability.h>
void setup() {