Saturday, July 30, 2011

Windows 7 - Photo Viewer was really slow

Windows 7 Photo Viewer was acting really slow for loading images, this fixed it:

  1. Go to Color management (Desktop -> Screen Resolution -> Advanced Settings -> Color Management -> Color Management -> Advanced (tab) -> Change System Defaults)
  2. Remove all profiles from all screens, and add single profile per display. (I chose sRGB virtual device mode profile.)
  3. Check the colors in Photo Viewer if the colors are fine then you chose good profile.

That did the trick.

Saturday, January 22, 2011

Where Django & PyDev fails

Don't get me wrong, I like Python, PyDev and Django. But I simply hate the small problems like this:


I forget something simple, like what was the order of return tuple of get_or_create? Then I try to look the tip of the function, and what do I get? The useless **kwargs passing.

Same thing with the god damned exception handling. I don't think I've seen any official package that lists the exceptions given function may rise. All functions should have a good doc-strings that lists parameters, exceptions (including nested) and in case the return value is tuple or something non obvious the order of items in tuple.

Simply, it takes ages to open up the webpage, and browse to right place of docs. There exists a fix, but PyDev does not support it. It's the official objects.inv for Django (sphinx mapping file from keyword to URI).

Sunday, December 12, 2010

Windows 7 - QoS Policies not working

I've noticed that QoS Policies does not work in Windows 7.

Solution (thanks to xedoc in speedguide.net):

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\QoS]
"Do not use NLA"="1"



I configure them using "Group Policy Manager", followingly:


And capturing using WireShark like this:


More about this in: Wireshark Ask Forum,  MSDN QoS Policy

Thursday, October 21, 2010

Basename, Filename, Dirname in Batch

Umm, batch scripts sucks, but here goes:

set filepath="C:\some path\having spaces.txt"

for /F "delims=" %%i in (%filepath%) do set dirname="%%~dpi" 
for /F "delims=" %%i in (%filepath%) do set filename="%%~nxi"
for /F "delims=" %%i in (%filepath%) do set basename="%%~ni"

echo %dirname%
echo %filename%
echo %basename%

I have awed this for crap many times before, now I have it here for the future.

Tuesday, June 22, 2010

Aero Snap vertical maximize winapi

Easy way to toggle the Aero Snap vertical maximize in WinAPI:
HWND active = GetForegroundWindow();
PostMessage((HWND) active, WM_NCLBUTTONDBLCLK, HTTOP, 0);

Thursday, May 27, 2010

Python binary tree traversal


# Python
from itertools import chain
from collections import deque

class n(object):
    left = None
    right = None
    value = None
    
    def __init__(self, value=None, left=None, right=None):
        self.value = value
        self.left = left
        self.right = right
        
    def __call__(self, left=None, right=None):
        self.left = left
        self.right = right
        return self.value

def preorder(node):
    lefts = []
    rights = []
    
    if node.left != None:
        lefts = preorder(node.left)
        
    if node.right != None:
        rights = preorder(node.right)
        
    return chain([node], lefts, rights)
        
def inorder(node):
    lefts = []
    rights = []
    
    if node.left != None:
        lefts = inorder(node.left)
    
    if node.right != None:
        rights = inorder(node.right)
        
    return chain(lefts, [node], rights)


def postorder(node):
    lefts = []
    rights = []
    
    if node.left != None:
        lefts = postorder(node.left)
    
    if node.right != None:
        rights = postorder(node.right)
        
    return chain(lefts, rights, [node])
    
    
def levelorder(node):
    queue = deque([node])
    
    while len(queue) > 0:
        node = queue.pop() # Remove from right
        yield node
        if node.left:
            queue.appendleft(node.left)
        if node.right:
            queue.appendleft(node.right)

# Create nodes
_ = None
A = n('A')
B = n('B')
C = n('C')
D = n('D')
E = n('E')
F = n('F')
G = n('G')
H = n('H')
I = n('I')

# Link the nodes
F(B,G)
B(A,D)
D(C,E)

G(_,I)
I(H,_)

print "Pre order:"
print list(node.value for node in preorder(F))
    
print "In order:"
print list(node.value for node in inorder(F))

print "Post order:"
print list(node.value for node in postorder(F))
    
print "Level order (queue):"
print list(node.value for node in levelorder(F))

Saturday, February 20, 2010

Python notes, optparse positional argument parsing

    parser = optparse.OptionParser()
    try:
        (options, (first_posarg, second_posarg, )) = parser.parse_args()
    except ValueError:
        parser.error("Two positional arguments are required.")