IrfanView: Replicate Crop on Multiple Images

I had a series of images of the same dimensions and wanted to crop all of them with the same bounds. Eyeballing the original crop and approximating the same on the rest of the images was out of the question, since the crops had to match to the very last pixel.

I tried to note down the crop parameters and redo the same on the rest of the images. When a crop rectangle is drawn on the image, its parameters can be seen on the Irfanview titlebar. The first 2 numbers are the coordinates of the origin (top left) and the next two numbers are the dimensions of the crop rectangle.

Redoing this crop manually on many images turned out bad since it was tiring to draw the rectangle with a mouse correctly to match the parameters.

Thankfully, the swiss army knife that is IrfanView has a better solution. Choose Edit โ†’ Create custom crop selection. If you have chosen a crop rectangle its parameters will already be displayed. Click on Save current values, click on Apply to image and crop the image. Open the rest of the images and do the same.

Advertisements

Beamer: Frame Title and Subtitle

The common method to provide the title and subtitle for a frame (slide) is:

\begin{frame}
\frametitle{News}
\framesubtitle{Technology}
\end{frame}

A shorter version which involves lesser typing is to provide the title and subtitle to \begin{frame} itself:

\begin{frame}{News}{Technology}
\end{frame}

How to split PDF file

PDFTK can be used to easily split out pages of a PDF file into separate PDF files at the shell. It is available for both Linux and Windows.

For Windows: Ensure that PDFTK is installed and the directory of pdftk.exe is in the PATH environment variable.

For Ubuntu: PDFTK can be installed using:

$ sudo apt install pdftk

Splitting

To split a PDF file into multiple PDF files, one per page of the original PDF file, invoke:

$ pdftk foobar.pdf burst output foobar-%d.pdf

If foobar.pdf is a 2 page PDF, this splits it into foobar-1.pdf and foobar-2.pdf.

If you split often, it would be much nicer to invoke the above simply as:

$ splitpdf foobar

To be able to do that on Windows, you can turn the above invocation into a batch file:

REM splitpdf.bat
pdftk %1.pdf burst output %1-%%d.pdf

The %1 is the first input argument to the batch file invocation. And %% is the way to escape %, which is a special character in a batch file.

(via Beamer + Ipe + views)

How to set font in Beamer

If you are not satisfied with the font themes that ship with Beamer, you can use any font family you want for your Beamer document. The font family you intend to use has to be available as a package. For example, to use the Helvetica font family include:

\usepackage{helvet}

The font theme has to match the style of the font family, else the resulting document may have a mix of fonts used in it. That is, use the serif font theme for a serif font family and so on. For example, to use the Concrete Math font family (which is serif):

\usefonttheme{serif}     % Font theme: serif
\usepackage{ccfonts}     % Font family: Concrete Math
\usepackage[T1]{fontenc} % Font encoding: T1

Sometimes, a font encoding may also have to be specified for the font family. For example, the T1 font encoding for Concrete Math font family in the example above.

Font themes in Beamer

A Beamer font theme represents the style of the font used in the document. Beamer comes with the following predefined font themes:

  • default (This is sans serif)
  • professionalfonts
  • serif
  • structurebold
  • structureitalicserif
  • strucutresmallcapsserif

To set the font theme for a Beamer document use the \usefonttheme command in the preamble of the document.

For example to set the font to serif:

\usefonttheme{serif}

Gmail: Mark All Incoming Email as Read

Since I have been following Inbox Zero for quite a while now, the only email seen in my inbox are unread email. If there is new email when I open Gmail, it is acted upon immediately or moved to other labels (folders) for later action. So, there is no point of the read-unread status of email in the inbox for me. Also, I do not like to see my inbox showing a unread count or seeing new email in the unread style (bold fonts).

In short, I would like all my incoming email to be marked as read. Since Gmail has no setting to do this, here is how I use a filter to achieve the same:

  1. Create a new filter. In the Has the words field enter is:unread and press Next Step ยป.


  2. Gmail pops up a dialog warning that this is not recommended and should it continue? Press OK.


  3. Check the Mark as read option and press Create Filter.


Python: Product of Elements of a List

Python has a built-in function to find the sum of the elements of a list:

alist = [10, 3, 8]
sum(alist) # 21

But, there are no such built-in functions for other arithmetic operations. Defining such arithmetic functions that operate on sequences like lists is easy.
Here is how to write a method that gives the product of the elements of a list:

import functools
import operator

def product(seq):
    """Product of a sequence."""
    return functools.reduce(operator.mul, seq, 1)

Python: __lt__()

If you try to sort a list of objects of your own class …

class Foobar:
    def __init__(self, idx):
        self.idx = idx
        return

fooList = [Foobar(10), Foobar(2)]
fooList.sort()

… you get a TypeError error:

TypeError: unorderable types: Foobar() < Foobar()

Python is reporting that it does not know how to compare Foobar objects.

Define a __lt__() method in the Foobar class. This rich comparison method is preferred over the generic __cmp__() method.

class Foobar:
    def __lt__(self, other):
    """Less-than comparison."""
    return self.idx < other.idx