Friday, July 31, 2009

New version of matplotlib out : 3D plotting!

The hard working folks at matplotlib have put out a new release candidate with interesting new features.

Remember - its a release candidate. Not (yet) for production.

Get it from http://drop.io/xortel1#
Install using sudo easy_install ~/Downloads/matplotlib-0.99.0.rc1_r0-py2.5-macosx-10.5-i386.egg
On mac you will hear complaints about
Searching for matplotlib==0.99.0.rc1-r0
Reading http://pypi.python.org/simple/matplotlib/
Reading http://matplotlib.sourceforge.net
Reading https://sourceforge.net/project/showfiles.php?group_id=80706&package_id=278194
Reading https://sourceforge.net/project/showfiles.php?group_id=80706&package_id=82474
Reading http://sourceforge.net/project/showfiles.php?group_id=80706&package_id=82474
Reading http://sourceforge.net/project/showfiles.php?group_id=80706
No local packages or download links found for matplotlib==0.99.0.rc1-r0
error: Could not find suitable distribution for Requirement.parse('matplotlib==0.99.0.rc1-r0')
but it will be installed fine.

Most interesting is the incorporation of 3D plotting.

from mpl_toolkits.mplot3d import axes3d
import pylab

x = y = pylab.arange(-1,1.0,.05)
X, Y = pylab.meshgrid(x,y)
Z = pylab.cos(pylab.pi*X) * pylab.sin(pylab.pi * Y)
fig = pylab.figure(); ax = axes3d.Axes3D(fig); cset = ax.contourf(X, Y, Z, 20);

Tuesday, July 21, 2009

Class and Instance Methods in Ruby

From here
class A
def self.class_method
puts 'class method'
end

def instance_method
puts 'instance method'
end
end

Thursday, July 16, 2009

Openterminal

http://homepage.mac.com/thomasw/OpenTerminal/

Lets you select a folder in finder and opens a terminal cd'd to that folder.

Interestingly, this is a free but not opensource app. This seems to be the culture around Macs - apps written specifically for Mac are less likely to be opensourced.

Thanks to Jon Hendry for the link.

Wednesday, July 15, 2009

Installing mongrel on mac OS X with ruby 1.9.1

What. A. Pain.

UPDATE: I'm now using thin instead of mongrel.

When you go to do sudo gem install mongrel it will barf with some errors related to a file called http1.c Stop. Do not adjust the channel. There is nothing wrong with your computer. Somebody goofed in the source code. From instructions here, you have to make the following changes to the source. Remember to edit as root, don't run gem install mongrel again - you will overwrite your corrections.

This stuff was worked out by Alan and clarified by Ami Mahloof
1) cd /usr/local/lib/ruby/gems/1.9.1/gems/mongrel-1.1.5/ext/http11

2) sudo vi / mate on http11.c and:

replace line 77 with

for(ch = RSTRING_PTR(f), end = ch + RSTRING_LEN(f); ch < end; ch++) {

replace line 172 with
colon = strchr(RSTRING_PTR(temp), ':');

replace line 174 with

rb_hash_aset(req, global_server_name, rb_str_substr(temp, 0, colon - RSTRING_PTR(temp)));

replce line 176,177

rb_str_substr(temp, colon - RSTRING_PTR(temp)+1,
RSTRING_LEN(temp)));

replace lines 298 299

dptr = RSTRING_PTR(data);
dlen = RSTRING_LEN(data);

3) save the file, close the vi / textmate

4) sudo ruby extconf.rb && sudo make && sudo make install

5) cd ../../lib/mongrel
(or the full path "/usr/local/lib/ruby/gems/1.9.1/gems/mongrel-1.1.5/lib/mongrel"

6) mate / sudo vi handlers.rb

7) fix the case statements in

On lines 208-212, change instances of ": false" to "then false"

8) sudo gem install gem_plugin (else mongrel may hang)
Full error message:
local:Rriki2 kghose$ sudo gem install mongrel
Building native extensions.  This could take a while...
ERROR:  Error installing mongrel:
ERROR: Failed to build gem native extension.

/usr/local/bin/ruby extconf.rb install mongrel
checking for main() in -lc... yes
creating Makefile

make
gcc -I. -I/usr/local/include/ruby-1.9.1/i386-darwin9.6.0 -I/usr/local/include/ruby-1.9.1/ruby/backward -I/usr/local/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -fno-common -D_XOPEN_SOURCE=1 -O2 -g -Wall -Wno-parentheses  -fno-common -pipe -fno-common  -o http11.o -c http11.c
http11.c: In function ‘http_field’:
http11.c:77: error: ‘struct RString’ has no member named ‘ptr’
http11.c:77: error: ‘struct RString’ has no member named ‘len’
http11.c:77: warning: left-hand operand of comma expression has no effect
http11.c:77: warning: statement with no effect
http11.c: In function ‘header_done’:
http11.c:172: error: ‘struct RString’ has no member named ‘ptr’
http11.c:174: error: ‘struct RString’ has no member named ‘ptr’
http11.c:176: error: ‘struct RString’ has no member named ‘ptr’
http11.c:177: error: ‘struct RString’ has no member named ‘len’
http11.c: In function ‘HttpParser_execute’:
http11.c:298: error: ‘struct RString’ has no member named ‘ptr’
http11.c:299: error: ‘struct RString’ has no member named ‘len’
make: *** [http11.o] Error 1


Gem files will remain installed in /usr/local/lib/ruby/gems/1.9.1/gems/mongrel-1.1.5 for inspection.
Results logged to /usr/local/lib/ruby/gems/1.9.1/gems/mongrel-1.1.5/ext/http11/gem_make.out

Saturday, July 11, 2009

Avoid buffered printing into nohup.out

Invoke with

python -h

this prevents print statements from being buffered (e.g. when being dumped into a nohup.out file)

Wednesday, July 8, 2009

Include program listing in latex document

Use the listings package, in combination with the colors package

Use \usepackage[usenames]{color} to preload 68 color definitions (otherwise you only get about 5 boring colors).

Documentation for colors is here.

Sunday, July 5, 2009

Internet speed over HMS secure connection


Hmm... I guess they throttle downloads, but I have 5/20 service, how can I upload faster?

This is the speed test without secure conection

Wednesday, July 1, 2009

Matplotlib (numpy) : max index of multidimensional array

If x is multidimensional pylab array x.argmax() returns the flat index (converts the multidimensional array into a flat vector before finding the max/min). The pylab function unravel_index comes to our help

pylab.unravel_index(x.argmax(), x.shape)

From a hint here.