Friday, October 14, 2011

How to change cygwin terminal to a better one

  1. Download Cygwin and install it.
  2. Download puttycyg and unpack it somewhere. For example at the "puttycyg" folder on your desktop.
  3. Cygwin created a shortcut on the desktop. Right click on it, select "Properties". Change "Target" line to
    "%USERPROFILE%\Desktop\puttycyg\putty.exe" -cygterm -
To change your default shell in cygwin, first make sure it is installed. Then edit /etc/passwd.

Thursday, June 30, 2011

How to install SS SiteBoost 0.29b with Firefox 5 and newer.

SS SiteBoost is a nice add-on for Firefox, enhancing the Shutterstock's user interface for contributors.

Unfortunately, the version 0.29b is disabled as incompatible in Firefox 4. It actually works fine, you just need to change the max supported version of Firefox from 4.0b8pre to 4.0:

  1. Go to the author's web site: http://351.pl/ss_siteboost_FF.html. Right click on "SS SiteBoost 0.29" and save it on your computer.
  2. sssiteboost.xpi is nothing more than a zip archive. Open it and extract install.rdf file (you may need to temporarly change .xpi extension to .zip).
  3. In install.rdf, find 4.0b8pre and change it to 5.0.*
    similar idea works for the newer or older versions of Firefox.
  4. Pack the modified install.rdf back into sssiteboost.xpi.
  5. Drug and drop sssiteboost.xpi into the Firefox window to install.

Tuesday, May 10, 2011

How to use Python Profiler

The simplest way to profile a python program is to run:

python -m cProfile --sort cumulative youprogram.py

The other sorting options are:

callscall count
cumulativecumulative time
filefile name
modulefile name
pcallsprimitive call count
lineline number
namefunction name
nflname/file/line
stdnamestandard name
timeinternal time

The profiling results are dumped to console. Use

python -m cProfile --sort cumulative youprogram.py > profile.txt

to forward all console output to profile.txt file.

Wednesday, April 6, 2011

How to install SS SiteBoost 0.29b with Firefox 4

SS SiteBoost is a nice add-on for Firefox, enhancing the Shutterstock's user interface for contributors.

Unfortunately, the version 0.29b is disabled as incompatible in Firefox 4. It actually works fine, you just need to change the max supported version of Firefox from 4.0b8pre to 4.0:

  1. Go to the author's web site: http://351.pl/ss_siteboost_FF.html. Right click on "SS SiteBoost 0.29" and save it on your computer.
  2. sssiteboost.xpi is nothing more than a zip archive. Open it and extract install.rdf file (you may need to temporarly change .xpi extension to .zip).
  3. In install.rdf, find 4.0b8pre and change it to 4.0.*
  4. Pack the modified install.rdf back into sssiteboost.xpi.
  5. Drug and drop sssiteboost.xpi into the Firefox window to install.

Sunday, February 20, 2011

Latex: Reduce PDF file size with latex + dvips + ps2pdf

Recently I have run into a funny problem with pdflatex. My one page document compiled in 111kb PDF file. How could it be that one page of plain text with no graphics or anything fancy generates such a huge file? Usually I don't care, we all have broadband and terabytes of the space on our hard drives these days. I didn't even noticed that until it was rejected by some weird submission system that has a strict limit on the file size. Trying different things, I found that the combination of latex + dvips + ps2pdf reduces the file size by almost 3 times:

pdflatex 111,214 bytes
latex + dvips + ps2pdf 40,544 bytes

As far as I know, pdflatex dumps all possible glyphs in the resulting pdf causing such a big difference, while the other option does not. Visually I found no significant difference between these two documents to bother with a bigger file.

Unfortunately TeXworks does not have an option for latex + dvips + ps2pdf by default, so I had to create it myself. It requires a few tricks (the instructions are for Windows, but the same idea works for Linux/Mac):

  • Create a latex-dvips-ps2pdf.bat somewhere on your drive with the following line
    @latex -synctex=1 "%1.tex" && dvips "%1.dvi" && ps2pdf "%1.ps"
  • In TeXworks open Preferences, Typesetting tab. Add "latex -> dvips -> ps2pdf" to Processing tools. Point to your latex-dvips-ps2pdf.bat file and provide $basename as your argument.
  • Try it and check your paper size.

If you use a different paper size than the one used in your latex system, you may run into problems. ps2pdf knows nothing about the paper size you've specified in you latex file. If you use MiKTeX, you can modify paper size in the MiKTeX settings program, say A4 or Letter (letterSize didn't work for me), otherwise you may need to include additional parameters for dvips and ps2pdf in your bat file.

Friday, January 14, 2011

How to install an LPR printer in Windows

To install an LPR printer in Windows 7 (and similarly in Windows Vista) you need to enable LPR ports first:
  1. Open "Control Panel".
  2. Select "Programs and Features" (use search field if it's hard to find).
  3. Click "Turn Windows Features on or off".
  4. In "Print and Document Services" turn on the "LPR Port Monitor".
then, install the printer:
  1. Open "Devices and Printers".
  2. Click "Add a Printer".
  3. Select "Add a local printer".
  4. Provide the IP of the print server and the queue name.
  5. Select the printer driver.

Thursday, November 4, 2010

Programming: a danger of a complex code

I'm teaching "Programming in C" this semester. It's a short introductory course and it's fun to see how students find their way through it. Same time it gives me some interesting statistics on students' most typical mistakes and helps me think about programming from a different perspective.

In the last lab exercise, we had to multiply 3x3 matrix A by 3x1 vector x and print out the results. How do you do that?

For example, you can do it like this (1):

y[0] = A[0][0]*x[0] + A[0][1]*x[1] + A[0][2]*x[2];
y[1] = A[1][0]*x[0] + A[1][1]*x[1] + A[1][2]*x[2];
y[2] = A[2][0]*x[0] + A[2][1]*x[1] + A[2][2]*x[2];

or like this (2):

for(i=0;i<ROWS;i++)
  for(j=0;j<COLS;j++)
    y[i] += A[i][j]*x[j];

I always thought, that (2) is a better solution. I'm not so sure anymore. 75% of my students forgot to explicitly initialize y[i]'s to 0. They've tested their program and it worked because the compiler initialized y for them, but still it is a potentially dangerous piece of code!

So, which solution is better? Rigid, but error proof and easy to read, or scalable, but more complex? Depends on the problem, but for this problem the guys who used (2) loose 2 points for not initializing their y's :-)