Skip to content

Instantly share code, notes, and snippets.

View marcusg's full-sized avatar
🏠
Working from home

Marcus Geißler marcusg

🏠
Working from home
View GitHub Profile
@brianhempel
brianhempel / bench_rails_memory_usage.rb
Last active October 6, 2022 12:47
A script to test the memory usage of your Rails application over time. It will run 30 requests against the specified action and report the final RSS. Choose the URL to hit on line 45 and then run with `ruby bench_rails_memory_usage.rb`.
require "net/http"
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
XRUBY_GC_HEAP_FREE_SLOTS=4096
XRUBY_GC_HEAP_INIT_SLOTS=10000
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with :truncation
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
@Neil-Aframe
Neil-Aframe / app.rb
Created March 14, 2013 13:25
Example, non-working, attempt to use nesteed mounts in Grape for DRY design with multiple paths to same resources
require "grape"
# Example attempt to do nested mounting. The real-world case is for a resource which can be
# addressed in multiple ways, and I want a DRY design where groups define the parameters to address
# an item, but the manipulations possible are the same, and defined by the http verb, so should be
# in one place (class Thing in this example to read a "thing" resource)
class Thing < Grape::API
get do
{ :message => 'You found the thing!' }
end
@orlando
orlando / activeadmin-cancan.rb
Created November 25, 2012 01:54
Deep integration of CanCan into ActiveAdmin
# blog post:
# Before using this initializer, you must set up Cancan. First, add the gem to your Gemfile:
#
# gem 'cancan'
#
# Next, generate and edit an Ability class:
#
# rails generate cancan:ability
#
@bbonamin
bbonamin / drag_drop.rb
Created July 17, 2012 14:18
Capybara drag and drop
shared_examples_for "driver with javascript support" do
before { @driver.visit('/with_js') }
describe '#find' do
it "should find dynamically changed nodes" do
@driver.find('//p').first.text.should == 'I changed it'
end
end
describe '#drag_to' do
@robertjwhitney
robertjwhitney / activeadmin_sortable.js.coffee
Created July 3, 2012 03:37
Simple drag/drop reordering of records in an ActiveAdmin view table
# http://stackoverflow.com/a/8936202
#
# ActiveAdmin already includes the necessary jquery in active_admin/base,
# so just add this to javascripts/active_admin.js after //= require active_admin/base
#
#
# Serialize and Sort
#
# model_name - you guessed it, the name of the model we are calling sort on.
# This is the actual variable name, no need to change it.
1.9.3p0 :001 > User.first./home/esalazar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb/completion.rb:182:in `block (2 levels) in <module:InputCompletor>': can't convert Regexp to String (TypeError)
from /home/esalazar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb/completion.rb:175:in `each_object'
from /home/esalazar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb/completion.rb:175:in `block in <module:InputCompletor>'
from /home/esalazar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb/input-method.rb:115:in `call'
from /home/esalazar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb/input-method.rb:115:in `readline'
from /home/esalazar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb/input-method.rb:115:in `gets'
from /home/esalazar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb.rb:139:in `block (2 levels) in eval_input'
from /home/esalazar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb.rb:273:in `signal_status'
from /home/esalazar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/irb.rb:138:in `block in eval_input'
from /home/e
@chrisbloom7
chrisbloom7 / README.md
Created June 6, 2011 07:16
A cheap knock off of the default validates_length_of validator, but checks the filesize of a Carrierwave attachment

Note that this validation runs both after the file is uploaded and after CarrierWave has processed the image. If your base uploader includes a filter to resize the image then the validation will be run against the resized image, not the original one that was uploaded. If this causes a problem for you, then you should avoid using a resizing filter on the base uploader and put any specific size requirements in a version instead.

So instead of this:

require 'carrierwave/processing/mini_magick'