Thursday, August 18, 2011

Set Windows Network Settings From The Command Line Using Net Shell (netsh.exe)


If you are changing network settings repeatedly on a test system it gets old having to point and click each time. Net Shell (netsh.exe) can be called as follows from the command line:

   netsh interface ipv4 set address name="Local Area Connection" dhcp HOST_IP
   SUBNETMASK GATEWAY_IP


For example:

   netsh interface ipv4 set address name="Local Area Connection" 10.0.0.2   
   255.255.255.0 10.0.0.1

Typing this over and over will get old as well so you can make a simple batch file called
ip.bat containing:

   netsh interface ipv4 set address name="Local Area Connection" %1 %2 %3 %4

Now you can type:

   ip [dhcp | static] HOST_IP SUBNETMASK GATEWAY_IP

For example:

   ip dhcp 10.0.0.2 255.255.255.0 10.0.0.1


Of course you can just create individual batch files for each test scenario.





Dell Laptop Power Jack Repair


A common problem with laptops is that the power receptacle on the mainboard stops making a reliable connection to the barrel connector on the power brick.  Often this leads to intermittent battery charging unless the connector is in just the "right" position. Eventually the connector fails completely and the laptop will not power on.

The entire job took about three hours. Getting to the connector to desolder it is a bear. A complete disassembly was required. Thus the mountain of parts in the right side of the photo.

Some newer laptops have daughterboards containing the power receptacle so that desoldering is not necessary. Not having good desoldering equipment made it difficult to get the through holes in the mainboard clean and ready for a new connector but a cheap solder sucker and solder wick eventually did the trick.

If your laptop is worth less than the cost of a professional repair, give it a try. If your laptop is worth much more I would leave this repair to the professionals.

Friday, August 5, 2011

MIT 6.00 Problem Set 8 - Problem 2


The problem statement does not mention sorting. But sorting the entire dict would be helpful. And the comparator could be used with sorted() but since there is no mention of sorting the data set I leave it unsorted.  So this may be a completely wrong approach but I take two tuples at a time and whichever is best is added to the solution set where best is judged by the comparator.

Python Code:

def greedyAdvisor(subjects, maxWork, comparator):
    schedule = {} # initial solution
    firstSubject = {}
    odd = True
    work = 0    
    test = subjects.copy()
    for key in subjects.keys():
        if odd == True:
            firstSubject = subjects[key]
            odd = False
        else:
            odd = True
            if comparator(firstSubject, subjects[key]):
                if work + firstSubject[WORK] <= maxWork:
                    schedule[key] = firstSubject
                    work += firstSubject[WORK]
            else:
                if work + subjects[key][WORK] <= maxWork:
                    schedule[key] = subjects[key]
                    work += subjects[key][WORK]

    if test != subjects:
        print "SUBJECTS MUTATED"

    return schedule
Output:
cmpValue
Course  Value   Work
======  ====    =====
12.05   7       1
14.01   6       1
22.12   10      18
6.09    8       4
7.11    7       4
7.15    3       3
7.17    10      1
7.19    10      5
8.10    4       6
8.14    3       7
8.18    4       10

Total Value:    72
Total Work:     60

cmpWork
Course  Value   Work
======  ====    =====
12.03   2       1
14.01   6       1
22.12   8       15
6.09    8       4
7.11    7       4
7.15    3       3
7.17    10      1
7.19    10      2
8.10    4       6
8.14    3       7
8.16    2       6
8.18    4       10

Total Value:    67
Total Work:     60

cmpRatio
Course  Value   Work
======  ====    =====
12.03   2       1
12.05   7       1
14.01   6       1
22.12   10      18
6.09    8       4
7.02    3       2
7.11    7       4
7.15    3       3
7.17    10      1
7.19    10      2
8.14    3       7
8.16    2       6
8.18    4       10

Total Value:    75
Total Work:     60

MIT 6.00 Problem Set 8 - Problem 1

Python Code:

def loadSubjects(filename):
    catalog = {}
    inputFile = open(filename)
    for line in inputFile:        
        line = string.strip(line)
        lineList = string.split(line, ',')

        lineList[1] = int(lineList[1])
        lineList[2] = int(lineList[2])
        catalog[lineList[0]] = lineList[1:]
    return catalog