Skip to content

Instantly share code, notes, and snippets.

View jiggneshhgohel's full-sized avatar

Jignesh Gohel jiggneshhgohel

  • India
View GitHub Profile
@Integralist
Integralist / Ruby Splats.rb
Last active October 8, 2015 12:40
Ruby Splat (single and double)
# When calling a method with a splat then the parameters are passed as a comma separated list
# When receiving arguments with a splat then they are converted into an Array
# When using a double splat (2.0+) then the argument is converted into a Hash (i.e. named parameters)
def foo(*args)
p args
end
foo 'a', 'b', 'c'
# => ["a", "b", "c"]
@iamatypeofwalrus
iamatypeofwalrus / stacktrace.md
Last active July 28, 2023 13:07
Print stacktrace without raising and Exception in Ruby and/or Rails

Print a stacktrace in Ruby or Rails without raising an exception

Why

You know what method is being and you want to figure out how it got there. Raising an exception is a bit harsh since all you want is a stack trace

How

puts caller

Seriously. It's that easy. If you're getting too much information you could

@justinweiss
justinweiss / filterable.rb
Last active January 11, 2024 07:28
Filterable
# Call scopes directly from your URL params:
#
# @products = Product.filter(params.slice(:status, :location, :starts_with))
module Filterable
extend ActiveSupport::Concern
module ClassMethods
# Call the class methods with names based on the keys in <tt>filtering_params</tt>
# with their associated values. For example, "{ status: 'delayed' }" would call
@WizardOfOgz
WizardOfOgz / gist:1012107
Created June 7, 2011 12:13
Save Base64-encoded images with Paperclip
class Avatar < ActiveRecord::Base
attr_accessor :content_type, :original_filename, :image_data
before_save :decode_base64_image
has_attached_file :image,
PAPERCLIP_CONFIG.merge(
:styles => {
:thumb => '32x32#',
:medium => '64x64#',