rake spec + rails_admin = weirdly failing specs
If you use rails_admin, your specs pass with the rspec binary, but not using rake spec (or rake parallel:spec etc), put this at the top of your spec_helper:
ENV['SKIP_RAILS_ADMIN_INITIALIZER'] = 'false'
Don't ask.
This is probably also true for cucumber, your env.rb would be the right place.
How to deal with: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type [...] at
-
Check if you have puppetsync enabled on the master and client
[main] logdir=/var/log/puppet vardir=/var/lib/puppet ssldir=/var/lib/puppet/ssl rundir=/var/run/puppet factpath=$vardir/lib/facter templatedir=$confdir/templates pluginsync = true -
Check in
/var/lib/puppet/libthere should be a [...].rb somewhere. Delete it and look if it get copied again after with the next puppet run. -
If you are using environments make sure the puppetmaster is also in the correct environment. (d...
Get the initial username which you used to login to your Linux system
If you need the initial user which you used to login to your Linux system or the time when you login you can do:
whoami
One purpose of this could be the .bashrc to show different Bash Prompts for root to different users:
if [ $(whoami) = "root" ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[41;33m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
Difference between class_inheritable_attribute and class_attribute | martinciu's dev blog
How to make class_attribute behave like class_inheritable_attribte which no longer exists in Rails.
Rack dies when parsing large forms
- Rack has a limit for how many form parameters it will parse.
- This limit is 65536 by default.
- There is a bug in Rack that will incorrectly count the number of input fields in nested forms. In my case a form with 1326 input fields was enough to break the default limit.
- If Rack thinks your request is too large, the request will fail with a low-level Ruby message like Fix: "undefined method `bytesize' for #" or the standard Rails error box.
- You ...
RSpec claims nil to be false
RSpec's be_false behaves unexpectedly:
nil.should be_false
# passes, as the expectation returns true
If you want to check for false, you need to do it like this:
nil.should == false
# fails as expected
See also
Deal with error: Expected foo_trait.rb to define FooTrait
Lately, I came across a nasty error. I had a class Article that included FooTrait and BarTrait. In BarTrait, I then accidentally called a non-existent method:
has_defaults :dummy => Dummy.non_existent_method
From that moment, no page would load anymore but always display an exception: Expected foo_trait.rb to define FooTrait. That trait had nothing to do with BarTrait.
Since it doesn't tell you what's wrong, you either remember where you were working last or you need to check all [traits](https://github.com/makandra/modul...
Some useful Unicode chars
Copy and paste at will, they're free!
- German quotation marks: „ “ (Ubuntu-Hotkey: AltGr+v and AltGr+b)
- English quotation marks: “ ”
- En dash: –
- Em dash: —
- Ellipsis: …
Some useful hints for users of Ubuntu Linux
- Your Ubuntu comes with a searchable list of Unicode chars. Go to Accessories / Character map.
Ctrl + Fsearches for a character by name. - If you want to write all of them (and more) yourself, [configure a compose key](https://makandracards.com/makandra/1030-insert-an...
BigDecimal#inspect for people who aren't cyborgs
I wonder if the guy that wrote BigDecimal#inspect has a tragic backstory that explains why he hates humanity.
- Tim Pope
I finally gave up and made BigDecimal#inspect return BigDecimal#to_s:
p BigDecimal.new('2.3') #=> "2.3"
Use the attached initializer.
Updated: Ruby doesn't sort strings with German umlauts correctly
I posted a solution which is awesome and also does natural sorting.
Don't use Ruby 1.9.2
Ruby 1.9.2 is very slow when loading files, especially starting Rails servers or running specs takes forever.
Do yourself a favor and upgrade to 1.9.3.
Order of multiple "rescue_from" statements might be unexpected
Take care when using rescue_from to rescue multiple errors.
The following will not work, because later rescue_from statements take precedence and so the first one will never be called:
rescue_from AccessDenied, :with => :redirect_to_home
rescue_from Exception, :with => :render_500
Simply reverse them.
GNOME3 Notifications For Skype ~ Web Upd8: Ubuntu / Linux blog
- Also works on Gnome 2
- Much prettier than Skype notifications
- Better visibility
Do not use "find" on Capybara nodes from an array
In a nutshell: Capybara's find will not work properly on nodes from a list. Don't find on elements from a list.
Background
Consider this HTML:
<div class="message">
<h2>Hello World</h2>
Lorem ipsum...
</div>
<div class="message">
<h2>Hello Universe</h2>
Lorem ipsum...
</div>
Now let's say you obtain a list of all such message containers as an array:
messages = page.all('.message')
And then you look at their titles like this:
messages[0].find('h2').text
=> "Hello W...
Use Nokogiri to convert CSS to XPath
CSS is a lot easier to write and read than clumsy XPath expressions. So when you need to use XPath, you can have Nokogiri help you out on creating it.
Simply use Nokogiri's xpath_for:
Nokogiri::CSS.xpath_for('#foo')
# => ["//*[@id = 'foo']"]
Nokogiri::CSS.xpath_for('#foo .bar:nth-of-type(2)')
# => ["//*[@id = 'foo']//*[contains(concat(' ', @class, ' '), ' bar ') and position() = 2]"]
Since XPath is more powerful you may still need to do some hardcore XPath hacking eventually. But at least you don't need to for simple cases.
LibreOffice won't embed most fonts into PDFs (with fix)
- LibreOffice Impress, Writer, etc. doesn't embed most fonts into the PDFs it generates.
- This means if you share a slide show with a font that is not Arial or Times, other people will get an error message "Cannot extract the embedded font 'XYZ Some characters may not display or print correctly" and unreadable text. Everybody loses.
- Some forums will recommend that you tick "PDF/A-1a" in the PDF options to make LibreOffice embed fonts. In reality, thi...
Rails 2's CookieStore produces invalid cookie data, causing tests to break
Note that this seems to affect only recent Rails 2 versions.
You will not encounter this until you are writing to the cookie more than once, but when doing so, integration tests (Cucumber) may break for you with this error:
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[] (NoMethodError)
Background
The regular/short cucumber backtrace is not of any help but looking at the full trace reveals that ActionPack's `actio...
How much should I refactor?
The Rails community has been abuzz with object-oriented programming, SOLID principles, laws, design patterns, and other principles, practices, and patterns. We’ve (re)discovered new tools and techniques to separate and reuse logic, making code easier to test, understand, and maintain. Now that we’ve learned about all these new tools, when do we use them?
LibreOffice Impress: Distorted text letters in presentation mode
Upgade to LibreOffice 3.5.3+ or disable hardware accelleration in Tools → Options → LibreOffice → View → Graphic output.
CSS3 Media Queries have reached recommendation status
Media Queries have reached W3C Recommendation on June 19th 2012.
If you were interested in other (future) web standards you can have a look at recent W3C publications.
Using ENUMs with Rails - See John Code
This sounds promising:
The best part from the Rails side, is that you don’t have to change anything at all in your code to swap a varchar out for an ENUM.
Show hint in HTML 5 text fields
To have your text input field pre-filled in with some text that disappears as soon as the user selects it, use the attribute placeholder:
<input type="text" placeholder="User name here">
This will only work in recent browsers (IE >= 10, FF >= 4, Chrome >= 4, Safari >= 5, Opera >= 11.6).
Updated: Puppet 2.6.x on Ubuntu lucid 10.04
New way to install an actual puppet version on ubuntu
Calendar quarter calculations in Ruby and MySQL
ActiveSupport >= 3 has
Date.parse('2011-02-10').beginning_of_quarter #=> 2011-01-01
Date.parse('2011-02-10').end_of_quarter #=> 2011-03-31
You can manually calculate the quarter index like
(Date.parse('2011-02-10').month / 3.0).ceil #=> 1
Yes, you do actually divide by 3.0, not 4.0.
MySQL has
SELECT QUARTER('2011-02-10'); #=> 1