LaTeX: Preamble

The preamble of a LaTeX document is the section between \documentclass and \begin{document}.

Advertisements

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

C++: Initialize STL Vector with Array

A STL vector does not have any constructor that looks like it accepts an array. So, the straightforward way to initialize a vector with an array looks like:

#include <vector>

int arr[ARR_LEN] = { /* Array elements */ };
std::vector iVec;
for (int i = 0; i < ARR_LEN; ++i)
    iVec.push_back( arr[i] );

That is too much code for a simple initialization! Thankfully, there is another way do it with less code.

The constructor vector(InputIterator begin, InputIterator end) which initializes a vector with the elements of the range [begin, end) can be used with arrays too. This is because array pointers have all the properties required of an (input) iterator:

#include <vector>

int arr[ARR_LEN] = { /* Array elements */ };
std::vector<int> iVec(arr, arr + ARR_LEN);

Note that the second argument arr + ARR_LEN is beyond the last element of the array and thus behaves as the correct end().

Windows 7: Shared Folders Management

In Windows 7, shared folders do not have an overlay icon on them indicating they are being shared. The reason for this change is explained by Raymond Chen here:

Given the changes in how people use computers, sharing information is becoming more and more of the default state. When you set up a HomeGroup, pretty much everything is going to be shared. To remove the visual clutter, the information was moved to the Details pane. What’s more, a single overlay cannot express the different ways an item can be shared, so in order to figure out what the deal is, you have to go to the Details pane anyway.

So, the best place to view your shared folders and to stop sharing them (after the sharing love is over) is the Shared Folders MMC. It can be invoked by typing fsmgmt.msc at the Start menu.

Adobe Acrobat: Embedded Font Error

Cannot extract the embedded font 'Foobar'. Some characters may not
display or print correctly.

You may see this error with Adobe Acrobat 8 when you open certain PDF documents. If the Foobar font has been used all over the PDF, all you see of the document will be gibberish!

Adobe says they have fixed this error in their Acrobat 8.1.1 update:

#1572280 Type 3 fonts with missing operators. PDF documents that contain Type 3 fonts with missing operators are non-compliant with the PDF specification. These non-compliant PDF documents are typically generated by third party products. When trying to opening the document, users see an error message, “Cannot extract the embedded font ‘F0’. Some characters may not be displayed or printed correctly.” PDF documents open correctly in Reader/Acrobat 7.x, but not 8.0 or 8.1. The root cause is Type 3 fonts that do not comply with the PDF specification, which requires either the ‘d0’ or ‘d1’ operator in every Type 3 character procedure. In version 7.x, if the offending character was not displayed, the PDF document opened normally. Version 8.0 catches this error even if the character is not displayed. The updated behavior will ignore the missing operator when the character procedure is empty.
Root: fixes an issue in versions 8.0 and 8.1, not present in earlier versions.

However, installing the 8.1.1 update does not really fix this error! In fact, even though I incrementally updated all the way up to 8.2, the error is not solved. 8.2 is the last Acrobat 8.x update available for the 8 series.

There does not seem to be any solution to this error by Adobe. It does not seem to be fixed even in the 9.x series of Adobe Acrobat (see Mark Kostka’s comment below). The solution seems to be the latest versions of Adobe Acrobat Reader or Foxit Reader. The PDF documents display and print without any problem in these readers!

How to disable Group By in Windows 7

Windows Explorer on Windows 7 tries to be intelligent and offers to group the contents of a directory according to certain parameters. A lot of times when it cannot do this, it lumps them in a group named Unspecified. I find this grouping affair very irritating, especially when selecting files using the keyboard.

To turn off Group By completely:

  1. Open any directory in Windows Explorer.
  2. Right-click and choose Group by > (None)
  3. Press the Alt key, so that the Explorer menu bar appears and choose Tools โ†’ Folder Options.
  4. Go to the View tab and click Apply to Folders. This will apply the Group By setting to all folders.