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

Windows Registry Editor Version 5.00

"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:
        if 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


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()
        (options, (first_posarg, second_posarg, )) = parser.parse_args()
    except ValueError:
        parser.error("Two positional arguments are required.")

Saturday, February 6, 2010

VLC S/PDIF Stuttering fix

I had this problem with VLC where all output going S/PDIF was stuttering with Windows Vista, and now that I got myself Windows 7 X64, I had to re-fix this problem.

Now I finally found the fix, so I decided to save it to here for future reference:

Preferences -> Advanced settings -> Audio -> Output modules -> Win32 waveOut extension output.

Now the AC3/DTS passthrough works without stuttering.

Saturday, January 2, 2010

Python snippets, find all occurences of string

>>> def find_all(string, occurrence):
...     found = 0
...     while True:
...         found = string.find(occurrence, found)
...         if found != -1:
...             yield found
...         else:
...             break
...         found += 1
>>> print list(find_all("awpropeoaspwtoapwroawpeoaweo", "p"))
[2, 5, 10, 15, 21]
>>> print list(find_all("Overllllapping", "ll"))
[4, 5, 6]

Note: Finds all overlapping matches.

Friday, January 1, 2010

Add your program to "Default Programs" in Windows 7

I wanted to have chromium in "Default Programs", so I can associate HTTP protocol to it, here is how I did that. If you want to do same just change C:\\Program Copies\\Chromium\\chrome.exe to point your chrome.exe, note that is in two places!

For your own program just change the chromium/path etc. to something suitable for your project.

Windows Registry Editor Version 5.00

; Infamous capabilities:

"ApplicationDescription"="Chromium - Beta Google Chrome"
"ApplicationIcon"="C:\\Program Copies\\Chromium\\chrome.exe,0"



; Register to Default Programs


; ChromiumURL HANDLER:

@="Chromium Document"
"FriendlyTypeName"="Chromium Document"



@="\"C:\\Program Copies\\Chromium\\chrome.exe\" -- \"%1\""