Skip to content

Instantly share code, notes, and snippets.

View ydnar's full-sized avatar

Randy Reddig ydnar

View GitHub Profile
@ydnar
ydnar / types.wit.go
Last active February 21, 2024 04:44
Go representation of wasi:filesystem/types@0.2.0
// Code generated by wit-bindgen-go. DO NOT EDIT.
// Package types represents the interface "wasi:filesystem/types@0.2.0".
//
// WASI filesystem is a filesystem API primarily intended to let users run WASI
// programs that access their files on their existing filesystems, without
// significant overhead.
//
// It is intended to be roughly portable between Unix-family platforms and
// Windows, though it does not hide many of the major differences.
// Thanks https://amorten.com/blog/2017/ios-bluetooth-and-microphone-input/
func configure() {
// ...
let session = AVAudioSession.sharedInstance()
let sampleRate = 48000.0
do {
@ydnar
ydnar / README.md
Last active December 13, 2023 19:26
wasi:cli/command

wasi:cli/command

Generating

  1. Install the wit-bindgen-cli crate via cargo install wit-bindgen-cli.
  2. Check out the wasi:cli repo.
  3. Run wit-bindgen c --world command wit in the wasi-cli directory.
package poll
import (
"unsafe"
"github.com/ydnar/wasm-tools-go/wasm/cm"
)
// Interface implements WIT interface "wasi:io/poll".
type Interface interface {
@ydnar
ydnar / fs.go
Created September 12, 2023 17:12
platform package for GOOS=wasip1
package platform
import (
"os"
"path/filepath"
)
// ExecutableDir returns the directory containing the current executable,
// or when an error occurs, the current working directory.
func ExecutableDir() (string, error) {
@ydnar
ydnar / redirects.js
Last active September 12, 2023 10:14
Nuxt.js middleware to enable redirects to absolute URLs
import url from 'url'
import qs from 'qs'
export default function (ctx) {
fixRedirect(ctx)
const { route, redirect } = ctx
const { path, query } = route
// Redirect trailing slashes, preserving query string: /foo/ -> /foo
if (path.length > 1 && path.slice(-1) === '/') {
@ydnar
ydnar / zero.go
Created July 17, 2023 19:40
nil as untyped zero value for Go
package main
func main() {
var s string
var _ = s == nil // true
var i int
var _ = i == nil // true
var v struct {
@ydnar
ydnar / swift.yaml
Created April 5, 2020 19:42
SwiftFormat with GitHub Actions
name: Swift
on:
push:
branches:
- master
paths:
- ".github/workflows/swift.yaml"
- "**.swift"
- "**/Package.resolved"
@ydnar
ydnar / queue.go
Last active April 26, 2023 00:54
Weighted queue using multi-channel select in Go
package priority
import (
"context"
"sync/atomic"
)
type Priority int
const (
@ydnar
ydnar / index.es6.js
Last active September 16, 2022 10:52
Versioned documents with Firestore Cloud Functions
import * as admin from 'firebase-admin'
import * as functions from 'firebase-functions'
admin.initializeApp(functions.config().firebase)
const db = admin.firestore()
async function writeIntegerVersion(event) {
const ref = event.data.ref
if (ref.path.indexOf('/_versions/') >= 0) {
return false