Skip to content

Instantly share code, notes, and snippets.

@devdave
devdave / cloudfront-response.d.ts
Created March 7, 2024 05:31
a part of the cloud front response code
export interface CloudFrontResponseEvent {
Records: Array<{
cf: CloudFrontEvent & {
readonly request: Pick<CloudFrontRequest, Exclude<keyof CloudFrontRequest, "body">>;
response: CloudFrontResponse;
};
}>;
}
@devdave
devdave / use-settings.ts
Created July 20, 2023 19:41
Experimental React settings state manager
import { map, Dictionary } from 'lodash'
import { UseMutationResult, UseQueryResult } from '@tanstack/react-query'
import { useCallback } from 'react'
type GenericTypes<TContainer> = TContainer[keyof TContainer]
export interface SettingsManagerReturn<TValues> {
get: <Field extends keyof TValues>(name: Field) => UseQueryResult<TValues[Field]> | undefined
set: <Field extends keyof TValues>(name: Field, value: TValues[Field]) => TValues[Field]
reconcile: (onValuesLoaded?: (values: TValues) => void) => void
@devdave
devdave / content_tree.tsx
Created June 12, 2023 18:23
Toggleable and hand onSelect with custom node.
import {TargetedElement} from "./types.ts";
import {FC} from "react";
import {Tree, NodeRendererProps} from "react-arborist";
type setElementsType = (elements: TargetedElement[]) => void;
interface ContentTreeProps {
elements: TargetedElement[],
setElements: setElementsType
@devdave
devdave / printout.py
Created April 7, 2023 16:14
print portal names for valheim
"""
1. Download & install Python, be sure to click option for it to be added to the system Path
2. Save this to Desktop or somewhere/anywhere
3. Find the file path to your valheim world db file.
4. Put the file path in between the quotes on line 23 / test_file
5. Using the command line, run `python printout.py`
"""
def portals(dbfile):
with open(dbfile, 'rb') as db:
@devdave
devdave / main.reds
Created March 8, 2023 14:58
Updated broken/cheat breach mini game for Cyberpunk 2077
//Breach protocol simplifier
//Copy to r6/scripts/breach/ make sure to create "breach" directory if it doesn't exist
// 1.6 compat
@replaceMethod(MinigameGenerationRuleScalingPrograms)
protected func OnProcessRule(out size: Uint32, out grid: array<array<GridCell>>) -> Bool {
let atStart: Bool;
let combinedPowerLevel: Float;
let extraDifficulty: Float;
let i: Int32;
@devdave
devdave / valheimdb_snippet.py
Created February 4, 2023 21:46
A short snippet to seek through a valheim db file and retrieve a lit of portals
# sourced from https://www.reddit.com/r/valheim/comments/lixlu7/any_way_to_look_up_the_name_of_a_portal_you_forgot/iibfmuo/
import mmap
def portals(dbfile):
db = open(dbfile, 'rb')
mm = mmap.mmap(db.fileno(), 0, prot=mmap.PROT_READ)
i, l = 0, set()
while True:
@devdave
devdave / contractions.py
Created December 1, 2022 21:44 — forked from nealrs/contractions.py
Expand common (and some very uncommon) english contractions
"""
this code is not mine! i shamelessly copied it from http://stackoverflow.com/questions/19790188/expanding-english-language-contractions-in-python
all credits go to alko and arturomp @ stack overflow.
basically, it's a big find/replace.
"""
import re
cList = {
"ain't": "am not",
@devdave
devdave / counter.py
Created December 1, 2022 18:42
simple script to summarize the contents of a directory of docx files
from pathlib import Path
from collections import Counter
from docx import Document # pip install python-docx
from nltk.tokenize import sent_tokenize, word_tokenize # pip install nltk==3.5
ROOT = Path(r"C:\\REDACTED\\book\\")
@devdave
devdave / python-people.md
Created November 15, 2022 16:14 — forked from samuelcolvin/python-people.md
An incomplete list of people in the Python community to follow on Twitter and Mastodon.

Python People

An incomplete list of people in the Python community to follow on Twitter and Mastodon.

With the risk that Twitter dies, I'd be sad to lose links to interesting people in the community, hence this list.

I would love you to comment below with links to people I've missed.

More context and comments at the end of the list.

@devdave
devdave / Speech Recognition.ahk
Created June 30, 2022 16:34 — forked from Uberi/Speech Recognition.ahk
Speech recognition with Microsoft's SAPI. A simple SpeechRecognizer class provides a quick and easy way to use speech recognition in your scripts. Inspired by some [prototype code](http://www.autohotkey.com/board/topic/24490-voice-recognition-com/) made a long time ago.
#NoEnv
#Warn All
#Warn LocalSameAsGlobal, Off
#Persistent
/*
Speech Recognition
==================
A class providing access to Microsoft's SAPI. Requires the SAPI SDK.