Skip to content

Instantly share code, notes, and snippets.

View allaire's full-sized avatar

Mathieu Allaire allaire

View GitHub Profile
@allaire
allaire / upload_erb.rb
Last active March 28, 2018 21:53
Capistrano 3 upload file from erb template
def template(from, to, options = {})
template_path = File.expand_path("../../templates/#{from}", __FILE__)
template = ERB.new(File.new(template_path).read).result(binding)
upload! StringIO.new(template), to, mode: 0644 # Otherwise it's set to 0640, which is not readable by other users (https://github.com/net-ssh/net-scp/blob/master/lib/net/scp/upload.rb#L63)
sudo "chown root:root #{to}" if options[:as_root]
end
node.default["postgresql"]["config"]["wal_level"] = "replica"
node.default["postgresql"]["config"]["max_wal_senders"] = 6
node.default["postgresql"]["config"]["wal_keep_segments"] = 120
node.default["postgresql"]["config"]["hot_standby"] = "on"
@allaire
allaire / curl-style.sh
Created March 2, 2017 14:07
Curl large style
~ $ curl -vv https://www.agendrix.com/wp-content/themes/agendrix/style.min.css\?ver\=1486665895
* Trying 162.216.18.169...
* TCP_NODELAY set
* Connected to www.agendrix.com (162.216.18.169) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
* Server certificate: *.agendrix.com
* Server certificate: COMODO RSA Domain Validation Secure Server CA
* Server certificate: COMODO RSA Certification Authority
> GET /wp-content/themes/agendrix/style.min.css?ver=1486665895 HTTP/1.1
> Host: www.agendrix.com
@allaire
allaire / web.pill
Last active March 22, 2016 15:39
Web app bluepill configuration file
ENV['RAILS_ENV'] = 'production'
web_path = '/home/deployer/apps/web/current'
Bluepill.application('web', :log_file => "#{web_path}/log/bluepill.log") do |app|
app.process('unicorn') do |process|
process.pid_file = "#{web_path}/tmp/pids/unicorn.pid"
process.working_dir = web_path
process.start_command = "/usr/local/bin/bundle exec unicorn -D -c #{web_path}/config/unicorn.rb -E #{ENV['RAILS_ENV']}"
@allaire
allaire / puma.rake
Created May 27, 2014 00:44
Puma with foreman upstart
namespace :load do
task :defaults do
set :puma_init_name, "#{fetch(:application)}-web"
set :puma_pid_path, "#{shared_path}/tmp/pids/puma.pid"
end
end
namespace :puma do
desc "Start puma workers"
task :start do
start on runlevel [2345]
stop on runlevel [06]
setuid deployer
setgid sysadmin
respawn
respawn limit 3 30
script
@allaire
allaire / capistrano-template.rb
Created November 4, 2013 03:27
Ryan Bates template method adapted for Capistrano v3
def template(from, to)
template_path = File.expand_path("../templates/#{from}", __FILE__)
template = ERB.new(File.new(template_path).read).result(binding)
upload! StringIO.new(template), to
end
# Encoding: UTF-8
SIG_REGEX = /(--|__|\w-$)|(^(\w+\s*){1,3} #{"Sent from my".reverse}$)|(^(\w+\s*){1,3} #{"Envoyé de mon".reverse}$)/n
has a non escaped non ASCII character in non ASCII-8BIT script (RegexpError)
PgSearch.multisearch_options = {
:using => { tsearch: { prefix: true } }
}
module PgSearch
class Document < ActiveRecord::Base
before_save do
self.organization_id = searchable.organization_id
end
end
@allaire
allaire / test.rake
Last active December 15, 2015 16:19
Rakefile
require 'rake/testtask'
Rake::TestTask.new('test:models' => ['db:test:prepare', 'db:seed']) do |t|
t.pattern = 'test/models/**/*_test.rb'
end
Rake::TestTask.new('test:controllers' => ['db:test:prepare', 'db:seed']) do |t|
t.pattern = 'test/controllers/**/*_test.rb'
end