Posts

Writing tornado.testing.test as simple python script (and pass command line options to the testee).

I wanted to execute tornado.testing unit test with command line options(tornado.options). Something like python3 -m tornado.test.runtests test.py --port=8080 However I found this is impossible, because runtests tries to process options by itself. Then I tried to do this   python3 test.py --port=8080 by putting following code at the end of the test script(test.py in this case). if __name__ == "__main__":   tornado.testing.main()  * tornado.options.parse_command_line() is called at the top of the testee's program. This didn't work because of "AttributeError: 'module' object has no attribute 'all'" error. So, I avoided this problem by adding "all()" function to the test.py like this, and it finally works. def all():     import unittest     return unittest.defaultTestLoader.loadTestsFromNames([__name__])

Subclassing and Signal connect on a same widget crashes PySide application on exit.

In pyside, I wanted to do something like these, class MyTextLine(QLineEdit): def focusInEvent(self, e): #do something QLineEdit.focusInEvent(self, e) .... widget = MyTextLine(QLineEdit) widget.editingFinished.connect(some_callback) However, this app tends to crash on exit. Core dump saids it is something about destructor of a signal manager. Details are rather vague, but I managed to avoid crash deleting signal-connect. class MyTextLine(QLineEdit): def focusInEvent(self, e): #do something QLineEdit.focusInEvent(self, e) def setCallback(self, cb): self.cb = cb def focusOutEvent(self, e): if hasattr(self, 'cb'): self.cb() .... widget = MyTextLine(QLineEdit) widget.setCallback(some_callback) If anyone knows why this happens, please teach me! One more thing, if you use QTreeWidget having widgets on it, it seems better to do clear() it before closing your application. Update 2015/01/25: It seems like widget.se...

pip3 fails to compile C module(like Pillow, readline etc) on Yosemite

After upgrading OSX to Yosemite, I found pip3 was not working on homebrewed python3. There seems to be many blogs about this problems but I should do some try-and-errors to fix. Here is what I did in order.  1. install Command Line Tools for 10.10, downloaded from Apple Developer(https://developer.apple.com/downloads/index.action) .  2. reinstall gcc brew reinstall gcc  3. reinstall python3 brew reinstall python3  4. do pip pip3 install pillow I am not sure this is the best way, but it worked for me at least. Hope this helps somebody.

Swift seems nice, but cannot write simple function such as converting array to UnsafePointer

I'm writing an iOS accelerated framework application with Swift and it's frequently necessary to convert Swift array to unsafe pointer. However the conversion function I wrote cannot be compiled. Does anybody know what's wrong with this function? func aryToUnsafePointer<T>(ary:T[]) -> UnsafePointer<T> { return UnsafePointer<T>((&ary as CMutablePointer<T>).value) } The error is 'T[]' is not a subtype of '@lvalue $T1' problem solved thanks to Justin It is not allowed to take "&" of argument directly, so changing function like this will work. func aryToUnsafePointer<T>(ary:T[]) -> UnsafePointer<T> { var a = ary return UnsafePointer<T>((&a as CMutablePointer<T>).value) } Now I understand the reason, but it seems a bit odd to me, though.

Why "CoreDragMessageHandler : Cannot track drag receiver. No pasteboard name."

I am trying to drag&drop file on a PySide application, however, An error "CoreDragMessageHandler : Cannot track drag receiver. No pasteboard name." keeps happening. It turns out, the reason is starting application from tmux. We should avoid starting application from tmux when trying to support a drag&drop.

Roating CGImageRef on iOS.

For reminder to myself, rotate image on center. CGImageRef imageref = [self imageFromSampleBuffer:sampleBuffer]; // or any other CGImageRef source. int w = CGImageGetWidth(imageref); int h = CGImageGetHeight(imageref); CGColorSpaceRef colorSpaceInfo = CGImageGetColorSpace(imageref); CGContextRef bitmap = CGBitmapContextCreate(NULL, w, h, CGImageGetBitsPerComponent(imageref), CGImageGetBytesPerRow(imageref), colorSpaceInfo, CGImageGetBitmapInfo(imageref)); CGContextTranslateCTM(bitmap, w/2, h/2); CGContextRotateCTM(bitmap, M_PI_4); CGContextTranslateCTM(bitmap, -w/2, -h/2; CGContextDrawImage(bitmap, CGRectMake(0, 0, w, h), imageref); CGImageRelease(imageref); imageref = CGBitmapContextCreateImage(bitmap); CGContextRelease(bitmap); return imagereff;

From 2 Numpy vectors(length=m,n) , create crossed matrix(shape=(m, n,2))

As a reminder for MYSELF, To create a matrix from two 1D vectors, like v1 = np.arange(4) #[0,1,2,3] v2 = np.arange(4) *10 #[0,10,20,30] to create crossed matrix [[[0,0],[0,10],[0,20],[0,30]], [[1,0],[1,10],[1,20],[1,30]], [[2,0],[2,10],[2,20],[2,30]], [[3,0],[3,10],[3,20],[3,30]]] I do crossed = np.dstack(( np.zeros((len(v1),len(v2)), dtype=v1.dtype) + v1[...,np.newaxis], np.zeros((len(v1),len(v2)),dtype=v2.dtype) + v2)) Is there any better way to do it? Any suggestion will be appreciated.