Skip to content

Instantly share code, notes, and snippets.

@reagent
reagent / .gitignore
Created April 1, 2013 14:51
Implementation of realloc / malloc
realloc
*.o
*.dSYM
@reagent
reagent / 00_README.md
Last active January 29, 2024 13:31
Custom HTTP Routing in Go

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 (
@reagent
reagent / .gitignore
Last active November 8, 2023 08:53
Curses Windowing Example
demo
*.swp
@reagent
reagent / etsy_verification_app.rb
Created November 7, 2010 02:26
A simple Sinatra app to test the OAuth callback functionality in Etsy. To use: 1. Install dependencies 2. Supply a valid api key & secret 3. Run `ruby etsy_verification_app.rb` 4. Point a browser to http://localhost:4567/
require 'rubygems'
require 'sinatra'
require 'etsy'
enable :sessions
Etsy.access_mode = :read_write
Etsy.api_key = "key"
Etsy.api_secret = "secret"
Etsy.callback_url = "http://localhost:4567/verify"
@reagent
reagent / .gitignore
Last active September 13, 2021 15:13
Curses + C Example
demo
*.swp
@reagent
reagent / 001_health_check.rb
Created November 21, 2012 16:12
Middleware Response Handler
class HealthCheck
class Middleware
def initialize(application)
@application = application
end
def call(environment)
if environment['PATH_INFO'] == '/health-check'
if HealthCheck.healthy?
@reagent
reagent / downgrade.sh
Last active October 30, 2019 16:35
Downgrade Apache + PHP on Ubuntu 14.04
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 August 15, 2019 03:27
Convert whitespace from tabs to 2 spaces
#!/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 / vcr_strip_credentials_from_params.rb
Created August 8, 2019 17:38
Example of stripping credentials / sensitive data from GET params when using VCR (5.0.x)
class URLSanitizer
def self.equal?(first, second)
new(first) == new(second)
end
def self.sanitize(url)
new(url).to_s
end
def initialize(url)