Skip to content

Instantly share code, notes, and snippets.

View ydnar's full-sized avatar

Randy Reddig ydnar

View GitHub Profile
@ydnar
ydnar / simultaneous-transitions.vue
Created September 24, 2017 13:35
Simultaneous page transitions in Nuxt.js
<template>
<div class="container">
<h1>Flex Test</h1>
<div class="content" @click="show = (show + 1) % 3">
<transition name="fade">
<div v-if="show == 0" class="foo">
<h2>Foo</h2>
<p>One paragraph.</p>
</div>
</transition>
@ydnar
ydnar / hitch-example.go
Last active December 26, 2017 01:24
hitch: middleware + routing for vanilla go http.Handlers — https://github.com/nbio/hitch
package main
import (
"fmt"
"net/http"
"github.com/nbio/hitch"
"github.com/nbio/httpcontext"
"github.com/nbio/httpgzip"
)
@ydnar
ydnar / EXPIRENX.txt
Last active January 12, 2018 21:58
Lua one-liner to implement an “EXPIRENX” command in Redis
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 / syncmap.go
Last active June 11, 2018 20:12
sync.Map with LoadOrCreate for idempotent deferred creation of expensive entries
package syncmap
import (
"sync"
)
// Map wraps a sync.Map to enable idempotent deferred creation of new values.
type Map struct {
sync.Map
}
@ydnar
ydnar / Makefile
Created January 28, 2020 17:30
Recursive make with positional arguments
# 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”
@ydnar
ydnar / Makefile
Created March 17, 2020 15:31
Swift tools package
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 / dependabot-go-fixup.yaml
Created April 1, 2020 15:28
Fix Dependabot Go modules PRs
name: Dependabot Go modules
on:
pull_request:
paths:
- "go.mod"
- "go.sum"
jobs:
dependabot:
@ydnar
ydnar / main.go
Created April 17, 2020 20:59
Get Tailscale IP from terminal
package main
import (
"flag"
"fmt"
"net"
"os"
)
func main() {
@ydnar
ydnar / main.go
Created June 4, 2020 19:22
protoc-gen-good
package main
import (
"errors"
"flag"
"fmt"
"os"
"path/filepath"
"strings"
"unicode"
@ydnar
ydnar / .circleci-config.yml
Last active January 14, 2021 11:02
Screenshot test artifacts on CircleCI with AVA + Puppeteer
version: 2
jobs:
build:
working_directory: ~/app
docker:
- image: circleci/node:8.7-browsers
environment:
NODE_ENV: production
steps:
- checkout