Skip to content

Instantly share code, notes, and snippets.

View danawoodman's full-sized avatar
👨‍🔬
Hacking away...

Dana Woodman danawoodman

👨‍🔬
Hacking away...
View GitHub Profile
@danawoodman
danawoodman / How to allow the file picker AND camera capture on Android.md
Last active February 17, 2025 15:42
How to allow the file picker AND camera capture on Android

Allow photo album AND the camera

On Android devices, if you want to create a file input that prompts the user to either choose an image from their photo album or take a picture with their camera, you'll need this basically undocumented capture attribute added to your input's accept property:

<input type="file" accept="image/*;capture=camera" />
@danawoodman
danawoodman / ESP32 Controlled Low-Voltage Path Lights.md
Last active February 5, 2025 03:18
ESP32 Controlled Low-Voltage Path Lights

ESP32 Controlled Low-Voltage Path Lights

Using an ESP32-C3 connected to HomeAssistant via ESPHome, control 12v yard path lights including configuring automations to turn lights on/off at sunset/sunrise and dimming.

This short guide will show you how to use HomeAssistant, and the ESPHome app for it, to control LED dimming. In this case I'm using this for low voltage yard path lights, but could be used for anything.

If you have HomeKit integrated with HomeAssistant than you can also control/dim your LEDs from your iPhone!

Parts

@danawoodman
danawoodman / Svelte action to auto-grow a textarea.md
Created January 14, 2025 19:44
Svelte action to auto-grow a textarea

Svelte action to auto-grow a textarea

A Svelte action that whena applied to a textaarea supports automatically growing or shrinking as content is added or removed.

Implementation

src/lib/actions/autogrow.ts:

export function autogrow(node: HTMLElement) {
@danawoodman
danawoodman / Using Golang templ with the Echo framework.md
Last active January 2, 2025 11:50
Using Golang templ with the Echo framework

Using Golang templ with the Echo framework

templ is a great view framework but there is no clear documentation (as of writing) showing how to use it with the Echo web framework. This short guide should show you how to set it up:

Install dependencies

Install templ and echo:

go get github.com/a-h/templ
@danawoodman
danawoodman / 1-react-websockets-reflux.md
Last active August 21, 2024 20:58
Using WebSockets with Reflux and React

WebSockets + Reflux + React

Using WebSockets, React and Reflux together can be a beautiful thing, but the intial setup can be a bit of a pain. The below examples attempt to offer one (arguably enjoyable) way to use these tools together.

Overview

This trifect works well if you think of things like so:

  1. Reflux Store: The store fetches, updates and persists data. A store can be a list of items or a single item. Most of the times you reach for this.state in react should instead live within stores. Stores can listen to other stores as well as to events being fired.
  2. Reflux Actions: Actions are triggered by components when the component wants to change the state of the store. A store listens to actions and can listen to more than one set of actions.
@danawoodman
danawoodman / Deploying CloudFlare Workers via CloudFlare Pages in a Turborepo monorepo.md
Last active August 15, 2024 19:44
Deploying CloudFlare Workers via CloudFlare Pages in a Turborepo monorepo

Deploying Cloudflare Workers via Cloudflare Pages in a Turborepo monorepo

Whew, what a mouthful.

Cloudflare Workers is an excellent platform for deploying a variety of applications but it has some limitations compared to Cloudflare's other product, Pages.

Pages gives you git integration which gives you auto-deploying via git push as well as pull request preview deployment links so you can test out features before pushing to production.

However, it's not super clear how to deploy a bare worker to Cloudflare Pages as Pages is more tailored right now for apps (SvelteKit, Astro, Next, etc), that is why I wrote up this little guide.

@danawoodman
danawoodman / Serving embedded static files with Echo (Golang).md
Last active August 7, 2024 11:23
Serving embedded static files with Echo (Golang)

Serving embedded static files with Echo (Golang)

For a project I'm working on, I need to ship a single server binary with all static files embedded and use that for the frontend of the server. The backend has a variety of routes which the frontend calls.

The frontend is a SvelteKit static app built to ./frontend/build. Here is the Echo configuration to get these files serving at the root of the web server:

@danawoodman
danawoodman / 0-react-hello-world.md
Last active March 9, 2024 00:32
React Hello World Examples

React "Hello World" Examples

Below are a small collection of React examples to get anyone started using React. They progress from simpler to more complex/full featured.

They will hopefully get you over the initial learning curve of the hard parts of React (JSX, props vs. state, lifecycle events, etc).

Usage

You will want to create an index.html file and copy/paste the contents of 1-base.html and then create a scripts.js file and copy/paste the contents of one of the examples into it.

@danawoodman
danawoodman / Release golang apps using Github Actions.md
Last active February 7, 2024 07:00
Create a Go app release for every git version tag using Github Actions

Release golang apps using Github Actions

Want to release a new binary on Github for every new git tag (e.g. v1.2.7)? Here is a simple Github Actions yaml config file that should get you started.

This script will automatically checkout your code, setup the correct version of go as defined in your go.mod file and build your go binary (in this case using a Makefile default target), then upload it to a new Github Release.

# .github/workflows/release.yml
name: Build and release Go Project
@danawoodman
danawoodman / Raspberry Pi web page kiosk mode.md
Last active February 7, 2024 05:22
How to setup a Raspberry Pi to start up a web page in kiosk mode

Start a web page in kiosk mode on a Raspberry Pi

Install dependencies

Start by installing chromium and unclutter which will hide the cursor on the screen:

sudo apt install -y -no-install-recommends chromium-browser unclutter