Skip to content

Instantly share code, notes, and snippets.

View mwpastore's full-sized avatar

Mike Pastore mwpastore

  • Chicago, Illinois
View GitHub Profile
@mwpastore
mwpastore / ember-cli-deploy-redis-sinatra.rb
Last active February 25, 2016 17:20
A slightly more sophisticated Sinatra example for ember-cli-deploy
require 'sinatra'
require 'redis'
configure do
# Define your Redis connection, key prefix, and revision preview query parameter here!
set :redis, Redis.new
set :prefix, 'foo:index'
set :param_key, 'preview'
end
@mwpastore
mwpastore / benchmark_inject.rb
Created November 3, 2015 06:59
Bechmark inject with symbol vs. & (to_proc)
require 'fruity'
ints = (0..9_999_999).to_a
compare do
block { ints.reduce(0, &:+) }
symbol { ints.reduce(0, :+) }
end
# $ rbenv version
@mwpastore
mwpastore / Rakefile.rb
Last active November 13, 2015 17:43
Rakefile task for Puma with Rerun
require 'bundler/setup'
namespace :server do
desc 'Start the Puma webserver in development mode (rerun, debug).'
task :debug do
# Delay requiring these to avoid Rake failures in production.
require 'file-tail'
require 'rerun'
require 'tempfile'
@mwpastore
mwpastore / workaround.md
Last active November 12, 2015 00:01
Workaround for installing ember-cli@1.13.10 in Node 4.2 with NPM 3.2

Setup:

  1. npm uninstall -g ember-cli # Remove old global ember-cli
  2. npm cache clean # Clear NPM cache
  3. bower cache clean # Clear Bower cache
  4. npm install -g ember-cli@1.13.10 --rollback false # Begin the ember-cli install
  5. cd $(npm config get prefix)/lib/node_modules/ember-cli
  6. npm install --save-dev tap-parser@1.2.2 # Install the missing package
  7. cd -
  8. npm install -g ember-cli@1.13.10 # Resume the ember-cli install
@mwpastore
mwpastore / sinatra.rb
Created November 25, 2015 22:46
Sinatra with caching example
require 'sinatra/base'
require 'concurrent'
class App < Sinatra::Application # or ::Base for fewer features
configure do
set :cache, Concurrent::Hash.new(0)
end
get '/?:word?' do
word = params[:word]
@mwpastore
mwpastore / ember-cli-deploy-mysql-sinatra.rb
Last active February 25, 2016 17:21
Sinatra example for ember-cli-deploy-mysql
require 'sinatra'
require 'sequel'
require 'mysql2'
configure do
# Define your database, table, and revision preview query parameter here!
set :database, Sequel.connect ENV.fetch('DATABASE_URL')
set :table, :foo_bootstrap
set :param_key, 'preview'
end

Keybase proof

I hereby claim:

  • I am mwpastore on github.
  • I am mwp (https://keybase.io/mwp) on keybase.
  • I have a public key ASB0_zpx5r3l4WAJjekRQSX-c28UMvN4twlq6XzVUd92dwo

To claim this, I am signing this object:

@mwpastore
mwpastore / .env
Last active October 1, 2016 21:36
Mailgun delivery method for Ruby Mail gem
MAILGUN_DOMAIN=sandboxwhatevs.mailgun.org
MAILGUN_API_KEY=key-whatevs
@mwpastore
mwpastore / 00README.md
Last active April 18, 2024 06:21
Lightning Fast WordPress: Caddy+Varnish+PHP-FPM

README

This gist assumes you are migrating an existing site for www.example.com — ideally WordPress — to a new server — ideally Ubuntu Server 16.04 LTS — and wish to enable HTTP/2 (backwards compatibile with HTTP/1.1) with always-on HTTPS, caching, compression, and more. Although these instructions are geared towards WordPress, they should be trivially extensible to other PHP frameworks, other FastCGI backends, and even non-FastCGI backends (using proxy in lieu of fastcgi in the terminal Caddyfile stanza).

Quickstart: Use your own naked and canonical domain names instead of example.com and www.example.com and customize the Caddyfile and VCL provided in this gist to your preferences!

These instructions target Varnish Cache 4.1, PHP-FPM 7.0, and Caddy 0.10. (I'm using MariaDB 10.1 as well, but that's not relevant to this guide.)

test.os.lower() = linux test.database_os.lower() = linux
self.results['frameworks'] != None: True
test.name: sinatra-sequel-postgres-passenger-mri
self.results['completed']: {}
================================================================================
Beginning sinatra-sequel-postgres-passenger-mri
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Starting sinatra-sequel-postgres-passenger-mri
--------------------------------------------------------------------------------