Skip to content

Instantly share code, notes, and snippets.

Getting sh*t done

Clemens Kofler clemens

Getting sh*t done
View GitHub Profile
View kwargs.rb
h = { a: 1, b: 2 }
def foo(a:, b:)
[a, b]
foo(h) #=> [1, 2]
View dynamic_operation_methods.rb
module Trailblazer; end
module My; end
class Trailblazer::Operation
def self.inherited(klass)
*mod_names, klass_name ='::')
mod = const_get(mod_names.join('::'))
mod.define_singleton_method(klass_name) do |*args|
View imagemagick-output.txt
tmp[master]% convert logo.jpg -format png -colorspace srgb -profile ../vendor/profiles/sRGBColorSpaceProfile.icm logo.png
tmp[master]% rm logo.png
tmp[master]% cp logo.jpg logo.png
tmp[master]% mogrify -format png -colorspace srgb -profile ../vendor/profiles/sRGBColorSpaceProfile.icm logo.png
mogrify: improper image header `../vendor/profiles/sRGBColorSpaceProfile.icm' @ error/png.c/ReadPNGImage/3981.
View log.txt
2016-08-01T09:24:58.489044+00:00 heroku[router]: at=info method=GET path="/" request_id=e8e2f6a9-b50b-4054-8efc-fb35457558e6 fwd="" dyno=web.1 connect=0ms service=16ms status=302 bytes=1389
View animation.css
@keyframes animation-1 {
/* whatever */
@keyframes animation-2 {
/* whatever */
@keyframes animation-3 {
/* whatever */
View sti.sql
ALTER TABLE accounts ADD CONSTRAINT valid_sti_type CHECK (type IN ('STIClass1', 'STIClass2'));
View ability_with_callable_policy_object.rb
class AgencyVisitPolicy
def initialize(user)
@user = user
def to_proc { |visit|[@user.agency_id, nil]) }
View indexes.rb
pp ActiveRecord::Base.connection.select_all("SHOW INDEXES FROM spree_paypal_website_payments_standard_notifications")
=> [
clemens /
Last active Aug 29, 2015
Problems without using instance variables to hand data from a Rails controller to a view

This is the first time I've run into an issue like this.

I've been using focused_controller in some projects and in others I've just extracted the expose method (see below). Everything was always fine.

Now in a CRM app I have a CommentsController that handles comments for multiple commentable resources – e.g. a contact. The comment form is currently always displayed on the resource's show page. So in case of errors (e.g. empty comment text), the commentable's show template is the one that needs to be re-rendered in order to properly show error messages. I don't want to do ugly stuff like redirect with error messages in the GET parameters or put something in the session.

As it stands, I found two solutions that actually work and allow me to use contact (as a method call) in the show template:

  • Use a combination of instance_variable_set/get/defined?. Remember: the commentable is essentially polymorphic so I have to set the name dynamically.
clemens / calendar_week.rb
Created Nov 24, 2014
A simple class wrapping a calendar week
View calendar_week.rb
class CalendarWeek
attr_reader :week, :year, :date
private :date
def self.current
def self.for_date(date)
new(date.year, date.cweek)
You can’t perform that action at this time.