How to convert a decimal number to an integer only if the decimal places are 0
def lazy_decimal(num)
if (num.round - num) == 0
num.to_i
else
num
end
end
xvfb backround info
X Virtual Framebuffer
http://de.wikipedia.org/wiki/Xvfb
e.g. use it to create screenshots.
For a basic implementation, see this:https://github.com/leonid-shevtsov/headless/blob/master/lib/headless.rb
Working in Cucumber with New lines and have_content
Problem:
expected there to be content "\n2\n" in "\n2\n" (RSpec::Expectations::ExpectationNotMetError)
Research:
https://github.com/jnicklas/capybara/issues/56
Answer: WTF!
Solution:
page.find(".#{count_name}-count").text.strip.should == "\n#{count}\n"
Ruby Interactive Editor
just stumpled upon this in the redmine gemfile
Extracting the filename of a url, that can have additional params
/\/((?:[\w\-\_]+\.\w{3,4}))(?:\?.+)?$/
we_magazine
We – Manifesto
we observes and leads the way into a participatory future. ➟ we means emergent net culture. ➟ we is positively disruptive. ➟ we is an attitude. ➟ we means sharing. ➟ we means collaboration. ➟ webelieves in collective intelligence. ➟ we means holistic and network thinking. ➟ we is smart because of the network of “Yous”. ➟ we is more than you & I. ➟ we means responsibility. ➟ we doesn’t mean control. ➟ we means a real change in power. ➟ we doesn’t mean copyright but creative commons. ➟we is diversity and harmony. ➟ we means partnership. ➟ we connects people, ideas and thoughts around the globe. ➟ we is authentic, humane, creative. ➟ we believes in the freedom of speech and ideas. ➟ we means openness and transparency. ➟ we points to potential uses of social media. ➟ wedetects trends. ➟ we reflects and discusses the experiences, related to social media. ➟ we describes the transformative nature of social media in economy, society and culture. ➟ we encourages collective action. ➟ we is open to authors around the globe. ➟ we engages into the current and future developments driven by social media. ➟ we embraces cultural diversity.
we is a magazine dedicated to the empowerment of many given to us by the Internet. ➟ The content is available for free on our website. ➟ We are planning 3,4 issues per year. ➟ we stands for a community of believers. Believers who are convinced that the Internet has the capacity to make theworld a better place. A change for the good! ➟ So all the articles you will read in WE-magazine are about this change. ➟ we looks at it from different point of views: culture, society, arts, education, politics, religion and economy. Our authors mainly work at the cutting edge of these topics, they are visionaires and innovators, gathered from all over the world.
or vs ||
i never use 'or' so i found this interesting.
Beginner Error in Rails: confusing an attribute of ActiveRecord instanze with an instance variable
As Ruby programmer you are used to write code like this, if you want to have a default value or rather make sure, that something is an Array or Hash, in order to rely on that for later treatment
def filters
@filters ||= { }
end
In Active Record that does not work, cuz:
@query.instance_variable_get :@filters
=> nil
@query.attributes
=> {"name"=>"_", "column_names"=>nil, "group_by"=>nil, "project_id"=>1, "sort_criteria"=>nil, "user_id"=>0, "search_mode"=>"all", "filters"=>{:subproject_id=>{:value=>[], :operator=>"*"}}, "is_public"=>false}
there is also obie's great post about this: http://www.jroller.com/obie/entry/default_values_for_activerecord_attributes
just for fun defining ruby modules inside classes
Usually you would rather define classes inside modules, but if you are left with a class and you want a module namespaced....
suung@q2:~$ suung@q2:~$ irb irb(main):001:0> class Foo irb(main):002:1> module Bar irb(main):003:2> def baz irb(main):004:3> puts 'baz' irb(main):005:3> end irb(main):006:2> end irb(main):007:1> end => nil irb(main):008:0> lass Baz NameError: uninitialized constant Baz from (irb):8 from :0 irb(main):009:0> class Baz irb(main):010:1> include Foo::Bar irb(main):011:1> end => Baz irb(main):012:0> Baz.new.baz baz => nil irb(main):013:0>