Skip to content

Instantly share code, notes, and snippets.

View seanhandley's full-sized avatar
🧀
Eating cheese

Sean Handley seanhandley

🧀
Eating cheese
View GitHub Profile
@seanhandley
seanhandley / 1 sources.list
Last active October 18, 2015 08:41
Enable HTTP2 in NginX on Ubuntu
# ...
deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ trusty nginx
# Where 'trusty' is the Ubuntu release codename (see `cat /etc/lsb-release`)
@seanhandley
seanhandley / assets.rb
Created October 12, 2015 14:02
Additional JS Manifests
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path
# Rails.application.config.assets.paths << Emoji.images_path
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
@seanhandley
seanhandley / nginx.conf
Created October 12, 2015 13:53
NginX Cache Headers
server {
# ...
# Feed
location ~* \.(?:rss|atom)$ {
expires 1h;
add_header Cache-Control "public";
}
# Media: images, icons, video, audio, HTC
@seanhandley
seanhandley / nginx.conf
Last active October 12, 2015 14:16
NginX GZIP
# ...
http {
# ...
##
# Gzip Settings
##
@seanhandley
seanhandley / production.rb
Created October 12, 2015 13:48
Minify CSS and JS
Rails.application.configure do
# ...
# Compress JavaScripts and CSS.
config.assets.css_compressor = :sass
config.assets.js_compressor = :uglifier
# ...
end
@seanhandley
seanhandley / deploy.sh
Last active October 12, 2015 13:45
Separate Assets Host
# Use rsync during your deployment process to sync
rake assets:precompile
rsync -avzhe ssh /home/rails/my_app/public/* user@assets.example.com:/public_html/
# Now your Rails app will fetch assets from the assets server
@seanhandley
seanhandley / nginx.conf
Created October 12, 2015 13:29
NginX with Unicorn
server {
listen 80;
server_name www.example.com;
return 301 https://example.com$request_uri;
}
upstream rails_app {
server unix:/var/run/rails/my_app/unicorn.sock fail_timeout=0;
}
@seanhandley
seanhandley / unicorn.rb
Created October 12, 2015 13:23
Unicorn Config
# Sample verbose configuration file for Unicorn (not Rack)
#
# This configuration file documents many features of Unicorn
# that may not be needed for some applications. See
# http://unicorn.bogomips.org/examples/unicorn.conf.minimal.rb
# for a much simpler configuration file.
#
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
# documentation.
@seanhandley
seanhandley / cache_fetch.rb
Last active October 14, 2015 20:31
Cache fetch
# This is a handy pattern for handling slow computations like API calls
def slow_results
Rails.cache.fetch("slow_api_results", expires_in: 10.minutes) do
slow_api_call
end
end
slow_results # Takes a few seconds to load first time
# => "Lorem ipsum..."
Thread ID: 21277412
%self cumulative total self children calls self/call total/call name
46.34 4.06 8.72 4.06 4.66 501 0.01 0.02 Integer#upto
23.89 6.16 2.09 2.09 0.00 61 0.03 0.03 Kernel.sleep
15.12 7.48 1.33 1.33 0.00 250862 0.00 0.00 Fixnum#%
14.13 8.72 1.24 1.24 0.00 250862 0.00 0.00 Fixnum#==
0.18 8.74 0.02 0.02 0.00 1 0.02 0.02 Array#each_index
0.17 8.75 6.64 0.01 6.63 500 0.00 0.01 Object#is_prime
0.17 8.77 6.66 0.01 6.64 1 0.01 6.66 Array#select
0.00 8.77 0.00 0.00 0.00 501 0.00 0.00 Fixnum#-