Skip to content

Instantly share code, notes, and snippets.

View bossley9's full-sized avatar
🇹🇼

Sam Bossley bossley9

🇹🇼
View GitHub Profile
// In this component, React "strict mode" is disabled. The main focus of this quiz is <MainComponent />.
// <ReactLifecycleQuiz /> is a simple parent component that wraps <MainComponent />.
import { useEffect, useRef, useState } from 'react'
export const ReactLifecycleQuiz = () => {
const [parentValue, setParentValue] = useState(0)
const _handleClick = () => {
setParentValue(parentValue + 1)
}
@bossley9
bossley9 / tech-debt.sh
Created October 29, 2022 16:58
Shipt Tech Debt Progress
#!/usr/bin/env sh
DIR="/Users/samuelbossley/Repos/segway-next"
opts="\
-R \
--exclude-dir ${DIR}/build \
--exclude-dir ${DIR}/coverage \
--exclude-dir ${DIR}/node_modules \
--exclude-dir ${DIR}/.yarn \
@bossley9
bossley9 / scanTable.js
Created July 31, 2019 13:31
efficient table scanning in DynamoDB
const AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient();
/**
* Given a parameters object, scans a table and returns the items in the response.
* If no valid matching items are found, returns a response containing an empty array.
* @param {object} params - DynamoDB scan params
* @param {boolean} recursiveEvaluate - boolean whether operation should continue
* until all results are retrieved. Default value is true.
*/
@bossley9
bossley9 / queryTable.js
Created July 31, 2019 13:00
efficient table querying in DynamoDB
const AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient();
/**
* Given a parameters object, queries a table and returns the items in an array.
* If no valid matching items are found, returns an empty array.
* @param {object} params - DynamoDB query params
* @param {boolean} recursiveEvaluate - boolean whether operation should continue
* until all results are retrieved. Default value is true.
*/
@bossley9
bossley9 / DynamicList.hpp
Last active November 13, 2019 22:50
A C++ dynamically sizeable array implementation
#pragma once
/**
* A dynamically sizeable array implementation.
*/
template <class T, class I = unsigned short>
class DynamicList {
private:
// the array storing all values
@bossley9
bossley9 / FizzBuzz.cpp
Last active November 13, 2019 21:48
FizzBuzz implementation
#include <stdio.h>
#include <Windows.h>
#include <string>
// define a pair of integer and string
struct NameNumPair {
// constructor
NameNumPair(int _num, std::string _name) {
num = _num;
name = _name;
@bossley9
bossley9 / rnBool.js
Last active July 31, 2019 14:00
A random boolean generating function
/**
* Given an optional percentage chance between 0 and 1, generates a random
* boolean value with the chance percentage. The default percentage chance
* is 0.5, or 50%.
* @param {double} perc - percentage chance true
* @return {boolean} chance
*/
exports.rnBool = function (perc = 0.5) {
// Because Math.random is [0, 1), percentage needs to be inversed
let invPerc = 1 - perc;