Thursday, June 19, 2014

pbibtex Japanese processing

If you are using pbibtex in TexShop and have Japanese bib file encoded in sjis, then you need to specify the kanji code as sjis in order to properly format the Japanese bibtext entries. This can be done either by command line as
$ pbibtex projname -kanji=sjis
or by the TexShop Preferences --> Engine dialog under default bibtex engine specification by setting
pbibtex -kanji=sjis

Friday, April 18, 2014

Python nose testing

Nose provide additional testing functionalities that are not provided in unittests framework. Unlike unittests which is a standard python module you will have to easy_install nose as described here.


use test_mytest.py to name a test module and test_method to name any test methods. If you do so the nosetests will be able to discover and execute those tests automatically.

You will have to use assert_equal(A, B) to test whether A is equal to B.
For numpy arrays use numpy.testing.assert_array_equal instead to compare numpy arrays.

To test the unit tests you must call nosetests as follows.

To display the name of the test functions
nosetests -v test.py

To display the print statements as well
nosetests -v -s test.py

Execute a specific test function within a class in a test module
nosetests -v -s test.py:className:test_method 
 

Friday, February 21, 2014

Synchronized decorator for Python

The following decorator provides synchronization for Python codes.
Reference


def synchronized(lock):
    """ Synchronization decorator. """

    def wrap(f):
        def newFunction(*args, **kw):
            lock.acquire()
            try:
                return f(*args, **kw)
            finally:
                lock.release()
        return newFunction
    return wrap

if __name__ == '__main__':
    from threading import Thread, Lock
    import time

    myLock = Lock()

    class MyThread(Thread):
        def __init__(self, n):
            Thread.__init__(self)
            self.n = n

        @synchronized(myLock)
        def run(self):
            """ Print out some stuff.

            The method sleeps for a second each iteration.  If another thread
            were running, it would execute then.
            But since the only active threads are all synchronized on the same
            lock, no other thread will run.
            """

            for i in range(5):
                print 'Thread %d: Start %d...' % (self.n, i),
                time.sleep(1)
                print '...stop [%d].' % self.n

    threads = [MyThread(i) for i in range(10)]
    for t in threads:
        t.start()

    for t in threads:
        t.join()

Filter forwarded messages in GMail

If you want to filter a message that has been forwarded to your GMail account by one of your other email services, then you can create a filter with Has Words field set to

deliveredto:your_email_service_mail_accountname_that_forwarded_message. 

You can set filters for example to archive such forwarded messages without showing them in your Inbox. You might want to do this for example, if you want to keep a record of all your emails in your GMail account but do not want to display duplicates when you are using an email client that display emails received in multiple accounts.

Thursday, December 19, 2013

numpy dot vs inner

dot and inner returns the same result for 1D arrays.
However, for 2D arrays (matrices), dot gives the matrix product, whereas inner gives the sum-product over the last axis.

References
inner vs. dot
inner document
dot document

what is sum product?
A = [[x1, x2], [x3, x4]]
B = [[y1, y2], [y3, y4]]

sum product of A and B is given by numpy.inner(A,B) as follows
A's row i is element-wise multiplied by B's row j and the values are added to get the (i,j) element

[[x1*y1+x2*y2, x1*y3+x2*y4], [x3*y1+x4*y2, x3*y3+x4*y4]]

Saturday, April 20, 2013

Apple airplay no sound issue

Sometimes when you mirror your display on airplay you cannot hear. Do the following to solve this issue.

sudo killall coreaudiod

Thursday, February 28, 2013

tmux

  • Commands:
    • starting a new named session
      • $ tmux new -s session_name
  • you can use a .tmux.conf file in your home directory to tmux as follows
    • setw -g mode-mouse on
    • # scrollback buffer size increase
    • set -g history-limit 500000
  • note that with mode-mouse on you cannot copy paste text (you can scroll). You need to do the following Ctrl+B: (note the colon) and then enter the following command
    set -g mode-mouse off
  • when you have finished copy/pasting text you can turn mode-mouse to on so that you can scroll using the mouse wheel

Continuously monitor GPU usage

 For nvidia GPUs do the follwing: nvidia-smi -l 1