Sometimes you may want to print files from the command line, especially when you have lots of them.
It's actually pretty simple:
lp -d YOUR_PRINTER_NAME FILENAMES
Your printer's name is then one you defined on your system. You can check with your CUPS configuration by visiting
So, for example:
lp -d Brother-MFC-9840CDW *.pdf
It should work with other file formats than PDF, too, but I have not tried that yet.
This note is to remember that there is something called AppArmor that could cause weird errors ("File not found", "Can't open file or directory", …) after configuration changes, e.g. when changing MySQL's data directory.
Remember to have a look at AppArmor's daemon configuration (usually at
/etc/apparmor.d/) if you change daemon configuration and run into errors such as the one above.
All the hidden and not hidden features of Git and GitHub.
Use the following command to test if a server (in this example: makandra.com on port 443) uses Perfect Forward Secrecy (PFS):
openssl s_client -connect makandra.com:443 -cipher ECDHE-RSA-RC4-SHA
You should see something like the following:
~ > openssl s_client -connect projecthero.com:443 -cipher ECDHE-RSA-RC4-SHA CONNECTED(00000003) depth=1 O = AlphaSSL, CN = AlphaSSL CA - G2 verify error:num=20:unable to get local issuer certificate verify return:0 --- Certificate chain 0 s:/C=DE/OU=Domain Control Va...
In order to save the original value of a constant, set the new value and restore the old value after a scenario was completed, you can use the following helper. It takes care of saving the old constant value, setting the new one without throwing warnings and resets the value with an
This module also enables you to introduce new global constants.
Since these newly defined constants do not have any value to be reset to,
they simply are deleted (
remove_const) once the respective Cucumber step finishes.
You can copy the file at…
When using TextMate2 with the cucumber bundle, it does not recognize step definitions (e.g.
custom_steps.rb) as such but believes they are plain Ruby files. But there is help!
Add these lines to the bottom of your
.tm_properties file (in
~/ for global settings, in any directory for per-project settings):
[ "*_steps.rb" ] fileType = "source.ruby.rspec.cucumber.steps"
Apparently, this works for any files. Define a regex and specify custom settings. The attached article lists all available configuration options (whic…
Be careful with the Active Record
When you accidentally pass an empty array to the
where method using
NOT IN, you probably will not get what you expected:
User.where("id NOT IN (?)", )
Even though you might expect this to return all records, this actually results in this query:
SELECT `users`.* FROM `users` WHERE (id NOT IN (NULL))
This will not return anything.
String#camelize method can actually help you out. Simply pass a
:lower argument to it.
>> 'foo_bar_baz'.camelize => "FooBarBaz" >> 'foo_bar_baz'.camelize(:lower) => "fooBarBaz"
rake -W [substring_of_task]
Enter the hostname of a server to test it for CVE-2014-0160.
A check if two date or time ranges A and B overlap needs to cover a lot of cases:
- A partially overlaps B
- A surrounds B
- B surrounds A
- A occurs entirely after B
- B occurs entirely after A
One trick to cover all these cases with a single expression is to see if the start date of each range is looking at the end date of the other range in the same direction.
The code below shows how to implement this in Ruby on Rails. The example is a class
Interval, which has two attributes
#end_date. These dates are considere…
A look at Prawn, PDFKit, and Wicked PDF
Hint: There's another card with this helper for Cucumber features.
Sometimes you feel like you need to stub some CONSTANT you have defined in an other class. Since actually constants are called constants because they're constant, there's no way to easily stub a constant.
Here are three solutions for you.
Rethink! Do you really need
CONSTANT = %w[foo bar] to be constant? In many cases, setting it as a sim…
- The "
I wait for the page to load" step now no longer uses
wait_untilwhich had been removed since Capybara 2.0.
- You can now also
rake all:rubiesusing rbenv.
If you come across an (older) application that is using Prototype instead of jQuery, you may often see events bound to single elements only, like this:
$('foo').observe('change', updateThings); $('bar').observe('change', updateThings); $('baz').observe('change', updateThings);
If you are calling only one method in each case, this is unnecessarily ugly. Also, when your page contents have been replaced via AJAX (like sections of a form after choosing something), those event hooks will no longer wo…
The Heartbleed Bug is a serious vulnerability in the popular OpenSSL cryptographic software library. This weakness allows stealing the information protected, under normal conditions, by the SSL/TLS encryption used to secure the Internet.
This is pretty much like defining subclasses through traits with the Modularity gem.
module MyConstantTrait as_trait do self::MY_CONSTANT = 'hello universe' end end
This would set
MY_CONSTANT for any class using the trait.
Of course you can also use parameters (for logic or for setting values, like here):
module ValuesTrait as_trait do |*args| self::VALUES = args end end class Foo does 'values', :f...
Declare an enum attribute where the values map to integers in the database, but can be queried by name.