Skip to content

Instantly share code, notes, and snippets.

View grosser's full-sized avatar
🎯
Focusing

Michael Grosser grosser

🎯
Focusing
View GitHub Profile

Ever wondered how much who adds/removes, its time to find out :D (those are real stats, i just obfuscated the names )

###Results

Git scores (in LOC):
mr-add              :  +482273       -9466
justu               :  +286250       -159905
grosser             :  +152384       -323344

another : +121257 -82116

begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "activerecord"
@grosser
grosser / rails_admin_without_devise.md
Last active July 27, 2016 06:25 — forked from huned/rails_admin_without_devise.md
Using RailsAdmin without devise

Using rails_admin without devise

Add RailsAdmin to your Gemfile

do NOT add devise

gem "rails_admin", :git => "git://github.com/sferik/rails_admin.git"

Bundle

@grosser
grosser / rake_autocomplete.rb
Created August 19, 2012 15:50 — forked from cayblood/rake_autocomplete.rb
Bash autocomplete script for rakefiles
#!/usr/bin/env ruby
# Complete rake tasks script for bash
# Save it somewhere and then add
# complete -C path/to/script -o default rake
# to your ~/.bashrc
# Xavier Shay (http://rhnh.net), combining work from
# Francis Hwang ( http://fhwang.net/ ) - http://fhwang.net/rb/rake-complete.rb
# Nicholas Seckar <nseckar@gmail.com> - http://www.webtypes.com/2006/03/31/rake-completion-script-that-handles-namespaces
# Saimon Moore <saimon@webtypes.com>
@grosser
grosser / rails_2_hacks.rb
Created January 14, 2014 19:53
hacks that help getting a rails 2 app run like a rails 3 app
# test
if Rails::VERSION::MAJOR == 2
# make integration tests use rack response, so we can test our middlewares
# and not only the pure controller response
ActionController::Base.class_eval do
# this is usually done just-in-time by #process but we need to do it earlier
include ActionController::Integration::ControllerCapture
# then we hide last_instantiation from #process
@grosser
grosser / unicorn_utils_sync_patch.rb
Created November 23, 2013 02:36
Make unicorn normally write to files even if they are not synced by @eac
# For Rails3, Rails.logger sync = false. Unicorn's log detection needs to accomodate this
module Unicorn
module Util
# :stopdoc:
def self.is_log?(fp)
append_flags = File::WRONLY | File::APPEND
! fp.closed? &&
fp.stat.file? &&
@grosser
grosser / audit.rb
Created July 12, 2013 01:43
Audit time taken by different methods
def audit(klass, method)
klass.class_eval do
define_method :"#{method}_with_audit" do |*args|
result = nil
time = Benchmark.realtime do
result = send(:"#{method}_without_audit", *args)
end
$time ||= {}
$time[klass] ||= {}
$time[klass][method] ||= 0
@grosser
grosser / lazydog.rb
Last active December 15, 2015 22:09
Non-blocking datadog metrics / reporting
require "dogapi"
require "celluloid/autostart"
require "singleton"
class LazyDog
include Celluloid
include Singleton
def emit_point(*args)
client.emit_point(*args)
@grosser
grosser / Gemfile
Last active December 12, 2015 01:08
Bundeling the same project with rails 2 and rails 3 (multiple gem versions but same gemfile) ``` ln -s Gemfile Gemfile.rails3 bundle BUNDLE_GEMFILE=Gemfile.rails3 bundle ``` using vendor/cache ? -> save disc space: ``` cd vendor/cache_rails3 ls ../cache | pru '%x{rm #{self} && ln -s ../cache/#{self}} if File.exist?(self)' ```
rails3 = ENV["BUNDLE_GEMFILE"].to_s.include?("rails3")
...
if rails3
# make bundler use a different cache dir
class << Bundler
def app_cache
root.join("vendor/cache_rails3")
end
@grosser
grosser / fix.rb
Last active December 11, 2015 02:59
Rails 2.3 fix for https://github.com/rails/rails/issues/8832 / CVE-2013-0155 prevent nil insertion, do a deep_munge for all non-browser input methods (which cannot produce empty hash or array or nil) ActiveRecord does not need the empty hash patch since e.g. `User.find_by_name({})` is ok
if Rails::VERSION::MAJOR == 2
ActionController::Base.class_eval do
def params_with_nil_fix
params = params_without_nil_fix
unless params.instance_variable_get(:@nil_fixed)
params.instance_variable_set(:@nil_fixed, true)
# normal form params cannot include nil/empty hash/empty array, just json/xml
deep_munge(params) unless ["application/x-www-form-urlencoded", "multipart/form-data", nil].include?(request.try(:content_type))
end