Skip to content

Instantly share code, notes, and snippets.

Randy Reddig ydnar

Block or report user

Report or block ydnar

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ydnar
ydnar / main.go
Created Apr 17, 2020
Get Tailscale IP from terminal
View main.go
package main
import (
"flag"
"fmt"
"net"
"os"
)
func main() {
@ydnar
ydnar / swift.yaml
Created Apr 5, 2020
SwiftFormat with GitHub Actions
View swift.yaml
name: Swift
on:
push:
branches:
- master
paths:
- ".github/workflows/swift.yaml"
- "**.swift"
- "**/Package.resolved"
@ydnar
ydnar / dependabot-go-fixup.yaml
Created Apr 1, 2020
Fix Dependabot Go modules PRs
View dependabot-go-fixup.yaml
name: Dependabot Go modules
on:
pull_request:
paths:
- "go.mod"
- "go.sum"
jobs:
dependabot:
@ydnar
ydnar / Makefile
Created Mar 17, 2020
Swift tools package
View Makefile
TOOLS := swiftformat protoc-gen-swift protoc-gen-grpc-swift
tools: $(TOOLS)
$(TOOLS): Package.swift Package.resolved
swift build -c release --product $@
cp $$(swift build -c release --show-bin-path)/$@ ~/bin/
@ydnar
ydnar / Makefile
Created Jan 28, 2020
Recursive make with positional arguments
View Makefile
# To make a sandwich:
# $ make <track> sandwich
# e.g.: make alpha sandwich
#
# This works by rewriting MAKECMDGOALS by stripping the argument from the list
# and recursively calling make with a variable assignment (e.g. track=alpha)
# and the remaining goal(s).
#
# The ifeq below ensures that the “real” goals aren’t executed unless the
# track variable is set. The @: command silences the “Nothing to be done”
View record-in-48khz-via-airpods.swift
// Thanks https://amorten.com/blog/2017/ios-bluetooth-and-microphone-input/
func configure() {
// ...
let session = AVAudioSession.sharedInstance()
let sampleRate = 48000.0
do {
@ydnar
ydnar / syncmap.go
Last active Jun 11, 2018
sync.Map with LoadOrCreate for idempotent deferred creation of expensive entries
View syncmap.go
package syncmap
import (
"sync"
)
// Map wraps a sync.Map to enable idempotent deferred creation of new values.
type Map struct {
sync.Map
}
@ydnar
ydnar / EXPIRENX.txt
Last active Jan 12, 2018
Lua one-liner to implement an “EXPIRENX” command in Redis
View EXPIRENX.txt
DEL example.com
HSET example.com status reserved
EVAL "return redis.call('TTL',KEYS[1])>0 or redis.call('EXPIRE',KEYS[1],ARGV[1])" 1 example.com 111111
HGETALL example.com
TTL example.com
HSET example.com comment IANA
EVAL "return redis.call('TTL',KEYS[1])>0 or redis.call('EXPIRE',KEYS[1],ARGV[1])" 1 example.com 222222
@ydnar
ydnar / .circleci-config.yml
Last active Jul 18, 2019
Screenshot test artifacts on CircleCI with AVA + Puppeteer
View .circleci-config.yml
version: 2
jobs:
build:
working_directory: ~/app
docker:
- image: circleci/node:8.7-browsers
environment:
NODE_ENV: production
steps:
- checkout
@ydnar
ydnar / index.es6.js
Last active Apr 28, 2020
Versioned documents with Firestore Cloud Functions
View index.es6.js
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
You can’t perform that action at this time.