Skip to content

Instantly share code, notes, and snippets.

@matthewmueller
matthewmueller / osx-for-hackers.sh
Last active April 21, 2024 03:30
OSX for Hackers (Mavericks/Yosemite)
# OSX for Hackers (Mavericks/Yosemite)
#
# Source: https://gist.github.com/brandonb927/3195465
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Ask for the administrator password upfront
@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
}
}
@matthewmueller
matthewmueller / escape-json.js
Created August 25, 2012 02:50
Escape JSON strings before trying to run JSON.parse
/*
Escape JSON
*/
var escapeJSON = exports.escapeJSON = function(json) {
var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
var meta = { // table of character substitutions
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
@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"
)