Monday, March 31, 2008

PyScripter

Oooo, shiny. PyScripter is awesome. From my spoilt python brat wishlist we have:
  1. Tabbed interface like Notepad++ and SciTE [CHECK]
  2. Remember session like Notepad++ [CHECK]
  3. Code context like IDLE editor [And More CHECK]
  4. Line numbers like SciTE [duh, CHECK]
  5. Adjustable tabbing and smart indent like SciTE (And not like IDLE; shudder) [OK, can't figure this out, but at least it does not mess up my existing indenting]
  6. Autocompletion like IDLE [And More CHECK]
  7. Debugger would be nice, but IPython happens to be all I need right now for that [CHECK]
  8. Folding [Ok, this seems to be missing]
In addition the little things I noticed were:
  1. Picture of bug before file name in tab, when file has a parsing error. Sweet touch

Word 2007...

... They only inserted bugs in Word 2003 so that people would be so relieved when 2007 came along.

Any how, exporting to pdf via Word 2007 was glitch free (for a 186 page thesis, with several figures).

Thanks to Ben for the pointer to word 2007.

Thursday, March 27, 2008

Microsoft word : annoying background color in figures

From here.

  1. Select figure
  2. On picture toolbar click 'set transparent color'
  3. Click on part of the figure that should show up white/no color

Microsoft word remove all comments

Goto reviewing panel, find 'remove all comments'

Diassembling a HDD

  1. Old plastic is brittle
  2. You need to take off all the screws, some of which are hidden under the stickers [here]
  3. The lid of the HDD comes off very easily
  4. The HDD platter is SHINY.
  5. The magnets that are part of the head assembly are strong! Fun!

Wednesday, March 26, 2008

IDE for Python (II)

Following up on a previous post about IDEs for Python, my current wishlist would be:

  1. Tabbed interface like Notepad++ and SciTE
  2. Remember session like Notepad++
  3. Code context like IDLE editor
  4. Line numbers like SciTE
  5. Adjustable tabbing and smart indent like SciTE (And not like IDLE; shudder)
  6. Autocompletion like IDLE
  7. Debugger would be nice, but IPython happens to be all I need right now for that
I'm gonna try out pyscripter...

Tuesday, March 25, 2008

Customizing polar plots in matplotlib

import pylab as m

m.polar(m.arange(360)*m.pi/180., m.rand(360))
m.thetagrids(angles, labels=None, fmt='%d', frac = 1.1)
m.rgrids(radii, labels=None, angle=22.5)


angles can be empty
radii has to be a tuple

Inkscape + matplotlib's svg = one strange love child

Heh, heh. Just when my analysis was coming along at a nice clip...

Here is part of figure1 (png shot of)



Here is part of fig2


And here is what happens when I copy fig2 and paste it into fig1


Note that the above figure should look exactly like fig2...
I LOVE Inkscape, I LOVE matplotlib, and I'm attached to my toolchain, I hope this can be fixed.

UPDATE:
  1. See this thread
  2. Mike has fixed the problem is SVN - you should replace the backend_svg.py with the one linked in Mike's post.

matplotlib : subplot with polar

Polar plots in matplotlib are generated using the polar(theta, R) command. The source for this command is simply (from the amazing '??' feature of IPython):

In [37]: m.polar??
Type: function
Base Class:
String Form:
Namespace: Interactive
File: c:\python25\lib\site-packages\matplotlib-0.91.2-py2.5-win32.egg\
matplotlib\pyplot.py
Definition: m.polar(*args, **kwargs)
Source:
def polar(*args, **kwargs):
"""
POLAR(theta, r)

Make a polar plot. Multiple theta, r arguments are supported,
with format strings, as in plot.
"""
ax = gca(polar=True)
ret = ax.plot(*args, **kwargs)
draw_if_interactive()
return ret


In order to make a subplot polar we simply add the polar=True argument thus:
m.subplot(nrows, ncols, nsubfig, polar=True)

Otherwise, it is treated as a cartesian plot even if you do m.polar(..) afterwards.

Matplotlib SVN repo

The code is a little hard to find so here is the pointer in svn at sourceforge

/trunk/matplotlib/lib/matplotlib

SCP into rubyforge

[From here]

user name is: yourrubyforgeusername
server name is: rubyforge.org
directory is: /var/www/gforge-projects/your-rubyforge-project-name

Use winscp for windows.

Monday, March 24, 2008

Set figure size

In matplotlib you set figure size as follows [from here]:

import pylab as m
f = m.figure()
f.set_size_inches((2,6))


which will make the figure 2in wide and 6in tall which works at least for SVG export

Saturday, March 22, 2008

Should I move RRiki from Ruby(Rails) to Python?

It boils down to
  1. Rails automagically uses the database contents to create an interface, in the other frameworks you have to explcitly create a database in the code.
  2. I use Python for computing, why not use it for note taking too.
Comparison of Rails and Django. [bright-green]

Possible Python frameworks:

web2py. - no configuration/install to use, can be used from a USB drive. After a laptop crash that option looks tempting..., has migrations which Django doesn't.

UPDATE: I'm not moving for now due to time constraints. I will at most look into using SQlite, instead of MySQL

Computer power up after being bumped during a move

Computer froze half-way into boot up. Memory modules needed to be taken out and reseated (simple pressing in of modules was not sufficient).

MSI motherboard, ethernet setup

Loaded 'fail-safe' defaults for a MSI Neo Platinum motherboard. Couldn't see the ethernet card on windows. Loaded 'optimized-defaults' and the card showed. Fail-safe probably disabled the ethernet card

Wednesday, March 19, 2008

Installing Unision on Windows

Grab and install the precompiled binary [from metadata].
Grab and install GTK - don't get the one on Alan's page, get it from the sourceforge page.

And that should be enough to get Unison GUI running

Tuesday, March 18, 2008

Firefox and thunderbird profiles

The great thing about firefox and thunderbird is that they store their whole state (histories, bookmarks etc.) in folders and you can choose where the folder is located. I just put this with the rest of my junk that gets backed up regularly, so if I need to reinstall windows, I just point thunderbird and firefox to my profiles folder and I get everything back, including extensions, just like nothing happened.

Firefox and Thunderbird need their profiles.ini file modified [firefox help here and here, thunderbird help here]

Monday, March 17, 2008

Vista, HP DV2210us freezes at start of waking from sleep/hibernation

[also see this]

This is a HP dv2210us which has a Go 6150 graphics card. From this microsoft knowledge base entry, assuming that this card has a PCI-E bus (NVIDIA tech specs), I need this hotfix.

The hot fix doesn't work for me.

The computer is now such that it will not boot up easily - it gets stuck at a blank screen whenever I switch it on. I have to coax it to get past what ever is stopping it by hitting f8 and catching it at the right boot phase.

I'm gonna wipe the hibernation file and see if that works. No

I do get an error - \boot\memtest.exe 0xc0000221 file possibly corrupt, header checksum does not match the computed checksum.

I think I will restore the computer to the factory default (yes, I do not have vista disks, thank you HP and Microsoft).

2008.03.18: I think the computer has a problem shutting down when it is asked to restart.

2008.03.22: Apparently the HP service techs know about this problem and will fix it since it is under warranty. They promise delivery on April 15, so I will be laptop free for about 3 weeks at least. That said HPs warranty covers home pickup and delivery, so thats a bit less hassle. Now if only they had a loaner laptop service...

Help! I deleted the hibernation file

And my computer doesn't show the hibernate option nay more!

Don't panic, open an admin shell and type

powercfg -h on

Apartment complexes in the Boston suburbs

Went apartment hunting in expensive Boston.

Windsor Village at Waltham [web]. 10min drive from Alewife station on the red line. They have awesome two storied units, like little town houses with patios, on a hilly country side. Very pretty in the snow. About $1900/month without utilities. They have a week day shuttle from the complex to Alewife. Commuting to Boston is a hassle because of the two step process.

Avalon at Lexington Hills [web]. 15 min drive from Alewife station on the red line. They have very nice huge (1300 sq ft) two bedrooms costing about $2200/month without utilities. They have a week day shuttle from the complex to Alewife. Commuting to Boston is a hassle because of the two step process. They need you to have a cheap renters insurance, they have covered parking.

Overlook ridge, revere [web]. Reasonable units, some with a view of the old quarry. We saw a sunny 2 bedrrom. They have a pool room and a yoga room. They have a shuttle to Malden ctr T, and a shuttle to downtown, parking is included. Rent was about $1800. Again, the commute is a hassle, but not as much as the previous two.

An apartment complex near meadow glen mall, Malden, MA. Cheapish ($1600 for a 2 bed) not close to the T. A little shabby looking, reminded me of student accommodations.

Gateway apartment homes [web]. Right next to the Malden T, nice, a little hotel looking. Close enough to the T to hear it from your living room - may be not so nice. OK prices ($1895 - heat and hot water- + $80 parking), OK units, very convenient to transportation.

Wellington Place [web]. Right next to Wellington T. Very nice complex, but the neighborhood is shabby. $1800 for 2 bed, $120 for parking.

Oakgrovevillage [web]. Right next to Oak Grove T. Nice complex, close to Middlesex fells reservation. Pretty. Pricey ($1800 for a 1 bed, covered parking included, utilities extra)

USB drive won't remove : Optimizing TSVN cache

External USB drive, won't eject (remove safely), says its busy.

Running fsutil does not help.

Running process explorer (as admin) shows that TSVNcache.exe is holding onto folders I've recently accessed, even though I have closed the folder. What's up?

From here we see that this is from the Totoise SVN client and it is the process that puts those nice SVN icons on the folders. This webpage also tells us how to prevent TSVN from running on all folders and only on those we store our code in:

Go to SVN settings/Look and feel/Icons and set the exclude paths (or include paths). Kill TSVNcache.exe and voila, your hard drive will be let go.

I wonder if this has something to do with explorer nuking itself randomly?

Sometimes even this doesn't work, and its a small bug in Vista and XP [from here].

I just set the policies for 'quick removal' (no caching) and don't worry about safe removal anymore.

Changing how counters are referenced in LaTeX

\renewcommand{\thepage}{Figure \arabic{page}}

causes the page number (formerly 1,2,3 etc) to be replaced by Figure 1 2 3 etc.

List of counters and there manipulation here.

Sunday, March 16, 2008

Vista, HP DV2210us suddenly stops booting

When trying to come out of sleep. Blank screen, no HDD activity, no key response. Restarting the computer did not help. Taking battery out and then plugging it back in did not help. Panic! Hardware problem? Turns out no. I'm guessing the hibernation file got corrupted.

Hit f8 on switch on to get to a menu screen that will let you continue with boot.

Also see this entry.

Wednesday, March 12, 2008

Dynamical systems simulation in python

Trying out PyDSTools [webpage, download]
These guys look professional - they have a test suite that you can run to check everything out.
Issues:
  1. You need to put a file called PyDSTool.pth [read this]
    Play close attention to the trick about subdirectories - you have to repeat it for each level, not just the root level. I have my install in c:\programs\PyDSTool and my file has
    C:\\
    C:\\Programs\\
    C:\\Programs\\PyDSTool\\
  2. I have scipy version 0.6.0 but PyDSTool doesn't detect that properly. I commented out the relevant lines in PyDSTool's root __init__.py
    #if vernums[1] != 5:
    # raise RuntimeError("SciPy v0.5.1 or above is required")

    and it continued with the tests.
Things seem to work OK, only one thing was declared broken:
PyCont: appears to be broken on your system

But, there were periodic errors of the nature:

***** Testing script impfn_test.py ****************************

Gnuplot not available
------- Examples of implicit function as variable
1D example: a half-circle using newton's method (secant method for estimating de
rivative)
Change sign of 'y' initial condition to solve for other half-circle
Gen defined? => False
traj1 = testimp.compute('traj1')
Error in supplied functional specification code
Traceback (most recent call last):
File "impfn_test.py", line 54, in
traj1 = testimp.compute('traj1')
File "C:\Programs\PyDSTool\Generator\ImplicitFnGen.py", line 294, in compute
exec tempspec[0] in globals()
File "string", line 1
def _specfn_imptest_316e-006(ds, t, x, parsinps):
^
SyntaxError: invalid syntax

***** Testing passed on test file impfn_test.py


Which I can't understand

Tuesday, March 11, 2008

IDE solutions for Python (Windows, Vista)

It turns out that for me the best combination (ease of installation + features) is the following odd couple: Ipython + IDLE (I was using Ipython + SciTe)

IDLEs shell sucks compared to Ipython, but IDLE's code editor is awesome, especially considering that its comes standard with the python install.

Scite Does:
  1. syntax highlighting
  2. code folding
  3. can call python
  4. Multiple tabs
Does not:
  1. integrate with debugger,
  2. parse modules and methods
  3. code completion
IDLE Does:
  1. Syntax highlighting
  2. parse module and methods
  3. code completion
  4. code context
  5. integrate debugger
Does not:
  1. Fold code
  2. Have multiple tabs (annoying)

Monday, March 10, 2008

Installing python and friends on Windows (vista)

One way to go is to get the installer from Enthought [here]. This is the academic version, but their license agreement is not clear to me: it is not clear that even as a researcher working on public money in a university doing research I publish in publicly accessible journals and make available on my website, I can use this distribution. What you pay for is the convenience of having a lot of open source python related software bundled together. You also get a lot of packages you may not be using.

For me, the old fashioned hunter gatherer lifestyle leads me to the following course of action:
  1. Download and install python using the installer [python.org]
  2. Download and install setup tools [python.org, scroll to the bottom]
  3. Run command prompt as admin to use easy_install [guide here]
  4. Install ipython
    easy_install http://ipython.scipy.org/dist/ipython-0.8.2-py2.5.egg
    easy_install http://ipython.scipy.org/dist/pyreadline-1.5.dev_r2876-py2.5.egg
    [or whatever versions you want from that page]
  5. Install numpy
    The egg is through sourceforge, which doesn't have direct access, so download it to a directory and then use the egg from there
    easy_install "D:\Documents\My Downloads\numpy-1.0.4-py2.5-win32.egg"
  6. Install scipy
    Download the egg from sourceforge, and then easy_install:
    easy_install "D:\Documents\My Downloads\scipy-0.6.0-py2.5-win32.egg"
  7. Install matplotlib
    The egg is through sourceforge, which doesn't have direct access, so download it to a directory and then use the egg from there
    easy_install "D:\Documents\My Downloads\matplotlib-0.91.2.win32-py2.5.egg"
These steps take care of everything including 2D plots that are exportable to svg, but what about 3D plots? This gets more tricky.

Configuring Ipython

You can change the directory where Ipython stores its configuration files by [from here] changing the IPYTHONDIR environment variable. The default is ~/.ipython for linux and /_ipython for windows.

Put your personal Ipython fetishes (like yellow screen with red text - I don't want to know details) in the ipy_user_conf.py file found in the configuration directory.

In order to see the options available to you, in a python shell do the following

import IPython.ipapi
ip = IPython.ipapi.get()
o = ip.options
o

Changing colors [here]

Saturday, March 8, 2008

Trivia sections in wikipedia articles

Trivia sections are discouraged in wikipedia articles [policy]. Somebody decided that if we call them 'notable media references' instead [policy], people might think this is a serious encyclopedia.

Wikipedia will not be rembered for its content. It will be known for itself - a giant sociological experiment that reminds us what we are like.

PS. Most articles I look up in wikipedia, I go straight to the trivia, er, notable media references, section. Without the trivia, why I would look up a 'real' encyclopedia instead.

Calculus made easy

There is a calculus book in pdf form online at djm.cc. I found this in my search for a reference to Netwton's difference quotient method [wikipedia], which I use in a paper and which Jeff wanted me to put in a reference for.

Looking for a reference to Netwton's difference quotient method was instructive because it led me to a problem I had not had to deal with yet: if you have a numerical method for computing a function f(x) then the simple newton's difference quotient method

d f(x) f(x+h) - f(x)
------ = --------------
dx h

is problematic because for small values of h (as required by the method) f(x+h) is almost the same as f(x) and the difference and the division may lead you into rounding errors.

This paper addresses that issue.

Friday, March 7, 2008

Bats face preys that employ

I have the misfortune to be currently writing a paper with word. Its not that bad, and sometimes quite funny.

I started to type "Insectivorous echolocating bats face prey that employ a variety of" and I got a jaggy underline at "prey that employ". Apparently I should either use

Insectivorous echolocating bats face prey that employs a variety of

OR

Insectivorous echolocating bats face preys that employ a variety of

My meaning is the latter, but I suspect the plural of the word 'prey' is one of these nasty illogical things in English.

Thursday, March 6, 2008

Who is Mr. Divide?

Today, in Matlab land

>> 1/[1 2 3]
??? Error using ==> mrdivide
Matrix dimensions must agree.


Who is Mr. Divide, and why can't my matrix dimensions agree to disagree?

Tuesday, March 4, 2008

Where does the time go? In "link_to"

For a table with 9400 records:

The following code, all Ruby On Rails-ed up, takes 8.15s
<table>
<tr>
<% for column in Journalabbr.content_columns %>
<th align="left"><%= column.human_name %></th>
<% end %>
</tr>

<% for journalabbr in @journalabbrs %>
<tr>
<% for column in Journalabbr.content_columns %>
<td><%=h journalabbr.send(column.name) %></td>
<% end %>
<td><%= link_to 'Show', :action => 'show', :id => journalabbr %></td>
<td><%= link_to 'Edit', :action => 'edit', :id => journalabbr %></td>
<td><%= link_to 'Destroy', { :action => 'destroy', :id => journalabbr }, :confirm => 'Are you sure?' %></td>
</tr>
<% end %>
</table>

By removing content_columns and send_columns and explicitly stating what columns to print, and keeping the same output, the code takes 7.86s.
<table>
<tr>
<th>Full Journal name</th>
<th>Journal name abbr.</th>
</tr>

<% for journalabbr in @journalabbrs %>
<tr>
<td><%=h journalabbr.full_name %></td>
<td><%=h journalabbr.abbr %></td>
<td><%= link_to 'Show', :action => 'show', :id => journalabbr %></td>
<td><%= link_to 'Edit', :action => 'edit', :id => journalabbr %></td>
<td><%= link_to 'Destroy', { :action => 'destroy', :id => journalabbr }, :confirm => 'Are you sure?' %></td>
</tr>
<% end %>
</table>

Removing all erb takes 0.46s.
<table>
<tr>
<th>Full Journal name</th>
<th>Journal name abbr.</th>
</tr>

<% for journalabbr in @journalabbrs %>
<tr>
<td><%=h journalabbr.full_name %></td>
<td><%=h journalabbr.abbr %></td>
</tr>
<% end %>
</table>
Now, removing all link_tos and replacing them with explicit HTML and javascript, with the same functionality as the first code, takes 0.655s! Just as neat and much faster!
<table>
<tr>
<th>Full Journal name</th>
<th>Journal name abbr.</th>
</tr>

<% for journalabbr in @journalabbrs %>
<tr>
<td><%=h journalabbr.full_name %></td>
<td><%=h journalabbr.abbr %></td>
<td><a href='/journalabbr/show/<%= journalabbr.id %>'>Show</a></td>
<td><a href='/journalabbr/edit/<%= journalabbr.id %>'>Edit</a></td>
<td><a href='/journalabbr/destroy/<%= journalabbr.id %>' onclick="return confirm('Are you sure?');">Destroy</a></td>
</tr>
<% end %>
</table>
Cool code HTML escaping and highlighting from palfrader.org

Monday, March 3, 2008

Passing on the MacBook Air

Looked into Apple Macintosh Laptop computers, as the new lab is a mac lab and decided to pass on the MacBook Air.

In comparison to the MacBook I found
Pros:
  1. Light - 3 pounds (vs 5 pounds for Macbook and my current HP DV2210us)
  2. Illuminated keyboard
Cons:
  1. Max memory is 2Gb (vs 4Gb)
  2. Max CPU brawn 1.8GHz Core 2 Duo (vs 2.4 GHz Core 2 Duo)
  3. 80GB 4200-rpm 1.8in HDD (vs 250 GB 5400-rpm 2.5in HDD)
  4. No optical drive (vs 8x DVD burner)
  5. 1 USB 2.0 and NO firewire (vs 2 USB 2.0 and 1 firewire)
  6. No ethernet port
  7. The power connector and the USB slots open out awkwardly from the case base [engadget]
Mostly, this machine will be plugged into a keyboard, a large monitor and will sit on a desk doing number crunching and paper writing (Macs do all the work for you, right, not like PCs where you actually have to write the paper yourself). I imagined the awkwardness with which the MacBook Air would sit, with no ethernet cable, always relying on a wireless network, even for DVD burning/loading, with that side slot half propped open because I want to use a flash drive to move a file. So I decided to go with a fully muscled up MacBook that is as small (the tabletop size is just a bit smaller than the Air), slightly heavier, and has double the memory and triple the harddisk, and infinite times more firewire and ethernet.

Saturday, March 1, 2008

Setting css class/style for link_to_remote

Add the relevant code to :html as shown below
<%= link_to_remote 'click me',
:update => 'divid',
:url => {:controller => 'taxes', :action => 'show', :params => {:id => '2'}}, :html => {:style => 'text-decoration: none'} %>


You can also do :html => {:class => 'mycssclass'}

Note that this is different from link_to
<%= link_to 'click me', {:controller => 'taxes', :action => "show", :id => '2' }, :style => 'text-decoration: none' %>
which is annoying until you find out.