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 / Using Golang templ with the Echo framework.md
Last active April 22, 2024 10:23
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 / 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
@danawoodman
danawoodman / How to build a Golang application for a Raspberry Pi.md
Last active February 7, 2024 00:02
How to build a Golang application for a Raspberry Pi

How to build a Golang application for a Raspberry Pi

Given a binary at cmd/server/main.go, create a binary at bin/server that is built for a Raspberry Pi:

env GOOS=linux GOARCH=arm GOARM=5 go build -o ./bin/server ./cmd/server/main.go
@danawoodman
danawoodman / Setup a system service for the RaspberryPi.md
Last active February 7, 2024 00:02
Setup a system service for the RaspberryPi

Setup a system service for the RaspberryPi

If you want to run your own app on a Debian system, like a RaspberryPi, you'll need to build the binary for the given device then setup systemd to run the binary.

Given you have an app called myapp, first create a service file to run your app, say at myapp.service on your local system:

[Unit]
Description=Some description here...
After=network.target
@danawoodman
danawoodman / Serving embedded static files with Echo (Golang).md
Last active January 17, 2024 01:05
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 / How to allow the file picker AND camera capture on Android.md
Last active January 11, 2024 21:10
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 / add-saved-to-list.js
Last active July 17, 2023 22:44
Add your Saved for Later items in your Amazon shopping cart to your first (primary) Wish List
await run();
async function run() {
let loop = 0;
while (true) {
loop++;
console.log("loop:", loop);
const items = get_items();
if (!items.length) break;
@danawoodman
danawoodman / pdf.js
Created April 10, 2015 19:41
Example of using pdfkit in Node.js
var fs = require('fs');
var PDFDocument = require('pdfkit');
var pdf = new PDFDocument({
size: 'LEGAL', // See other page sizes here: https://github.com/devongovett/pdfkit/blob/d95b826475dd325fb29ef007a9c1bf7a527e9808/lib/page.coffee#L69
info: {
Title: 'Tile of File Here',
Author: 'Some Author',
}
});