Skip to content

Instantly share code, notes, and snippets.

Nick Larson ifightcrime

Block or report user

Report or block ifightcrime

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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 Oct 30, 2017
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 Aug 10, 2017
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 Aug 6, 2017 — forked from yefim/Dockerfile
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
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 Feb 10, 2017
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 Aug 27, 2016
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.

@ifightcrime
ifightcrime / migrate_redis.rb
Created Jun 27, 2016
Migrate redis key/values by key match
View migrate_redis.rb
require 'redis'
redisSrc = Redis.connect url: "redis://<src>:6379"
redisDest = Redis.connect url: "redis://<dest>:6379"
redisSrc.keys("*").each do |key|
begin
data = redisSrc.dump key
ttl = redisSrc.pttl key # milleseconds
redisDest.restore key, ttl, data
@ifightcrime
ifightcrime / values_pointers.go
Created Apr 5, 2016 — forked from josephspurrier/values_pointers.go
Golang - Asterisk and Ampersand Cheatsheet
View values_pointers.go
/*
********************************************************************************
Golang - Asterisk and Ampersand Cheatsheet
********************************************************************************
Also available at: https://play.golang.org/p/lNpnS9j1ma
Allowed:
--------
p := Person{"Hillary", 28} stores the value
You can’t perform that action at this time.