Skip to content

Instantly share code, notes, and snippets.

# 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"
@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
# 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
# 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)
# 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
# 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
# ISSUE: https://github.com/jruby/jruby/issues/405
# In JRuby, FileUtils.remove_entry_secure(dir) crashes when a dir is under
# a world-writable directory because it tries to open directory.
# Opening directory is not allowed in Java.
# -- https://github.com/jruby/jruby/blob/1.7.0/lib/ruby/1.9/tmpdir.rb#L25-L28
#[1] pry(main)> Dir.tmpdir
# encoding: utf-8
# https://github.com/mongodb/mongoid/blob/4789bfffd3cbfa065eb7be7f34fbac122278a0ae/lib/mongoid/criteria.rb#L324
require "mongoid/criteria"
module Mongoid
class Criteria
OnlyWhenDefaultScopeError = Class.new(StandardError)
# encoding: utf-8
module ImplicitConnectionForbidder
def self.forbid_implicit_connections
yield
end
end
# http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html#method-i-with_connection
# http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html#method-i-release_connection
# encoding: utf-8
require "active_record/log_subscriber"
require "logger"
module ActiveRecord
class LogSubscriber
NULL_LOGGER = ::Logger.new(nil)
def logger