Skip to content

Instantly share code, notes, and snippets.

View elithrar's full-sized avatar
🌐
Helping make the Internet better.

Matt Silverlock elithrar

🌐
Helping make the Internet better.
View GitHub Profile
package main
import (
"fmt"
"log"
"net/http"
"html/template"
"github.com/gorilla/sessions"
import (
"fmt"
"html/template"
"net/http"
"github.com/oxtoacart/bpool"
)
var bufpool *bpool.BufferPool
https://docs.google.com/presentation/d/1GXCaoat2CEcPu9lJ9eJDjzVW_Vuqr-Yq7kJolfOpBG0/edit?usp=sharing
@elithrar
elithrar / get-local-api.js
Last active July 16, 2023 14:44
A Scriptable powered iOS 14 widget (https://docs.scriptable.app/) using JavaScriptCore to get the current AQI from a PurpleNow sensor: https://fire.airnow.gov/
const API_URL = "https://www.purpleair.com/json?show=";
// Params: lat, lng, zoom
const MAP_URL = "https://fire.airnow.gov/"
// const CACHE_FILE = "aqi_data.json"
// Find a nearby PurpleAir sensor ID via https://fire.airnow.gov/
// Click a sensor near your location: the ID is the trailing integers
// https://www.purpleair.com/json has all sensors by location & ID.
let SENSOR_ID = args.widgetParameter || "19066"
const HEADER_COLOR = "#222222"
@elithrar
elithrar / use.go
Last active January 5, 2023 11:19
go/use: Little middleware chains that could. Inspired by comments here: https://github.com/gorilla/mux/pull/36
r := mux.NewRouter()
// Single handler
r.HandleFunc("/form", use(http.HandlerFunc(formHandler), csrf, logging)
// All handlers
http.Handle("/", recovery(r))
// Sub-routers
apiMiddleware := []func(http.Handler) http.Handler{logging, apiAuth, json}
@elithrar
elithrar / query.sql
Last active May 30, 2022 23:56
Using BigQuery to find public GitHub READMEs (readme%) with "blazing" in the contents: via https://twitter.com/peterbourgon/status/1039902928151052288
SELECT
repo_name,
path
FROM (
SELECT
id,
repo_name,
path
FROM
`bigquery-public-data.github_repos.files`
@elithrar
elithrar / supervisord.conf
Last active September 4, 2021 20:08
Example supervisord.conf for a Go application #golang
[unix_http_server]
file=/var/run/supervisor.sock
chmod=0770
chown=root:supervisor
[supervisord]
pidfile=/var/run/supervisord.pid
nodaemon=false
logfile=/var/log/supervisord/supervisord.log
loglevel=error
@elithrar
elithrar / authserver.go
Last active June 30, 2021 07:12
HTTP Basic Auth example in Go (based on http://stackoverflow.com/a/21937924/556573 + bespoke middleware implementation)
package main
import (
"encoding/base64"
"github.com/gorilla/mux"
"net/http"
"strings"
)
func main() {
@elithrar
elithrar / wale_postgres_recovery.md
Last active May 3, 2021 15:38
WAL-E + Postgres 9.x (single server + DB) Setup and Recovery

A quick "how to" on what you need to do to both setup AND recover a single-server PostgreSQL database using WAL-E

  • WAL-E: https://github.com/wal-e/wal-e
  • Assuming Ubuntu 12.04 LTS ("Precise")
  • We'll be using S3. Make sure you have an IAM in a group with GetObject, ListBucket and PutObject on the bucket you want to use (and that it's not public).

Setup:

  1. These packages:
@elithrar
elithrar / .travis.yml
Last active September 13, 2020 21:29
CircleCI vs. TravisCI for gorilla/mux - comparing maintainability, verbosity, DRY, etc. Ref: https://twitter.com/elithrar/status/1140342082768261120 & https://blog.questionable.services/article/building-go-projects-on-circle-ci/
language: go
matrix:
include:
- go: 1.7.x
- go: 1.8.x
- go: 1.9.x
- go: 1.10.x
- go: 1.11.x