Skip to content

Instantly share code, notes, and snippets.

https://blog.codeship.com/producing-documentation-for-your-rails-api/
@docunext
docunext / contributions.txt
Created December 16, 2016 01:30
Contributions
https://git.kernel.org/cgit/git/git.git/commit/?id=246090a5d0ff3a51df8fed676e8159c3776c954a
https://git.kernel.org/cgit/git/git.git/commit/?id=897e3e454062d2bb9d3c1e4068caf4971fd713ff
https://git.kernel.org/cgit/git/git.git/commit/?id=a2f69581ffc26fadb27bc29dd03074791a16d61e
https://git.kernel.org/cgit/git/git.git/commit/?id=13f72a1d5faacfdfea43e2fd961cb4009206a605
http://contributors.rubyonrails.org/contributors/albert-lash/commits
@docunext
docunext / RAILS_ENV2Rails.env
Last active December 16, 2015 10:39
Change RAILS_ENV to Rails.env
for i in app config lib test; do grep -rl RAILS_ENV $i | awk '{print "sed -ri \"s/RAILS_ENV/Rails.env/g\" " $1 }' > com.sh && sh com.sh && rm com.sh; done
for i in app config lib test; do grep -rl RAILS_ROOT $i | awk '{print "sed -ri \"s/RAILS_ROOT/Rails.root/g\" " $1 }' > com.sh && sh com.sh && rm com.sh; done
for i in app config lib test; do grep -rlE " $" $i | awk '{print "sed -ri \"s/\ +$//g\" " $1 }' > com.sh && sh com.sh && rm com.sh; done
require 'active_support/concern'
module MiniController
extend ActiveSupport::Concern
included do
include AbstractController::Layouts
include ActionController::Helpers
include ActionController::UrlFor
set :stage, 'production'
set :shared_children, shared_children << 'tmp/sockets'
puma_sock = "unix://#{shared_path}/sockets/puma.sock"
puma_control = "unix://#{shared_path}/sockets/pumactl.sock"
puma_state = "#{shared_path}/sockets/puma.state"
puma_log = "#{shared_path}/log/puma-#{stage}.log"
namespace :deploy do
desc "Start the application"
# Thanks http://devblog.mixlr.com/2012/09/01/nginx-lua/
class CsrfTokenEndpoint
def self.call(env)
if env["PATH_INFO"] =~ /^\/csrf_token_endpoint/
session = env["rack.session"] || {}
token = session[:_csrf_token]
if token.nil?
token = SecureRandom.base64(32)
session[:_csrf_token] = token
@docunext
docunext / Gemfile
Last active December 15, 2015 08:59
Trying to make debian and rails4 play nicely.
source 'https://rubygems.org'
# Do not change - using system gems install by apt
group :debian do
gem 'pg', '0.13.2'
gem 'tilt', '1.3.3'
gem 'rdoc', '3.9.4'
gem 'erubis', '2.7.0'
gem 'tzinfo', '0.3.33'
@docunext
docunext / roary-snibbet.rb
Last active December 15, 2015 08:39
A snibbet of docunext/svxbox/lib/svxbox/roary.rb as an example of ActiveSupport::Concern.
module SvxBox::Roary
extend ActiveSupport::Concern
included do
cattr_accessor :param_suffix
before_validation :ensure_param_key_has_value, :if => :param_key_attribute?
validates :param_key, :presence => true, :uniqueness => true, :if => :param_key_attribute?
end
# ...
@docunext
docunext / redirect_to_tld.rb
Created September 6, 2012 18:49 — forked from stevenwilkin/redirect_to_tld.rb
Rack middleware to ensure all traffic is served from a canonical domain
# ensure all requests are served from a canonical top-level-domain
#
# the following in your config.ru will cause all traffic to stevenwilkin.co.uk to
# be redirected to stevenwilkin.com if both domains are served by the same app
#
# require 'redirect_to_tld'
# use RedirectToTLD, 'stevenwilkin.com'
#
class RedirectToTLD
# Hi! I'am rack middleware!
# I was born for show right way to you JavaScript
# My author's name was Aleksandr Koss. Mail him at kossnocorp@gmail.com
# Nice to MIT you!
require(File.dirname(__FILE__) + '/../config/environment') unless defined?(Rails)
class RoutesJs
def initialize app, options = {}