Skip to content

Instantly share code, notes, and snippets.

Roman Le Négrate Roman2K

Block or report user

Report or block Roman2K

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:15677
#!/usr/bin/env ruby
# Sort entries by content size. Usage:
# sortbysize [<directory>='.']
#
# This script is documented at:
# http://roman.flucti.com/sorting-directories-by-content-size-with-ruby
#
class Entry < Struct.new(:size, :unit, :name)
@Roman2K
Roman2K / gist:16852
Created Oct 15, 2008
Test helper for painless record creation
View gist:16852
# Test helper for painless record creation. Details at:
# http://roman.flucti.com/painless-record-creation-with-activerecord
#
def insert!(model, attributes={})
attributes = attributes.stringify_keys
begin
record = model.new(attributes)
def record.callback(*args)
# inhibit all callbacks
end
View gist:25513
# Untested
module WithLogger
attr_writer :logger
def logger
@logger ||= Rails.logger
end
end
SomeClass.extend WithLogger
View gist:25514
def nil_blank_count(object)
object.attributes.values.select(&:present?).size
end
View post.rb
class Post < ActiveRecord::Base
validates_length_of :title, :minimum => 4
def custom_method
title.scan(/./).join(' ').upcase
end
end
View gist:26647
def insert!(model, attributes={})
attributes = attributes.stringify_keys
begin
record = model.new {|r| r.send(:attributes=, attributes, false) }
def record.callback(*args)
# inhibit all callbacks
end
record.save(false)
rescue ActiveRecord::StatementInvalid
if $!.message =~ /Column '(.+?)' cannot be null/
View gist:39131
From 3014a599a158c7ef1332bf3dbc6ca25c015c618e Mon Sep 17 00:00:00 2001
From: Roman Le Negrate <roman.lenegrate@gmail.com>
Date: Mon, 22 Dec 2008 22:30:20 +0100
Subject: [PATCH] only include acts-like-git specific modules when versioning gets configured
---
lib/acts_like_git.rb | 7 +------
lib/acts_like_git/active_record_ext/base.rb | 4 ++++
2 files changed, 5 insertions(+), 6 deletions(-)
View gist:55833
some.code(before)
eval(Pathname(__FILE__).dirname.join('_bar.pdf.prawn').read)
some.code(after)
View gist:55835
def show
# ...
send_file_headers! \
:disposition => 'attachment', :filename => "foo-#{@foo.to_param}.pdf",
:type => Mime::PDF, :length => false
end
View gist:55837
bounding_box [100, 600], :width => 200 do
text "The rain in spain falls mainly on the plains " * 5
stroke do
line bounds.top_left, bounds.top_right
line bounds.bottom_left, bounds.bottom_right
end
end
You can’t perform that action at this time.