Skip to content

Instantly share code, notes, and snippets.

View cmrigney's full-sized avatar

Cody Rigney cmrigney

  • Docker
  • Canton, Ohio
View GitHub Profile
@cmrigney
cmrigney / useLocalStorage.ts
Created September 5, 2023 19:10
useLocalStorage implemented with useSyncExternalStore
export function useLocalStorage<T>(key: string, initialValue: T) {
const store = useMemo(
() => getLocalStorageStore(key, initialValue),
[key, initialValue],
);
const currentValue = useSyncExternalStore(store.subscribe, store.getSnapshot);
const setValue = useCallback(
(value: T | ((value: T) => T)): void => {
@cmrigney
cmrigney / Dockerfile
Created August 7, 2023 19:54
Example Rust Dockerfile from docker init
# syntax=docker/dockerfile:1
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/engine/reference/builder/
################################################################################
# Create a stage for building the application.
ARG RUST_VERSION=1.71.1
@cmrigney
cmrigney / Dockerfile
Created August 7, 2023 19:51
Example Go Dockerfile from docker init
# syntax=docker/dockerfile:1
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/engine/reference/builder/
################################################################################
# Create a stage for building the application.
ARG GO_VERSION=1.21
FROM golang:${GO_VERSION} AS build
@cmrigney
cmrigney / ap-lora-http.lox
Created April 13, 2023 00:42
Forwards LoRa messages via web server. Written in my version of Lox. Runs on Pi Pico.
// Forwards LoRa messages via web server. Written in my version of Lox. Runs on Pi Pico.
var pico = systemImport("pico");
var lora = systemImport("lora_radio");
pico.LEDPin.on();
fun error(msg) {
logln(msg);
pico.LEDPin.off();
pico.exit();
@cmrigney
cmrigney / desk-adjust.lox
Created April 13, 2023 00:39
Personal hacked desk adjustment system, written in my version of Lox. Runs on a Pi Pico.
// Personal hacked desk adjustment system, written in my version of Lox. Runs on a Pi Pico.
var pico = systemImport("pico");
var CRNL = Buffer(Array(13, 10)).asString();
class DoubleClickTracker {
init(pin, callback) {
this.pin = pin;
this.callback = callback;
this.reset();
@cmrigney
cmrigney / Merge.d.ts
Created June 21, 2022 20:21
Merge two object types recursively.
type Assign<T1, T2> = Omit<T1, keyof T2> & T2;
type Merge<T1, T2> = T1 extends object
? T2 extends object
? Assign<
T1,
{
[k in keyof T2]: Merge<
k extends keyof T1 ? T1[k] : T2[k],
T2[k]
>;
@cmrigney
cmrigney / useRedux.ts
Created April 11, 2019 18:05
Example for useRedux
// Adapted code from https://github.com/flepretre/use-redux
import { useContext, useState, useEffect, useCallback } from 'react';
import { ReactReduxContext } from 'react-redux';
import { bindActionCreators, ActionCreator } from 'redux';
export function useRedux() {
const { store } = useContext(ReactReduxContext);
const { getState, dispatch, subscribe } = store;
const reduxState = getState();