Include existing PDF files into new TeX document
If you plan to insert an existing PDF into a new LaTeX document that you will compile to PDF, you can use \includegraphics
for this. Although, be prepared to get tons of errors complaining about overfill hboxes and the like.
You can use this package that takes care:
\usepackage[final]{pdfpages}
In order to insert a PDF, use:
\includepdf{$filename}
See the external link for more options.
Fix errors when rendering PDF output
If you run specs or your application and get an error like:
ActionController::MissingFile in 'ProductsController#show, should render PDF'
Cannot read file /some/file.pdf
You may be missing the HTMLDOC binary on your system. Install it like this on Debian/Ubuntu:
sudo apt-get install htmldoc
Iterate over every n-th element of a Range in Ruby
If you want to iterate over a Range, but only look at every n-th element, use the step
method:
(0..10).step(5).each do |i|
puts i
end
# Prints three lines:
# 0
# 5
# 10
This is useful e.g. to iterate over every Monday in a range of Dates
.
If you are using Rails or ActiveSupport, calling step
without a block will return an array of matching elements:
(0..10).step(5)
# => [0, 5, 10]
Test the content-type of a response in Cucumber
The step definitions below allow you to write this in both Webrat and Capybara:
When I follow "Download as PDF"
Then I should get a response with content-type "application/pdf"
Capybara
Then /^I should get a response with content-type "([^"]*)"$/ do |content_type|
page.response_headers['Content-Type'].should == content_type
end
Webrat
Then /^I should get a response with content-type "([^"]*)"$/ do |content_type|
response.content_type.should == content_type
end
Unfortunatly this do...
Git: See all unpushed commits or commits that are not in another branch
If you need to find out which of your local commits are not on the remote server do this:
git cherry -v
The -v
option prints out the commit messages. Without it you will see only the SHA1 codes.
You may also compare against another (upstream) branch like that:
git cherry -v origin/somebranch
This tool is especially useful when you have a ton of commits after a merge and want to know the commit differences between branches.
The LaTeX Font Catalogue
Gallery of fonts you can use without much hassle in LaTeX. The license of the fonts vary, but are all free. Note that the fonts not necessarily are free to distribute, and some fonts are available for non-commercial use only.
Request a non-HTML format in controller specs
If a controller action responds to other formats than HTML (XML, PDF, Excel, JSON, ...), you can reach that code in a controller spec like this:
describe UsersController do
describe '#index' do
it 'should be able to send an excel file' do
# stubs and expectations go here
get :index, :format => 'xls'
end
end
end
Remember that both the :format
parameter and the HTTP_ACCEPT
header can m...
Fix permissions of temporary RTeX files (which are group and world-readable)
We use RTeX for PDF exports.
While converting LaTeX to PDF, RTeX opens a temporary file which has problematic permissions: Both group and world can read those files.
Although the temp files should go away they sometimes live longer than one would expect.
We patched RTeX to fix this (and have more secure permissions). Place the code below into config/initializers/rtex.rb
Debug Ruby code
This is an awesome gadget in your toolbox, even if your test coverage is great.
-
gem install ruby-debug
(Ruby 1.8) orgem install debugger
(Ruby 1.9) - Start your server with
script/server --debugger
- Set a breakpoint by invoking
debugger
anywhere in your code - Open your application in the browser and run the code path that crosses the breakpoint
- Once you reach the breakpoint, the page loading will seem to "hang".
- Switch to the shell you started the server with. That shell will be running an irb session where you can step thr...
Count lines of code
The following counts all the lines in all *.rb
files in the app
directory. Run several of these commands to get a rough estimate of the LOC.
find app -name *.rb -exec wc {} \; | awk '{a+=$1;print a}' | tail -1
MySQL replication how-to
This may be awkward to set up, but will work once you're done.
Fun facts:
- In case of a connection loss the slave will try to reconnect to the master server and resume replication for the next 24 hours
- If you want to use your slave as a "real" MySQL server, you basically need to switch off replication (
STOP SLAVE; RESET SLAVE;
and reset your my.cnf) and restart the MySQL daemon.
Master server configuration
-
- Create replication user
- In the MySQL shell:
CREATE USER 'replicator'@'%' IDENTI...
A List Apart: Articles: Unwebbable
An example of the conundrum of transferring print documents to the web, one that has become legendary in some circles, is the film screenplay.
jspdf - Project Hosting on Google Code
jsPDF is an open-source library for generating PDF documents using nothing but Javascript. You can use it in a Firefox extension, in Server Side Javascript and with Data URIs in some browsers.
Ruby Ghostscript by Shairon Toledo
Ruby Ghostscript (RGhost) is a library for document developers wanting a quick and easy way to generate pdf files. It's optimized to work with larger documents.
michaeldv's awesome_print at master - GitHub
Pretty print your Ruby objects with style -- in full color and with proper indentation
wkhtmltopdf - Project Hosting on Google Code
Simple shell utility to convert html to pdf using the webkit rendering engine, and qt.
Rethinking PDF Creation in Ruby
We're excited to announce PDFKit, an open source library that makes working with wkhtmltopdf a snap.