Skip to content

Instantly share code, notes, and snippets.

Avatar
🙏

Patrick Reagan reagent

🙏
View GitHub Profile
View 01-links.md
@reagent
reagent / vcr_strip_credentials_from_params.rb
Created Aug 8, 2019
Example of stripping credentials / sensitive data from GET params when using VCR (5.0.x)
View vcr_strip_credentials_from_params.rb
class URLSanitizer
def self.equal?(first, second)
new(first) == new(second)
end
def self.sanitize(url)
new(url).to_s
end
def initialize(url)
@reagent
reagent / migrator.rb
Created Nov 21, 2017
DIY migrations in Ruby
View migrator.rb
require 'pg'
require 'uri'
class Migrator
class Migration
def initialize(connection, path)
@connection, @path = connection, path
end
@reagent
reagent / 00_README.md
Last active Feb 5, 2021
Custom HTTP Routing in Go
View 00_README.md

Custom HTTP Routing in Go

Basic Routing

Responding to requests via simple route matching is built in to Go's net/http standard library package. Just register the path prefixes and callbacks you want invoked and then call the ListenAndServe to have the default request handler invoked on each request. For example:

package main

import (
View libcurl-curb-installation.md

Installing libcurl with Updated OpenSSL Support

If your Linux distribution is so out of date that you can no longer install updated patches, you'll typically need to either reach for an unsupported package or install the software via source. Additionally, I didn't want to interfere with installed software in fear of rendering the system unusable.

Become Root and Grab Tarballs

You're going to be installing stuff that requires root access, so it's easier to just be able to do it when you want without having to worry about using sudo and permissions. Be careful you don't delete anything you can't recover

$ sudo su - 
View check-gzip
#!/usr/bin/env ruby
url = ARGV.pop
if url.to_s.strip.length == 0
puts "Error: Please supply a URL"
exit 1
end
uncompressed_bytes = `curl "#{url}" --silent --write-out "%{size_download}\n" --output /dev/null`
@reagent
reagent / downgrade.sh
Last active Oct 30, 2019
Downgrade Apache + PHP on Ubuntu 14.04
View downgrade.sh
cat <<EOF >> /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu precise main restricted universe
deb http://archive.ubuntu.com/ubuntu precise-updates main restricted universe
deb http://security.ubuntu.com/ubuntu precise-security main restricted universe multiverse
EOF
apt-get update
apt-get purge \
apache2 \
@reagent
reagent / whitespace.sh
Last active Aug 15, 2019
Convert whitespace from tabs to 2 spaces
View whitespace.sh
#!/bin/bash
set -e # fail on nonzero status
cd $1
files=`find . \
-not \( -path ./vendor -prune \) \
-not \( -path ./tmp -prune \) \
-name '*.html' -o -name '*.js' -o -name '*.coffee' -o \
@reagent
reagent / .gitignore
Last active May 14, 2020
Curses Windowing Example
@reagent
reagent / .gitignore
Last active Dec 2, 2020
Curses + C Example