Monday 29 April 2013

executing shell commands from python

p = subprocess.call(['/bin/bash', '-c', 'ls *.pdf'], stdout=sub.PIPE, stderr=sub.STDOUT))

This is blocking.  For non-blocking use,

p = subprocess.Popen(['/bin/bash', '-c', 'ls *.pdf'], stdout=sub.PIPE, stderr=sub.STDOUT))


The p object has methods for interrogating the output from the command.

Python 2.7 has more options.  For < 2.7 use,


p = subprocess.Popen(['ls', '-l'], stdout=subprocess.PIPE).communicate()[0]
to get the output from the command.

Installing LaTeX packages (April 2013)

I have other instructions on this blog but the current configuration I'm using is:

Add,

export TEXINPUTS=~/texmf//:

to ~/.bashrc

Copy package contents into ~/texmf/tex/generic

Run texhash

Monday 22 April 2013

Using nbconvert

Following the instructions at https://github.com/ipython/nbconvert

In my path:

git clone https://github.com/ipython/nbconvert.git

Install all components listed at the top link (except sudo apt-get install texlive-full)

Conversion:

$ nbconvert.py  --format latex Untitled2.ipynb
$ pdflatex Untitled2.tex
$ evince Untitled2.pdf


Worked! (with warnings about depreciation)

I cannot get nbconvert2.py to work (yet).

Monday 15 April 2013

android: opengl

http://developer.android.com/training/graphics/opengl/index.html

pandas: updating a row.


# remove a row, and append it again.  I need to remove a Ze value at a freq, and update it with a new value.
# Don't think I can update the value directly.
print df # original shows all rows
tmp = df[abs(df['A'] - -0.671540) < 1E-3]  # copy
df = df[abs(df['A'] - -0.671540) > 1E-3]  # this shows the first index to be removed.
print df
print df.append(tmp, ignore_index = True)

Sunday 14 April 2013

Updating NVIDIA drivers broke gw2 and steam

I downloaded the latest nvidia binary and installed it.  I said, `yes' to install 32 bit stuff.  On reset, X did not start up.

I think.  I may have attempted to change the NVIDIA binary version via Ubuntu's software manager (gui); reset and found X to fail:  and accessed the nvidia site; downloaded the lastest, installed, saying 'yes'.  Restart:  x started ok but Gw2 now will not start via playonlinux and the terminal shows something about OpenGL not being installed.

I attempted to install Steam, hoping it would fix things.  It didn't.

Follwing https://github.com/ValveSoftware/steam-for-linux/issues/321,
Carlos Jenkins suggested adding,

/usr/lib32
/usr/lib/i386-linux-gnu/mesa
 
to 

/etc/ld.so.conf.d/steam.conf

and doing,


 

sudo ldconfig 


This fixed gw2 and steam.

Friday 12 April 2013

A Python counter. Using it for colour incrementing.


class z:

    """Counter.  My first!  

    Instantiate with number of items between 0 and 1.
    Calling the class will return an incrementing value.

    """


    def __init__(self, n):
        self.n = n
        self.i = -1

    def __call__(self):
        """This gets called when the instantiated object is called"""
        if self.i == self.n:
            raise StopIteration
        self.i += 1
        return self.i * 1.0 / (self.n - 1)

Use as,

In [1]:  a = z(10)

In [2]:  print a(), a(), a(), a(), a(), a(), a(), a(), a(), a()

         0.0 0.111 0.222 0.333 0.444 0.555 0.666 0.777 0.888 1.0

(Those results are truncated ;) )

Use to control colour as,

from matplotlib import cm
a = z(10)
plot(x, y, color=cm.jet(a))
plot(x2, y2, color=cm.jet(a))
plot(x3, y3, color=cm.jet(a))