Skip to content

Instantly share code, notes, and snippets.

# encoding: utf-8
# In JRuby, Tempfile is implemented in Java. We were able to improve the performance substantially,
# and avoid the buggy stdlib version in the process.
# -- Nick Sieger
# http://stackoverflow.com/questions/1466460/jruby-tempfile-rb
# JRuby: Tempfile.new('p').path => "/tmp/p.4642.20811"
# 1.9.3: Tempfile.new('p').path => "/tmp/p20120426-4327-19gcrqi"
# encoding: utf-8
# config/initializers/active_record_disconnect.rb
# Disconnect after intialization.
# Helpful for TorqueBox keeping connection for each
# runtime even when it is not used.
#
# $ rails c
# [1] > ActiveRecord::Base.connection_pool.connections.size
# => 0
# encoding: utf-8
# config/initializers/torquebox-backstage.rb
# WARN: tilt autoloading 'tilt/haml' in a non thread-safe way; explicit require 'tilt/haml' suggested.
# WARN: tilt autoloading 'tilt/sass' in a non thread-safe way; explicit require 'tilt/sass' suggested.
require "tilt/haml"
require "tilt/sass"
# https://github.com/rails/rails/issues/15843
Backstage::Application.disable(:sessions)
# config/application.rb
['md5sum', 'convert', 'mogrify', 'identify', 'file'].each do |app|
`command -v #{app} > /dev/null 2>&1`
next if $?.exitstatus == 0
abort "ERROR: command #{app.inspect} not found"
end
@kml
kml / get-revision.rb
Created December 13, 2016 23:14
/revision
# config/routes.rb
REVISION = Rails.root.join('REVISION').exist? ? Rails.root.join('REVISION').read.chomp.strip : nil
Rails.application.routes.draw do
get 'revision' => proc { |_env| [200, {'Content-Type' => 'text/plain'}, [REVISION.to_s]] }
end
# Usage:
# bind "tcp://127.0.0.1:5000"
# activate_control_app "tcp://127.0.0.1:9293", auth_token: "foo"
#
# curl -v http://127.0.0.1:5000/ping
# curl -v http://127.0.0.1:9293/ping/disable?token=foo
# curl -v http://127.0.0.1:9293/ping/enable?token=foo
# https://github.com/puma/puma/blob/master/lib/puma/app/status.rb
require "puma/app/status"