Skip to content

Instantly share code, notes, and snippets.

@matthewmueller
matthewmueller / child-main.go
Last active June 3, 2022 15:01
Cancelable Reader. Useful for tests where you want to wait for some input, but not hang forever. (Before using, you need to change child-main.go to child/main.go)
package main
import (
"fmt"
"time"
)
func main() {
for i := 0; i < 10; i++ {
time.Sleep(1 * time.Second)
@matthewmueller
matthewmueller / awaiting_response.gs
Created February 8, 2022 03:27
Some Google Scripts I used to run periodically on my Gmail. Saving for posterity.
/*
* This script goes through your Gmail Inbox and finds recent emails where you
* were the last respondent. It applies a nice label to them, so you can
* see them in Priority Inbox or do something else.
*
* To remove and ignore an email thread, just remove the unrespondedLabel and
* apply the ignoreLabel.
*
* This is most effective when paired with a time-based script trigger.
*
@matthewmueller
matthewmueller / generics.go
Last active December 30, 2021 18:51
Experimenting with generics as a way of annotating fields
// You can edit this code!
// Click here and start typing.
package main
import (
"io"
)
func main() {
fmt.Println(Show(Query[int]{10}))
@matthewmueller
matthewmueller / mail.php
Created September 21, 2020 15:15
Laravel mailer configuration
/*
|--------------------------------------------------------------------------
| Mailer Configurations
|--------------------------------------------------------------------------
|
| Here you may configure all of the mailers used by your application plus
| their respective settings. Several examples have been configured for
| you and you are free to add your own as your application requires.
|
@matthewmueller
matthewmueller / database.yml
Created September 21, 2020 15:12
Rails Configuration with Environment
# SQLite. Versions 3.8.0 and up are supported.
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
@matthewmueller
matthewmueller / responsewriter.go
Created August 31, 2020 09:34
ResponseWriter wrapper to allows middleware to set headers without worrying about the response header being written already.
package responsewriter
import (
"bytes"
"net/http"
"github.com/felixge/httpsnoop"
)
// Wrap the response writer
@matthewmueller
matthewmueller / grammar.go
Created August 1, 2020 12:30
Route parser, similar to https://github.com/pillarjs/path-to-regexp in Express.js
package route
//go:generate peg -switch -inline grammar.peg
import (
"regexp"
"github.com/kr/pretty"
)
package plugin
import (
"fmt"
"io"
"os"
"os/exec"
"strconv"
)
// Usage:
// $ node index.js
//
// Code to generate this. Should be modified to auto-generate tables, columns, etc.
const types = [
'bigint',
'int8',
'bigserial',
@matthewmueller
matthewmueller / protocol.ts
Last active November 13, 2023 22:13
Protocol example
export type API = {
'get /teams/:key': {
request: {
key: string
}
response: {
key: string
name: string
}
}