Monday, September 19, 2011

TexShop coloring

From version 3.06 (Lion) it is possible to have different background and foreground colors in TexShop.

You can select the background colors from Preference dialog box. However, other colors must be
specified at command line.

defaults write foreground_R 1
default write foreground_B 1
default write foreground_G 1
will make the font color to white.

The background color can be changed from TexShop Preferences window.

defaults write TexShop commandblue 1
defaults write TexShop commandred 0
defaults write TexShop commandgreen 1
will make the command color to cyan.

To change the cursor color to white do
defaults write TexShop insertionpoint_R 1
defaults write TexShop insertionpoint_G 1
defaults write TexShop insertionpoint_B 1

defaults write TexShop commentred 0
defaults write TexShop commentblue 0
defaults write TexShop commentgreen 1
will make the comment color to lime green.

These are RGB decimal color codes. To obtain those values divide RGB colors from 255.
Here is a list of RGB colors.

TexShop documentation where these color preferences are mentioned can be seen here.

Thursday, September 1, 2011

pygmentize

Install pygmentize by

sudo easy_install Pygments

quick start (copied from the official Web site)



You can use Pygments from the command line, using the pygmentize script:
$ pygmentize test.py
will highlight the Python file test.py using ANSI escape sequences (a.k.a. terminal colors) and print the result to standard output.
To output HTML, use the -f option:
$ pygmentize -f html -o test.html test.py
to write an HTML-highlighted version of test.py to the file test.html. Note that it will only be a snippet of HTML, if you want a full HTML document, use the "full" option:
$ pygmentize -f html -O full -o test.html test.py
This will produce a full HTML document with included stylesheet.
A style can be selected with -O style=.
If you need a stylesheet for an existing HTML file using Pygments CSS classes, it can be created with:
$ pygmentize -S default -f html > style.css

Wednesday, August 17, 2011

Python urllib proxies

It is possible to open a url via a proxy server using urllib as shown in the following code.
Here is the documentation.
Here is a list of proxies. To check your IP you can use this site.

import urllib
import re

httpProxy =  "http://85.172.205.91.static.giga-dns.com:3128"
webSite = "http://whatismyipaddress.com/"

if False:
    # no proxy.
    txt = urllib.urlopen(webSite).read()

if True:
    # with proxy.
    proxies = {'http':httpProxy}
    txt = urllib.urlopen(webSite, proxies=proxies).read()
    
IPreg = re.compile('

Thursday, July 28, 2011

Aptana Studio

In Apatana studio you can perform block editing. First select some lines of text and then press Command+Option+A. This will enable block highlighting mode. Now use Shift+Arrow Keys to expand or shrink the current selection. When you type in some text, all the highlighted fields will change simultaneously.

Friday, July 8, 2011

Synchronizing system clock (Ubuntu)

There are nice GUIs to do this if you have installed some Window managing system such as Gnome or KDE. However, if you have a server installation and have not installed any of those Window managing system and/or want to do this via command line then do the following (requires sudo access).


sudo ntpdate ntp.ubuntu.com

Thursday, June 2, 2011

Killing Zombies

Well, the word zombie means it is already dead but not quite so... This entry is about really "killing" the zombie processes.

running "top" lists up the zombie processes (marked by "Z" in status column) and also the total number of zombie processes.

To list zombie processes do:
ps aux | awk '{ print $8 " " $2 }' | grep -w Z


kill -9 pid
might also work.


Reference

Thursday, April 7, 2011

TexShop MacTex US letter PDFs

By default when you install MacTex and use TexShop for writing and compiling latex you will get PDFs with page size A4. This is all fine for most cases but some conferences require you to submit in US letter format and do not accept A4. This is where the problem begins and all sorts of solutions are proposed on the Web and most require you changing your entire latex configuration to produce US letter size (at least temporary until you revert those changes back to A4). Naturally, I tried those solutions (giving up the hope of finding a solution that can do this paper size change per document basis as it should be and not for the entire latex system) but failed. So I adopted the following command line approach and it works like a charm even without having to modify a single configuration file.

So I thought I would share this solution with the rest of the world.


  1. First things first. Write your document using TexShop (producing A4 size PDFs as it is done by default) and concentrate on the content of the document. At the end of the day that is what matters most. :-)
  2. Now open a Terminal and type the following command to produce a dvi file.
    /usr/texbin/latex mypaper.tex
    Of course, the path to latex (/usr/texbin/latex) depends on your MacTex installation and this is the default installation path. This will produce the 'mypaper.dvi' file.
  3. Now we can convert this dvi to a PDF with suitable page size (US letter in this case) using the following command.
    /usr/texbin/dvipdfm -p letter mypaper.dvi
    This command will produce the 'mypaper.pdf' with the US letter paper size. By the way the dimensions for those two sizes are as follows.
    US letter: 215.9mm x 279.4mm
    A4: 210mm x 297mm source is Wikipedia.
  4. This does the trick! Of course you can also produce a postscript (ps) file if you want to. (Some publishers ask for this one as well.)
    /usr/texbin/dvips -t letter mypaper.dvi -o mypaper.pdf
    Another option to generate a pdf is from this ps file. You can use Acrobat distiller for this purpose. But then why would need to do that when you can do that directly using dvipdfm from the dvi file.
Well, at the end of the day there is no alternative to the power of the command line.... :-)

Additional Note
If you are using pdflatex and do not want to go through the above tex->dvi->pdf routine OR you are compiling with sig-alternate class in the ACM template, creating US letter size PDFs might be difficult.
A good reference is here.
The solution proposed in that reference is to put the following page size modifying lines in the preamble of the document (where you would put \usepackage commands and is prior to \begin{document} is called the preamble in a tex document.).

\setlength{\pdfpagewidth}{8.5in}
\setlength{\pdfpageheight}{11in}



This indeed works!

Tuesday, February 22, 2011

Numpy Exceptions

To print all warnings in numpy do the following

import numpy as np
np.seterr(all='print')

This will print all warnings to stderr.

You can also make warnings to exceptions.
An example is shown below. The documentation is here.


import numpy

numpy.seterr(all='raise')

s = 10000.0

try:
    x = numpy.exp(s)
    print x
except:
    print "That is too big!"




Sunday, January 30, 2011

How to change Figure and Table captions in LaTex

Usually figures and tables in LaTex get captions such as Figure 1 or Table 1. We can change these to other names as follows.

\renewcommand{\figurename}{Fig.}

OR to Japanese captions such as (with jarticle class)


¥renewcommand{¥figurename}{図}
¥renewcommand{¥tablename}{表}

Continuously monitor GPU usage

 For nvidia GPUs do the follwing: nvidia-smi -l 1