RSpec: Tagging examples and example groups
In RSpec you can tag examples or example groups with any tags you like simply by saying
describe ReportCreator, slow: true do
# ..
end
describe ReportCreator do
it 'generates reports', slow: true do
# ...
end
end
You can then only run examples with these tags.
rspec --tag slow
rspec -t slow
# Using the parallel_tests gem
rake "parallel:spec[,,--tag slow]"
Or you can run all examples except the ones with a certain tag:
rspec --tag ~slow # note the ~
rspec -t ~slow
# Using the parallel_tests gem
r...
Fontawesome 4+ icon naming conventions
Fontawesome 4 has introduced new naming conventions that make it easy to retrieve variants of a given icon.
The format is:
fa-[name]-[alt]-[shape]-[o]-[direction]
Note that this is a naming convention which doesn't imply there's an icon for any combination of tags.
name
The name of the icon, e.g. comment
, print
, bookmark
etc. See the full list.
alt
An alternative icon.
shape
The icon inside a circle
or square
.
o
An outlined ...
AngularJS Cheat Sheet (PDF)
This cheat sheet ... aims at providing a quick reference to
the most commonly used features in AngularJS.
grosser/rspec-instafail
Gem to show failing specs instantly.
Unlike the --fail-fast
option it doesn't abort abort on the first failure, but keeps running other examples after print out the failure.
I haven't tried it with parallel_tests
.
The developer console can do more than you think!
You can do so much more than console.log(...)
! See the attached link for a great breakdown of what the developer console can give you.
Some of my favorites:
console.log takes many arguments
E.g. console.log("Current string:", string, "Current number:", 12)
Your output can have hyperlinks to Javascript objects
E.g. console.log("Check out the current %o, it's great", location)
[Di...
Installing Adobe Reader on Ubuntu
Adobe no longer supports their PDF reader on Linux and the official page does not offer it for download. \
However, some files may not display properly on Ubuntu's default PDF reader Evince or PDF forms may not work as expected. Hence, you may still need to use it.
Here is how to install the Adobe Reader (acroread
) if you need to:
-
Download the
.deb
archive from the Adobe servers (yes, it's still there):cd /tmp && wget http://ardownload.adobe.com/pub/adobe/reader/unix/9.x/9.5.5/enu/AdbeRdr9.5.5-1_i386linux_enu.deb
-
I...
LibreOffice Writer prints text frames as black areas
To fix this:
- Right-click on the frame
- Select Frame...
- Open Background
- Set As to "Color"
- Set the background color to "No fill"
Bootstrap: How to avoid printing link URLs
By default, Twitter Bootstrap's print styles include printing links.
/* Bootstrap's way of printing URLs */
@media print {
a[href]:after {
content: " (" attr(href) ")";
}
}
If you want to turn that off, you can do
/* Don't print link hrefs */
@media print {
a[href]:after {
content: none
}
}
Fixing tlmgr cannot setup TLPDB
tlmgr
is the TeX Live Manager and responsible for the TeX installation on your (Linux) machine.
If you're getting the message:
(running on Debian, switching to user mode!)
cannot setup TLPDB in /home/dominik/texmf at /usr/bin/tlmgr line 5336.
... tlmgr
has not been initialized. Run this to initialize it:
tlmgr init-usertree
Then, you may set e.g. a global paper size standard: tlmgr paper a4
.
How to repair a corrupt PDF
If you have issues with PDFs, fix them like this: pdftk <corrupted_file>.pdf output <fixed_file>.pdf
Background
I had an issue where an included PDF would not show up in a document created with xelatex
. This is the relevant line of LaTeX code:
\AddToShipoutPicture*{ \includegraphics[width=21cm]{/home/dominik/code/ihero/public/system/stationery/original/stationery.pdf} }
The included PDF is a stationery for invoices which users can upload themselves. It did work until someone updated their stationery with a nearly-iden...
How to install the `xelatex` binary on Ubuntu 14.04
Just install the texlive-xetex
package:
sudo apt-get install texlive-xetex
Running integration tests without texlive-xetex
will produce an error during xelatex
execution:
RTeX::Document::ExecutableNotFoundError
When Sass-generated stylesheets print a Encoding::CompatibilityError
We upgraded a Rails 2 application to Rails 3.2 and Ruby 2.1, changed the mysql adapter from mysql
to mysql2
, but did not activitate the asset pipeline. Instead we used Sass the old-school way (stylesheets in public/sass/*.sass
) and relied on stylesheet_link_tag
to activate the Sass compiler.
Now all Sass-generated stylesheets inserted the following text into body:before
:
Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT
I could get rid of this by removing all generated .css
files in `...
pdfkit/wkhtmltopdf: When a header is invisible
If you're using the :header_html
option in PDFKit (or the corresponding --header-html
option in wkhtmltopdf
), and the header remains invisible, you need to add this to your header HTML:
<!doctype html>
The same applies to footers via footer_html
I'm sorry.
Linux: Running a program with a different locale than your default
When your system is not running on English, you may sometimes want to run some applications and not use your system locale.
Use cases are scripts that parse output, or just using the (possibly) more common English labels or error messages. Here is how to do that.
I will use the date
command and print the current weekday, just for the sake of an example.
Changing the locale using environment variables
Most often, setting LC_ALL
for your command should be enough. The following was run on a system using a German locale.
$ date +%...
What we know about PDFKit
What PDFKit is
- PDFKit converts a web page to a PDF document. It uses a Webkit engine under the hood.
- For you as a web developer this means you can keep using the technology you are familar with and don't need to learn LaTeX. All you need is a pretty print-stylesheet.
How to use it from your Rails application
- You can have PDFKit render a website by simply calling
PDFKit.new('http://google.com').to_file('google.pdf')
. You can then send the...
Ruby lets you redefine backticks
This actually works:
class Klass
def initialize
`hi world`
end
def `(message)
puts "Called with backticks: #{message}"
end
end
Klass.new # Prints "Called with backticks: hi world"
Hat tip to @jcoglan.
PSA: Umlauts are not always what they seem to be
When you have a string containing umlauts which don't behave as expected (are not matched with a regexp, can't be found with an SQL query, do not print correctly on LaTeX documents, etc), you may be encountering umlauts which are not actually umlaut characters.
They look, depending on the font, like their "real" umlaut counterpart:
- ä ↔ ä
- ö ↔ ö
- ü ↔ ü
However, they are not the same:
'ä' == 'ä' # false
'ä'.size # 1
'ä'.size # 2
Looking at how those strings are constructed reveals what is going on:
'ä'.unpack('U*...
Lightweight PDF viewer: MuPDF
MuPDF is a PDF reader that renders very quickly, yet still correctly.
It supports PDF 1.7 and all the fancy shenanigans that evince (Ubuntu's default PDF reader) fails to render properly.
On Ubuntu, MuPDF is available in the Universe sources. Simply install via APT:
sudo apt-get install mupdf
Interaction primarily happens via keyboard, but there is basic mouse support.\
See the manpage for more details on navigating.
One downside: There is no printing support, so if...
A Ruby script that installs all gems it is missing
So you want your Ruby script to install missing gems instead of dying? Take this method:
def installing_missing_gems(&block)
yield
rescue LoadError => e
gem_name = e.message.split('--').last.strip
install_command = 'gem install ' + gem_name
# install missing gem
puts 'Probably missing gem: ' + gem_name
print 'Auto-install it? [yN] '
gets.strip =~ /y/i or exit(1)
system(install_command) or exit(1)
# retry
Gem.clear_paths
puts 'Trying again ...'
require gem_name
retry
end
Use it like this:
insta...
About "unexpected '#' after 'DESCENDANT_SELECTOR' (Nokogiri::CSS::SyntaxError)"
The error unexpected 'x' after 'DESCENDANT_SELECTOR' (Nokogiri::CSS::SyntaxError)
(where x
may be basically any character) occurs when the Nokogiri parser receives an invalid selector like .field_with_errors #
or td <strong>
.
In Cucumber, the culprit will be an invalid step definition that builds an invalid selector:
# inside some step definition:
field = find_field(label)
page.send(expectation, have_css(".field_with_errors ##{field[:id]}"))
The above raises the mentioned error if field[:id]
is nil, i.e. the foun...
Offtopic: Floppy-disc OS
MenuetOS is an Operating System in development for the PC written entirely in 32/64 bit assembly language. Menuet64 is released under License and Menuet32 under GPL. Menuet supports 32/64 bit x86 assembly programming for smaller, faster and less resource hungry applications.
- Fits on a single floppy, boots also from CD and USB drives
- Responsive GUI with resolutions up to 1920x1080, 16 million colours
- Free-form, transparent and skinnable application windows, drag'n drop
- SMP multiprocessor support with currently up to 8 cpus
- IDE: E...
Rails 2: Refuse response formats application-wide
If you regularly get ActionView::MissingTemplate
exceptions, maybe some bot visits your site requesting silly formats like:
http://www.rails-app.com/makandra.html-username-2000 # => Rails tries to retrieve 'makandra' with format 'html-username-2000'
Just restrict accepted format parameters for the whole application like this:
class ApplicationController < ActionController::Base
before_filter :refuse_silly_formats
private
def refuse_silly_formats
acceptable_formats = %w[html xml pdf]
if par...
Linux: How to print PDF files from the command line
Sometimes you may want to print files from the command line, especially when you have lots of them.
You can use lp
for that.
To print a single example.pdf
file on your default printer, simply say:
lp example.pdf
lp
accepts multiple filenames, so to print all PDF files in the current directory:
lp *.pdf
You can specify a printer via the -d
switch:
lp -d YOUR_PRINTER_NAME *.pdf
Your printer's name is then one you defined on your system. You can check with your CUPS configuration by visiting `http://localhost:631/...