Skip to content

Instantly share code, notes, and snippets.

# Our own variable where we deploy this app to
deploy_to = "/srv/example.com"
current_path = "#{deploy_to}/current"
shared_path = "#{deploy_to}/shared"
shared_bundler_gems_path = "#{shared_path}/bundler_gems"
# See http://unicorn.bogomips.org/Sandbox.html
# Helps ensure the correct unicorn_rails is used when upgrading with USR2
Unicorn::HttpServer::START_CTX[0] = "#{shared_bundler_gems_path}/bin/unicorn_rails"
@enriclluelles
enriclluelles / gist:2775500
Created May 23, 2012 14:24
Multithreaded seeds
Rails.configuration.cache_classes = true
Rails.configuration.threadsafe!
Rails.configuration.allow_concurrency = true
require "#{Rails.root}/test/factories"
Dir.glob(File.join(Rails.root, 'app', '{lib,app}', '*.rb')).each{|f| require f}
Rails.application.eager_load!
puts "Creating users..."
users = []

simple.rb

code = <<END
class Adder
  def add_two(x)
    x+2
  end
end
@thom-nic
thom-nic / chunked_transfer_decoder.rb
Last active February 5, 2020 15:23
Rack middleware to decode chunked transfer HTTP request
#require 'rack/request'
# Rack middleware to decode a `Transfer-Encoding: chunked` HTTP request.
#
# USAGE NOTE:
#
# Some HTTP servers (Webrick and Unicorn/Rabinbows/Zbatery) already decode the
# chunked stream, but they leave the 'Transfer-Encoding' header and don't bother
# to add a 'Content-Length' header, which causes rails ActionDispatch::Request
# to not parse the whole request body.
@alexey
alexey / README_AA_CC_AASM.md
Last active August 7, 2020 08:34
ActiveAdmin + CanCan + AASM event switcher with AJAX

About:

Inspired by activeadmin_addons and its Enum Integration I want to make similar functionality for AASM by letting users change events depending on their abilities and available events/statuses in model.

Sorry i have no time to create an addon right now for this gem but i will try to do it soon. Feel free to modify, use it and integrate. Ask me any question if you need!

Prequestites:

Gem: ActiveAdmin,

@cesartalves
cesartalves / .env
Last active April 13, 2021 09:44
Rails Conf k8s quick setup
# https://github.com/ddollar/forego
ASSET_HOST=localhost:3000
APPLICATION_HOST=localhost:3000
BCRYPT_COST=12
PORT=3000
RACK_ENV=development
RACK_MINI_PROFILER=0
SECRET_KEY_BASE=development_secret
EXECJS_RUNTIME=Node
@ccschmitz
ccschmitz / data_migrations_in_rails.md
Created August 19, 2014 13:10
Some tips for handling data migrations in Rails

Data Migrations in Rails Apps

If you need to manipulate existing data when your code is deployed, there are two main ways to do it:

  1. Create a rake task to migrate the data after the code is deployed. This is ideal for more complex data migrations.
  2. Use ActiveRecord models in a migration. This is acceptable for smaller data manipulations.

Regardless of the method you use, make sure to test your migrations before submitting them.

Data Migrations in Models

@mudge
mudge / gist:428455
Created June 7, 2010 09:29
Namespaces with Nokogiri::Builder
# Dealing with namespaces in Nokogiri.
#
# First thing you must do is abandon what you're used to with Builder,
# namespaces aren't just attributes on an element, they uniquely identify
# what sort of element you are building and, as such, you are better off
# specifying them manually.
#
# The key here is accessing the Nokogiri::XML::Element being built with
# b.parent, then you can set the namespace (distinguished by an element
# with a prefix such as "soap12:Envelope") or add a default namespace
@morhekil
morhekil / anonsplat.rb
Created June 23, 2015 23:20
Destructuring Ruby hashes with named parameters and anonymous splat
def stuff
yield action: 'Boom', schedule: '7PM', color: :red, debug: true
end
# When a hash is yielded to a block, we can used named arguments to
# capture the keys we want, and an anonymous splat to ignore
# everything else
stuff { |action:, schedule:, **| p "Doing #{action} at #{schedule}" }
#
@robhurring
robhurring / Rakefile
Created December 7, 2010 20:09
Delayed Job with Sinatra -- without sinatra specific gems, etc.
task :environment do
require './dj-sinatra'
end
namespace :jobs do
desc "Clear the delayed_job queue."
task :clear => :environment do
Delayed::Job.delete_all
end