View

Linux: Manipulate PDF documents

Here are some tools that are useful to manipulate PDF documents under Linux/Ubuntu:

Xournal (Ubuntu 14.04+)
Add text, add images, add hand-written notes. No geometrical shapes.
uPdf (old Ubuntus)
Add text, add images, add geometrical shapes. Horrible GUI, but works some of the time.
PDF-Shuffler
Graphical GUI to reorder pages, remove pages, rotate pages, add pages.
pdftk
Command …

netstat: Sum open connections by IP (and sort it)

The following sums up all connections (ESTABLISHED, TIME_WAIT, FIN_WAIT, etc.) and sorts it:

netstat -n | awk ' $5 ~ /^[0-9]/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

Works on FreeBSD and Linux.

Geordi 1.3 released

Changes:

  • Geordi is now (partially) tested with Cucumber. Yay!
  • geordi cucumber supports a new @solo tag. Scenarios tagged with @solo will be excluded from parallel runs, and run sequentially in a second run
  • Support for Capistrano 2 AND 3 (will deploy without :migrations on Capistrano 3)
  • Now requires a .firefox-version file to set up a test firefox. By default now uses the system Firefox/a test Chrome/whatever and doesn't print warnings any more.
  • geordi deploy --no-migrations (aliased -M): Deploy with `cap …

bash: print columns / a table

Ever wondered how you can create a simple table output in bash? You can use the tool column for creating a simple table output.

Column gives you the possibility to indent text accurate to the same level. Pipe output to column -t (maybe configure the delimeter with -s) and see the magic happening.

detailed example

I needed to separate a list of databases and their corresponding size with a pipe symbol: |
Here is a example list.txt:

```
DB Size_in_MB
foobar 11011.2
barfoo 4582.9
donkey 4220.8
shoryuken 555.9
hadouken 220.0
k…

Linked contentRepeats

Ruby blocks: Braces and do/end have different precedence

Braces and do/end are completely swappable—almost all the time. They have different precedence. It’s not often that anyone comes across what this means in practice.

TL;DR {} binds stronger than do…end (as always in Ruby, special characters bind stronger than words)

Demo

Right way

names = ['bRUce', 'STaN', 'JOlIE']

# Blocks in braces are passed to the rightmost method
print names.map { |name| name.downcase }
print(names.map do |name| name.downcase end) # equivalent
=> ["bruce", "stan", "jolie"]

Wrong way

Avoid…

Linked content

find out which processes using swap

Wondering which processes are placed in your swap you can use this bash oneliner:

for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r

You will see the swap usage of each process sorted by the highes amount of swap usage.

Please don't forget that swap usage of a process isn't an indicator for high memory usage of this process but for the frequency of access or activity of it. The kernel tries to avoid swapping pages which were recently accessed.

Also you should notic…

Linked content

start tcpdump log on high traffic

Logging tcpdump output all the time can create a huge amount of data. This can be both: too much data size on HDD and tiring to analyze. You can run a script in a screen which checks out the packages transfered per second and start a tcpdump when the packages exceed a fixed number.

```
#!/usr/bin/env bash

interface=eth0
dumpdir=/tmp/
packet_threshold=5000
log_packets=100000

while /bin/true; do
pkt_old=grep $interface: /proc/net/dev | cut -d : -f2 | awk '{ print $2 }'
sleep 1
pkt_new=`grep $interface: /proc/net/dev | cut -d : -f…

Sending TCP keepalives in Ruby

When you make a simple TCP connection to a remote server (like telnet), your client won't normally notice when the connection is unexpectly severed on the remote side. E.g. if someone would disconnect a network cable from the server you're connected to, no client would notice. It would simply look like nothing is being sent.

You can detect remote connection loss by configuring your client socket to send TCP keepalive signals after some period of inactivity. If those signals are not acknowledged by the other side, your client will terminat…

Linked content

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…

whenever: Preview the crontab

If you'd like to preview the crontab that whenever will deploy, run the following:

bundle exec whenever

This will print the cron syntax without modifying your local crontab.

Parallel Rspec with RTeX

Running projects parallel makes some trouble with PDF generation. Use geordi rspec spec to force sequential tests for the whole application or failed specs only.


geordi rspec
RTeX::Document::GenerationError in '...'
Could not find result PDF document.pdf after generation.
Check .../document.log

The document will show you, that RTeX tries to generate a PDF document out of a HTML file, which won't work.

Make timestamp of dmesg in Ubuntu human readable

dmesg shows the kernel ring buffer containing low-level system messages.
Per default, dmesg shows a timestamp:

12:59:26 fnordomator ~ > dmesg | tail
[101925.211846] usb 2-1.1: USB disconnect, device number 16
[110486.855788] usb 2-1.1: new high-speed USB device number 17 using ehci_hcd

If you're a human, use dmesg -T to print the timestamp human readable:

12:59:31 fnordomator ~ > dmesg -T | tail
[Di Apr 21 12:43:16 2015] usb 2-1.1: USB disconnect, device number 16
[Di Apr 21 15:05:57 2015] usb 2-1.1: new hig...
Linked content

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 version of t…
Linked content

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.

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) or gem 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…
Linked content

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:

  1. 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
    
  2. I…

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
  }
}
Linked content

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.

This website uses cookies to improve usability and analyze traffic.
Accept or learn more