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.")

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.

ChromiumToSetDefaults.reg:
Windows Registry Editor Version 5.00

; Infamous capabilities:

[HKEY_LOCAL_MACHINE\SOFTWARE\Chromium\Capabilities]
"ApplicationDescription"="Chromium - Beta Google Chrome"
"ApplicationIcon"="C:\\Program Copies\\Chromium\\chrome.exe,0"
"ApplicationName"="Chromium"

[HKEY_LOCAL_MACHINE\SOFTWARE\Chromium\Capabilities\FileAssociations]
".htm"="ChromiumURL"
".html"="ChromiumURL"
".shtml"="ChromiumURL"
".xht"="ChromiumURL"
".xhtml"="ChromiumURL"

[HKEY_LOCAL_MACHINE\SOFTWARE\Chromium\Capabilities\URLAssociations]
"ftp"="ChromiumURL"
"http"="ChromiumURL"
"https"="ChromiumURL"

; Register to Default Programs

[HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications]
"Chromium"="Software\\Chromium\\Capabilities"

; ChromiumURL HANDLER:

[HKEY_LOCAL_MACHINE\Software\Classes\ChromiumURL]
@="Chromium Document"
"FriendlyTypeName"="Chromium Document"

[HKEY_LOCAL_MACHINE\Software\Classes\ChromiumURL\shell]

[HKEY_LOCAL_MACHINE\Software\Classes\ChromiumURL\shell\open]

[HKEY_LOCAL_MACHINE\Software\Classes\ChromiumURL\shell\open\command]
@="\"C:\\Program Copies\\Chromium\\chrome.exe\" -- \"%1\""