Skip to content

Instantly share code, notes, and snippets.

View theacodes's full-sized avatar
🪼
I'm workin on it!

Stargirl Flowers theacodes

🪼
I'm workin on it!
View GitHub Profile
@theacodes
theacodes / model_replace.py
Last active November 19, 2024 01:24
Pydantic model_replace helper
from typing import Annotated, Any, overload
import pydantic
@overload
def model_replace[T: pydantic.BaseModel](val: T, /, **kwargs) -> T: ...
@overload
def model_replace[T: pydantic.BaseModel](val: T, _partial: T, /) -> T: ...
def model_replace[T: pydantic.BaseModel](val: T, _partial: T | None = None, /, **kwargs) -> T:
@theacodes
theacodes / attach-controller.ts
Created June 18, 2024 21:56
Lit attachController directive
/*
* Copyright (c) 2024 Opulo, Inc
* Published under the Mozilla Public License
* Full text available at: https://www.mozilla.org/en-US/MPL/
*/
import { isFunction } from "@glimmer/common/types";
import {
AsyncDirective,
LitElement,
@theacodes
theacodes / watch.ts
Created April 22, 2024 17:54
Lit @change decorator
/**
* Helper for watching reactive properties (@property) or internal state (@state)
* and calling a callback.
*
* Adapted from Shoelace:
* - https://github.com/shoelace-style/shoelace/blob/64996b2d3512a13d2ec68146fb92164d03e07e6a/src/internal/watch.ts
*/
import type { PropertyValues, ReactiveElement } from "lit";
@theacodes
theacodes / thread_emoji.py
Created December 2, 2023 17:42
Thread emoji
import threading
ANIMALS = list(
"🐶🐱🐭🐹🐰🦊🐻🐼🐨🐯🦁🐮🐷🐽🐸🐵🐔🐧🐦🐤🪿🦆🦉🦇🦇🐺🐗🐴🦄🫎🐝🪱🐛🦋🐌🐞🐜🪰🪲🪳🦟🦗🕷️🕸️🦂🐢🐍🦎🦖🦕🐙🦑🪼🦐🦞🦀🐡🐠🐟🐬🐳🐋🦈🦭🐊🐅🐆🦓🦍🦧🦣🐘🦛🦏🐪🐫🦒🦘🦬🐃🐂🐄🫏🐎🐖🐏🐑🦙🐐🦌🐕🐩🐈🐓🦃🦤🦚🦜🦢🦩🕊️🐇🦝🦨🦡🦫🦦🦥🐁🐀🐿️🦔🐉🐲"
)
ANIMALS_LEFT = []
THREAD_EMOJI = {}
def thread_emoji():
@theacodes
theacodes / main.dart
Created December 29, 2022 16:58
silent-echo-3373
void main() {
for (int i = 0; i < 5; i++) {
print('hello ${i + 1}');
}
}
@theacodes
theacodes / main.cpp
Created November 14, 2021 19:41
C++ examples for converting between MIDI notes, frequencies, and Volts/octave
#include <cstdint>
#include <cmath>
/*
Examples for converting between note numbers, frequencies, and Volts/octave.
If you're unfamiliar with MIDI note numbers, they are integers that
correspond to semitones (half steps). For example, MIDI note 12 is
C1 (16.35 Hz) and MIDI note 24 (twelve half steps higher) is C2 (32.70 Hz).
@theacodes
theacodes / main.dart
Created November 27, 2019 19:24
AnimatedContainer with FutureBuilder
FutureBuilder(
future: future,
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
double width;
switch(snapshot.connectionState) {
case ConnectionState.none:
case ConnectionState.waiting:
case ConnectionState.active:
width = 0;
break;
@theacodes
theacodes / winterbloom_voltage_out.py
Created October 9, 2019 05:26
A helper library to setting a DAC to direct voltage values
# (c) 2019 Alethea Flowers
# Licensed under the MIT license.
"""A helper library to setting a DAC to direct voltage values.
That is, instead of setting a 16-bit integer value you can set the DAC to a
floating-point voltage value.
This requires information about the real-world DAC output and any output
scaling - this is called **calibration** data.
@theacodes
theacodes / winterbloom_ad5689.py
Last active October 9, 2019 05:26
CircuitPython driver for the AD5689
# (c) 2019 Alethea Flowers
# Licensed under the MIT license.
"""A driver for the Analog Devices AD5689(R) 16-bit Digital to Analog Converter.
AD5689 wiring expectations (TSSOP-16 package):
* 1: AD5689 = Vref, AD5689R = NC (uses internal reference)
* 2: NC
* 3: Analog output A
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,