Skip to content

Instantly share code, notes, and snippets.

Avatar

Nick Larson ifightcrime

View GitHub Profile
@ifightcrime
ifightcrime / cuid.sql
Created October 26, 2022 14:48 — forked from srfrog/cuid.sql
CUIDs for PL/PgSQL
View cuid.sql
-- 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.
@ifightcrime
ifightcrime / .vimrc
Last active December 20, 2021 23:19
My barebones .vimrc
View .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
@ifightcrime
ifightcrime / git_author_stats.sh
Created January 11, 2019 04:57
Git stats by author
View git_author_stats.sh
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";}'
@ifightcrime
ifightcrime / 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
View authorized_keys.md

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
@ifightcrime
ifightcrime / page_scraper.py
Last active August 10, 2017 18:18
Scrape a list of urls from a file
View page_scraper.py
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:
@ifightcrime
ifightcrime / 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
View Dockerfile
# Example Dockerfile
FROM hello-world
@ifightcrime
ifightcrime / log_exceptions.rb
Created May 12, 2017 21:23
Ruby logger helper method for friendly logging of exceptions with stack trace.
View log_exceptions.rb
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
@ifightcrime
ifightcrime / splunk_to_slack.js
Created February 10, 2017 01:35
Transform a Splunk webhook and send to Slack
View splunk_to_slack.js
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',
@ifightcrime
ifightcrime / oauth_dance.rb
Created August 27, 2016 19:29
Quick script for OAuth2 dancin'
View oauth_dance.rb
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,
View gist:9b2b5a4d28e76c12d9892223cf22de7a

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.