Tuesday, February 9, 2010

Mencoder: Change speed and size of movie and output such that Quicktime can play it

mencoder input.mp4 -speed 0.33 -vf scale=450:360 -ovc lavc -ffourcc DX50 -oac pcm -o output_slowmo_small.avi

The -ffourcc DX50 makes it quicktime playable
The pcm is needed when we change speed (copy won't work)

Monday, February 8, 2010

TimeTracker - see what files Time Machine is backing up

1.9GB backup! Since yesterday? I work hard, but not that hard. I wanted to see what exactly was getting backed up. Time Machine doesn't let you do that but TimeTracker from CharlesSoft allows you to peek into your Time Machine backups and see what is getting backed up for each backup and how big it is. For instance, its annoying but my email trash is getting backed up. It would, however, take too much time to go through and find every little think that I don't want backed up but is getting backed up, so...

Sunday, February 7, 2010

Mac OS X time machine: deleting backups

From here:
You can delete specific folders and files from the backups, deleting all backups if needed. Open a finder window, navigate to the folder, open time machine, click the gear icon and select 'Delet backup'. If you are in the tree view you have an option to delete all backups of the selected folder.

LaTeX equations in inkscape on Mac OS X (10.5.8)

Warning message when trying to use the Tex extension:
The fantastic lxml wrapper for libxml2 is required by inkex.py and therefore this extension. Please download and install the latest version from http://cheeseshop.python.org/pypi/lxml/, or install it through your package manager by a command like: sudo apt-get install python-lxml
  1. Download and install libxml2 and xslt for mac from here. Follow install instructions. 
  2. STATIC_DEPS=true easy_install lxml
  3. sudo easy_install lxml
Leads to next error message
Contents/Resources/extensions/textext.py:55: DeprecationWarning: the md5 module is deprecated; use hashlib instead
  import os, sys, tempfile, traceback, glob, re, md5, copy
Traceback (most recent call last):
  File "Contents/Resources/extensions/textext.py", line 933, in <module>
    e.affect()
  File "/Applications/Writing/Inkscape.app/Contents/Resources/extensions/inkex.py", line 207, in affect
    self.effect()
  File "Contents/Resources/extensions/textext.py", line 348, in effect
    % ';\n'.join(converter_errors))
RuntimeError: No Latex -> SVG converter available:
Pdf2Svg: Command pdf2svg failed: [Errno 2] No such file or directory;
PstoeditPlotSvg: Command pstoedit -help failed: [Errno 2] No such file or directory;
SkConvert: Command pstoedit failed: [Errno 2] No such file or directory

  1. Down load and expand pstoedit from here.
  2. ./configure
  3. make
Fails, some problem with ImageMagic. From here we can compile without all that.
  1. ./configure --without-magick
  2. make
  3. sudo make install
More later

Saturday, February 6, 2010

Mobile phone <-> email (T-mobile)

From here and here:

e-mail to phone:
e-mail address: [phone number]@tmomail.net
Subject:Subject
Body:Body
Resulting SMS:[my email]/Subject/Body

phone to e-mail:
Phone number: 500
Text: [your email]/Subject/Body
Resulting email
Subject: Subject
Body: Body

Tuesday, February 2, 2010

qmake redux

In QT 4.6 qmake's default behavior has changed. If you just run qmake it will generate an xcode project. You now need to do
qmake -spec macx-g++
To force generation of a makefile

Monday, February 1, 2010

Inkscape, Mac OS X and X11

X11 latest version (XQuartz 2.4) copies stuff as a bitmap by default. Switch that off in the preferences to copy vector graphics.

ALT key won't work, preventing us from doing super script and subscript (kerning with ALT+up or down arrow keys)

ALT key can be made to work like this or this (but I was not successful)

Sizing for posters, talks and papers

Following society for neuroscience guidelines for figures:
Text on figures should be 2-6mm high -> 5.6pt to 17pt
Using figure labeling to be at least 8pt Arial for papers = 2.8mm
Use a scaling of x2 for talks = 5.6mm
Use a scaling of x4 for posters =  11.3mm

Sunday, January 31, 2010

"An error occurred while extracting one of the Network Connect components"

I love VPN. It allows me to log into my work computers from home and annoy them by giving them large amounts of work to do while I sleep. Harvard Medical uses a solution from Juniper Networks, and the client app is called Network Connect.app We I went to connect, and I'm told to update and I say OK. And then I get this error message. I can't install the new version. 40 minutes later after following up several false leads, I find a JN page by copying and pasting the exact error message. It turns out that updating Java on my mac (which I guess I did at some point) changes some default password stored deep in the guts of Java from “changeit” to “changeme”.

I gota few things to say about this. The PG rated ones are
  • After looking through Juniper Network's knowledge base I have to say, the guy (or guys) in charge are pretty professional and thorough.
  • Their website could do with a little bit better navigation though
  • I would have expected Sun engineers to comeup with a better mechanism for a default password than putting 'changeit' or 'changeme' somewhere. Make a separate mechanism for password free access and give an option to activate a password if one wishes.
  • Now that I've changed the password back, I wonder what this now breaks?
God, and these machines will be taking care of us in our old age...

Friday, January 29, 2010

Strange behavior of dict from Manager() in python's multiprocessing module

import multiprocessing as mp

def f(d):
  d['f'] = {}
  d['f']['msg'] = 'I am here'

manager = mp.Manager()
d = manager.dict()

p = mp.Process(target=f, args=(d,))

p.start()
p.join()

print d

d = {}
f(d)

print d


Output:

{'f': {}}
{'f': {'msg': 'I am here'}}



Whaa???? BUGREPORT!

Update: Some one has suffered before me.

Thursday, January 28, 2010

Setting default sorting order in a rails model

class Note < ActiveRecord::Base
  default_scope :order => 'date DESC, title'
end

Tuesday, January 26, 2010

time.time() vs time.clock()

From a variety of sources, notably here, we have:

time.clock() gives the best timer accuracy on Windows, while the time.time() function gives the best accuracy on Unix/Linux.

Additionally on non 'win32' systems time.clock() will measure application CPU time, which excludes time spent waiting for I/O while time.time() will measure 'absolute' time. On win32 time.clock() also measures CPU time.

If you want to time your code and get absolute times, do what timeit does:

if sys.platform == "win32":
    # On Windows, the best timer is time.clock()
    default_timer = time.clock
else:
    # On most other platforms, the best timer is time.time()
    default_timer = time.time

Monday, January 25, 2010

MS word citations file formats etc.

  1. There is one citations file called Sources.xml, created after you add your first citation
  2. On Mac the location is ~/Documents/Microsoft User Data (see here for windows specific info)
  3. There is a paucity of documentation on the format (so surprising, no?) but various people have put effort into understanding it:
    1. Straight forward code on one page for a bibtex to xml conversion.
    2. Some one's journal of reverse engineering the xml format. 
    3. bibutils - command line tools to convert citations between various formats
    4. BibTex -> citation converter by Joonhwan Lee (closed source, free)

In short, while MS Word has wasted time and effort reinventing the wheel (and doing so badly) at least the format is text based. Really, all we need to do is convert our PIs to using LyX and we don't have to deal with this %$#@@ any more!

Sunday, January 24, 2010

iTunes : getting songs from the same album to group together

When I pulled some of my CDs to iTunes I found that sometimes songs from the same album would appear, in album view, as different albums. It was very annoying. It turns out that iTunes won't group songs with the same album name but different artist (or different album artist) into the same album in album view. The solution is to select all the songs you think should be in the same album, right click for 'info' and then under 'options' check 'part of a compilation'. Make sure that the album artist is the same or is blank.

From apple's support page.

Thursday, January 21, 2010

Firefox 3.6 : new tab

New tab opens right next to the active one, not at the end of the currently open tabs. Nice.

Wednesday, January 20, 2010

Rubble pile asteroids

As a child I learned about asteroids and have pictured them as solid pieces of rock of different sizes. Apparently, though, there have been suggestions since the 1970s and recent empirical data that some asteroids are actually collections of smaller rocks held loosely together by mutual gravity.

I don't know what proportion of asteroids are not monolithic, whether the majority of asteroids are such piles of rubble, but this was a piece of information that startled me, because it is from a field I was very interested in as a child, and as a child I had taken the astronomical statements as fact, rather than as interpretations of incomplete data.

The statement that asteroids are not monolithic blocks of stone, but are rather collections of small rocks is more interesting to me than some stupid political discussion about whether we should call a celestial body a 'planet' or a 'dwarf planet' or a salami hamburger.

From an article in Nature, this page and wikipedia it seems that the evidence for asteroids being rubble piles is:
  1. Many asteroids have very low desities, indicating a lot of empty space within them
  2. Clark R. Chapman and Donald R. Davis theoretically showed from energy considerations that, after a collision, pieces of an asteroid were more likely to fall back together under mutual gravity, than to fly apart.
  3. Many asteroids have large craters on them. If the asteroids were solid, the collision that generated such a large crater would have shattered the asteroid. If the asteroid was a rubble pile, the loose collection of rocks would absorb and dissipate the energy remaining together as a pile.
  4. No large asteroid has been found that spins faster than the limit at which a collection of rocks of that size would fly apart due to centrifugal force (bite me).
  5. When near earth asteroids pass us, their shape is altered due to tidal forces to an extent only possible if they are collections of small rocks.

I had a dream once, of sending robot spaceships to mine the asteroids and bring back valuable materials. I need to revise the design a little bit...

Monday, January 18, 2010

Some advice on posters

@swarthmore - a web page by Colin Purrington.

Some interesting links from that article:
Poster flickr group
ePosters.net

Sunday, January 17, 2010

QT 4.6 : QListView will not show an updated model without focus

I moved an application I wrote and use from Qt 4.2 to Qt 4.6. I have a widget where there is a QListView associated with a QStringListModel. I type in a text box, hit enter and add text to the QStringListModel. In Qt 4.2 this would cause QListView to automatically show the updated model. In 4.6 the updated view is only shown if QListView has focus. So now I have to setFocus() on the QListView and then setFocus() on the text box to make QListView show the updated model.

Bugreport

And we think these computers will be taking care of us in our old age.
Sigh.

PS. On the plus side, 4.2 had a bug where a text edit would not accept the enter key and would pass it onto the parent widget which would cause a dialog box with a text edit to be accepted. That has been fixed.

Trolltech giveth and trolltech taketh.

Monday, January 11, 2010

Altering Python strings

Python strings are immutable. Which means, that unlike in ruby and some other languages you can not do:

str = 'Dodge This'
str[-2:] = 'at'


You need to do:

str = 'Dodge This'
str = str[:-2] + 'at'

Friday, January 8, 2010

String escaping for database queries in Python

From python docs, use parameter substitution rather than some complicated home brewed escaping solution:

Sqlite uses '?' (question marks) as placeholders

Sunday, December 6, 2009

Splinter Cell: Chaos Theory - disabling lights

Well, the right click (alt fire) on the suppressed pistol activates some magic device that can temporarily knock out a light - for about 10s or so. Why did I have to search on the internet and track down vague clues until I hit this page and found out for sure? Shouldn't there  be a manual somewhere? UPDATE: I gotta read the notes on the equipment screen more carefully...

UPDATE2: The manual is useful. Save trees/animal skins, don't print it out.

Friday, December 4, 2009

Max os x service start up : StartupItem

A good guide is available here

File:  /Library/StartupItems/RRiki/StartupParameters.plist:

{
 Description = "RRiki server";
 Provides    = ("RRiki");
 Uses        = ("Ruby");
 OrderPreference = "Last";
 Messages =
 {
  start = "Starting RRiki server";
  stop = "Stopping RRiki server";
  restart = "Restarting RRiki server";
 };
}


File: /Library/StartupItems/RRiki/RRiki

#!/bin/sh

##
# RRiki service startup script
##

. /etc/rc.common

StartService ()
{
    ConsoleMessage "Starting RRiki"
    cd /Users/kghose/Source/Rriki2/
    /usr/local/bin/thin start -eproduction -d
}

StopService ()
{
    ConsoleMessage "Stopping RRiki"
    cd /Users/kghose/Source/Rriki2/
    /usr/local/bin/thin stop 
}

RestartService ()
{
    ConsoleMessage "Restarting RRiki"
    cd /Users/kghose/Source/Rriki2/
    /usr/local/bin/thin restart -eproduction -d
}

RunService "$1"


To manipulate the service:
sudo SystemStarter restart RRiki

Thursday, December 3, 2009

Moved from mongrel to thin

Now using thin rather than mongrel. Seems to be fast and responsive and most importantly installs without errors.

Calling an action when a selection box changes

in partial (view)

<%= select('history', 'sel', history_list, {:selected => selected}, {:class => 'historyselect'}) %>
<%= link_to_remote 'x',
      :url => {:controller => 'rriki',
               :action => 'clear_history'},
      :html => {:title => 'Clear history'},
      :method => :get %>
<%= observe_field 'history_sel',
    :url => {:controller => 'rriki',
             :action => 'select_item_in_history'},
    :with => 'history_sel' %>


changing the select will call the action select_item_in_history with params['history_sel'] set to the selected value.

Testing to see if a variable exists in ruby

Partials can take parameters (called locals), but can crash your app if a caller does not pass a local and you try and access it in the partial. You can use the following construct to initialize a variable if it does not exist

var = nil unless defined?var

where var is your variable

Rails: Debugging form helpers generated with remote calls (AJAX)

When parts of a webpage are updated using AJAX calls (e.g remote functions) these updated parts do not show up when you ask Firefox for the webpage html (using CTRL+U). A hack to see the generated html from a suspect rails call is to simply print out the html on the webpage instead of executing it by doing:

<%=h ...rails command... %> Instead of

<%= ...rails command... %>

html_options for rails select tag

I had a select tag that I wanted to mess with a little to apply some styles etc. to. The select tag has an html_options hash and I was trying to use that. My initial attempt was

select('history', 'sel', history_list, html_options => {:class => 'historyselect'}) WRONG

This is not python, and even though the rails docs setout the syntax as:

select(object, method, choices, options = {}, html_options = {})

ruby can not accept keyword arguments. Only positional, so you have to do:

select('history', 'sel', history_list, {}, {:class => 'historyselect'})

The empty braces signify the empty 'options' argument, and the next set of braces signify the html_options hash

Tuesday, November 24, 2009

PAN = FOA

At NIH when you look at a grant they all have a Program Announcement number (PA). When you go to grants.gov they ask for the Funding Opportunity Announcement number (FOA). The first test of eligibility to apply for the grant is to realize that they both mean the same thing...

Wednesday, November 11, 2009

Running a script from the regular python shell

regular python shell: execfile('myscript.py')
ipython: run myscript.py
           : run -i myscript.py (if you want the script to have access to the workspace variables)

Tuesday, November 10, 2009

Installing brian

  1. nose
  2. sympy