Skip to content

Instantly share code, notes, and snippets.

View longlostnick's full-sized avatar

Nick Larson longlostnick

View GitHub Profile
@longlostnick
longlostnick / cuid.sql
Created October 26, 2022 14:48 — forked from srfrog/cuid.sql
CUIDs for PL/PgSQL
-- Collision-resistant ids optimized for horizontal scaling and performance, for PL/PgSQL.
-- Based on https://github.com/ericelliott/cuid
-- Version 1.0.0
-- Usage: SELECT cuid();
-- BEGIN CONFIG ---
-- Put a unique host ID (int) here per server instance.
-- Once set, this value should not be changed.
@longlostnick
longlostnick / .vimrc
Last active December 20, 2021 23:19
My barebones .vimrc
"-----------------------------------------------------------------------------
" General Stuff
"-----------------------------------------------------------------------------
set nohls
set incsearch
" set the search scan so that it ignores case when the search is all lower
" case but recognizes uppercase if it's specified
set ignorecase
@longlostnick
longlostnick / git_author_stats.sh
Created January 11, 2019 04:57
Git stats by author
git log --shortstat --pretty="%cE" | sed 's/\(.*\)@.*/\1/' | grep -v "^$" | awk 'BEGIN { line=""; } !/^ / { if (line=="" || !match(line, $0)) {line = $0 "," line }} /^ / { print line " # " $0; line=""}' | sort | sed -E 's/# //;s/ files? changed,//;s/([0-9]+) ([0-9]+ deletion)/\1 0 insertions\(+\), \2/;s/\(\+\)$/\(\+\), 0 deletions\(-\)/;s/insertions?\(\+\), //;s/ deletions?\(-\)//' | awk 'BEGIN {name=""; files=0; insertions=0; deletions=0;} {if ($1 != name && name != "") { print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net"; files=0; insertions=0; deletions=0; name=$1; } name=$1; files+=$2; insertions+=$3; deletions+=$4} END {print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net";}'
@longlostnick
longlostnick / authorized_keys.md
Last active October 30, 2017 05:40
Simple set of bash scripts for uploading public keys to remote servers via GitHub usernames

authorized_keys

A method for managing and giving team members access to remote servers without needing to pass around the master .pem key. Generates and sends authorized key files to a list of hosts based on a set of permissions.

fetch_keys_from_github.sh

Generates a new keys/*.txt file for each user defined in permissions.txt when one doesn't already exist. Gets the list by calling out to https://github.com/<user>.keys. After first fetching a set of keys, the list can be paired down if necessary before running upload_keys.sh.

./fetch_keys_from_github.sh
@longlostnick
longlostnick / page_scraper.py
Last active August 10, 2017 18:18
Scrape a list of urls from a file
import io
import urllib.request
opener = urllib.request.FancyURLopener({})
pages_to_scrape = []
file = open("/Users/<user>/Downloads/random_slugs.txt", "r")
pages_to_scrape = file.readlines()
for url in pages_to_scrape:
@longlostnick
longlostnick / Dockerfile
Created August 6, 2017 21:51 — forked from yefim/Dockerrun.aws.json
Build a Docker image, push it to AWS EC2 Container Registry, then deploy it to AWS Elastic Beanstalk
# Example Dockerfile
FROM hello-world
@longlostnick
longlostnick / log_exceptions.rb
Created May 12, 2017 21:23
Ruby logger helper method for friendly logging of exceptions with stack trace.
class Logger
def exception(e, level=:error)
self.send level, "#{e.inspect} #{e.message}"
self.send level, " #{e.backtrace.first(25).join("\n ")}"
end
end
@longlostnick
longlostnick / splunk_to_slack.js
Created February 10, 2017 01:35
Transform a Splunk webhook and send to Slack
var util = require("util");
var https = require("https");
var title_template = "Alert - <%s|%s>";
var body_template = "\`\`\`%s\`\`\`";
var request_options = {
hostname: 'hooks.slack.com',
path: '<slack_url>',
method: 'POST',
@longlostnick
longlostnick / oauth_dance.rb
Created August 27, 2016 19:29
Quick script for OAuth2 dancin'
require 'oauth2'
client_id = ''
client_secret = ''
login_server = 'https://test.salesforce.com'
redirect_uri = 'https://login.salesforce.com/services/oauth2/callback'
client = OAuth2::Client.new(
client_id,
client_secret,

Setting up a WordPress site on AWS

This tutorial walks through setting up AWS infrastructure for WordPress, starting at creating an AWS account. We'll manually provision a single EC2 instance (i.e an AWS virtual machine) to run WordPress using Nginx, PHP-FPM, and MySQL.

This tutorial assumes you're relatively comfortable on the command line and editing system configuration files. It is intended for folks who want a high-level of control and understanding of their infrastructure. It will take about half an hour if you don't Google away at some point.

If you experience any difficulties or have any feedback, leave a comment. 🐬

Coming soon: I'll write another tutorial on a high availability setup for WordPress on AWS, including load-balancing multiple application servers in an auto-scaling group and utilizing RDS.