Welcome Guest Search | Active Topics | Members | Log In | Register

Profile: pixelninja
About
User Name: pixelninja
Groups: Administration
Rank: Administration
Real Name: Eric Burcham
Location Richardson, TX
Occupation: Software / Database / Web / Graphics Designer
Interests: Swing & Salsa, Rock Climbing, Acoustic Guitar
Gender: Male
Statistics
Joined: Sunday, July 24, 2005
Last Visit: Thursday, June 25, 2009 9:11:48 AM
Number of Posts: 14
[0.01% of all post / 0.01 posts per day]
Avatar
Last 10 Posts
Topic: Changing Windows IP Configuration With a Batch File
Posted: Monday, August 22, 2005 12:03:52 PM
You may download the complete source for this example here.

As a working college student, I have a consistant problem having to change my network settings. For instance, I like to download files at home, so I need certain ports open on my wireless router. This dictates that I have to use a static IP address in order to not be re-mapping ports all the time.

At school, the university requires that I use a dynamic IP address, or I cannot even connect to the network.

At work, I need to use a certain DNS server, but have a dynamic IP address. Go figure.

This means that I am constantly changing my IP configuration, and that I have three different sets of information to remember. The solution... a batch file that handles the whole shebang. This has only been tested on WinXP, by the way.


In order to have three sets of settings, I just created four files. One .bat and three .txt files so that I can just add settings for each location in the .txt files.


The ConfigIP.bat file looks like this.

Code:
@echo off
title Eric Burcham's IP Configuration Batch File - 2005
setlocal
set OK=N



:again
    set /p choice=Please enter 1[Home], 2[School] or END ??
    if /i [%choice%]==[END] endlocal&goto end
    if [%choice%]==[] goto again
    if [%choice%]==[1] goto 1
    if [%choice%]==[2] goto 2
    set /p xxx=wrong entry, press any key to exit. 
    endlocal
    goto end



:1
    echo NIC setting for Home being configured.....
    @netsh exec home.txt
    set /p see=IP changed successfully to Home Settings [9]see new setting [Enter]exit...
    if [%see%]==[9] goto show
    echo Ending IP Configuration
    goto end



:2
    echo NIC setting for School being configured.....
    @netsh exec school.txt
    set /p see=IP changed successfully to School Settings [9]see new setting [Enter]exit...
    if [%see%]==[9] goto show
    echo Ending IP Configuration
    goto end



:show
@netsh int ip show config



:end
@echo on
cls


This files presents the user with a selection; 1 or 2. Based on which selection they make, the IP settings are loaded from the following files.

home.txt
Code:
# ----------------------------------
# Interface IP Configuration         
# ----------------------------------
pushd interface ip


# Interface IP Configuration for "Wireless Network Connection"
set address name="Wireless Network Connection" source=static addr=192.168.2.50 mask=255.255.255.0
set address name="Wireless Network Connection" gateway=192.168.2.1 gwmetric=0
set dns name="Wireless Network Connection" source=static addr=192.168.2.1 register=primary


popd
# End of interface IP configuration



school.txt
Code:
# ----------------------------------
# Interface IP Configuration         
# ----------------------------------
pushd interface ip


# Interface IP Configuration for "Wireless Network Connection"
set address name="Wireless Network Connection" source=dhcp
set dns name="Wireless Network Connection" source=dhcp register=primary
set wins name="Wireless Network Connection" source=dhcp


popd
# End of interface IP configuration




You can simply add a new .txt file for each set of settings you need, and a section in the .bat file to load them. Voila! 2 second IP configuration.

You may download the complete source for this example here.




If I have seen further than others, it is by standing upon the shoulders of giants.
~Sir Isaac Newton


If I have not seen as far as others, it is because giants were standing on my shoulders.
~Hal Abelson
Topic: Greatest Consecutive Sum
Posted: Wednesday, August 10, 2005 4:32:02 PM
This is my favorite to see someone do really well. The trick is to set two variables, one as a working variable and one that contains the highest sum found so far. You can iterate the array once, and reset the working variable any time it dips below zero, since the lowest number we will allow as a return value is zero. Then you just reset the highest value when the working one goes above it.

Code:
/// <summary>
/// This method should return the greatest possible sum of consecutive integers within the array "numbers"
///
/// Please note that the solution should be as efficient as possible ans not be breakable.
///
/// If all numbers in the array are negative, return 0
/// </summary>
/// <param name="numbers">Integer array</param>
/// <returns></returns>
public static int GreatestConsecutiveSum(int[] numbers)
{
    // Examples
    //-1, -2, -3          returns 0
    // 0, 1, 2, 3, -1     returns 6
    // -10, 1, 2, 3       returns 6
    // 1, 2, 3, -10, 20    returns 20
    // 1, 2, 3, -5, 20     returns 21

    int sum = 0; // Variable to hold greatest sum
    int temp = 0; // Working variable

    for (int i = 0; i < numbers.Length; i++)
    {
        temp += numbers[i];

        if (temp < 0)
        {
            temp = 0;
        }

        if (temp > sum)
        {
            sum = temp;
        }
    }

    // Return answer
    return sum;
}





If I have seen further than others, it is by standing upon the shoulders of giants.
~Sir Isaac Newton


If I have not seen as far as others, it is because giants were standing on my shoulders.
~Hal Abelson
Topic: Solving for prime numbers
Posted: Wednesday, August 10, 2005 4:26:07 PM
This one only has a few places that people hiccup. Obviously people with a strong math background have an advantage here, because they might know Fermat's Little Theorem is a fast heuristic.

The main catching point is on how many possible factors to test before deciding the number is prime. A person might decide to divide 100 by every number from 1-99 and look for a remainder of 0, but they only need to go to ten. Any higher than a number's square root and any higher factors would have already divided evenly.

Code:
/// <summary>
/// This method should return whether or not an integer is a prime number
///
/// Please note that the solution should be as efficient as possible and not be breakable.
/// </summary>
/// <param name="number">Integer to be tested</param>
/// <returns>true or false</returns>
public static bool IsPrime(int number)
{
    // Throw out impossibles
    if (number < 2)
    {
        return false;
    }

    // Don't need to test above the square root of a number
    for (int i = 2; i < (number); i++)
    {
        // If remainder is 0, number is not prime
        if (number % i == 0)
        {
            // return false
            return false;
        }
    }

    // If all conditions are met, return true
    return true;
}





If I have seen further than others, it is by standing upon the shoulders of giants.
~Sir Isaac Newton


If I have not seen as far as others, it is because giants were standing on my shoulders.
~Hal Abelson
Topic: Mulitplying two integers
Posted: Wednesday, August 10, 2005 4:21:21 PM
Here is the best solution that I came up with. The obvious solution is to loop on one variable and add another. There are two things to watch out for when candidates answer this question.

1) Do they make sure to loop on the smaller integer?
2) Do they handle negatives?

Almost anyone can nail the basic problem. I am looking for someone who solves it intelligently, and covers all their bases. The best candidates will talk through everything carefully and make sure that they have thought of everything before they actually start writing on the whiteboard.

Code:
/// <summary>
/// This method should return the product of the two given integers.
///
/// Do not use built in operatros such as "*"
///
/// Please note that the solution should be as efficient as possible and not be breakable.
///
/// Do not worry about results that are out of the normal integer range.
/// </summary>
/// <param name="x">Integer to be multiplied</param>
/// <param name="y">Integer to be multiplied</param>
/// <returns>The product of the two integers</returns>
public static int Multiply(int x, int y)
{
    int product = 0;

    bool isNegative = false; // Variable to store whether or not the product should be negative

    if ((x > 0 && y < 0) || (x < 0 && y > 0))
    {
        isNegative = true;
    }

    // Take absolute values to loop
    x = Math.Abs(x);
    y = Math.Abs(y);

    // We'll loop on x, so make sure it is the smaller integer
    if (y > x)
    {
        int temp = x;
        x = y;
        y = temp;
    }

    // Calculate the product
    for (int i = 0; i < x; i++)
    {
        product += y;
    }

    // Recheck negative condition
    if (isNegative == true)
    {
        product = -product;
    }

    // Return product
    return product;
}





If I have seen further than others, it is by standing upon the shoulders of giants.
~Sir Isaac Newton


If I have not seen as far as others, it is because giants were standing on my shoulders.
~Hal Abelson
Topic: Greatest Consecutive Sum
Posted: Tuesday, July 26, 2005 11:13:27 PM
This one is a little trickier. Most people will try to brute force it... that is to say they will simply add every possible combination of integers and see which on is the largest. This works fine for small arrays, but what about an array with a million integers? I think it might run for a little while. You are looking for candidates that come up with an elegant solution. It is possible to iterate the array just once and come up with the correct answer.

Code:
/// <summary>
/// This method should return the greatest possible sum of consecutive integers within the array "numbers"
///
/// Please note that the solution should be as efficient as possible ans not be breakable.
///
/// If all numbers in the array are negative, return 0
/// </summary>
/// <param name="numbers">Integer array</param>
/// <returns></returns>
public static int GreatestConsecutiveSum(int[] numbers)
{
    // Examples
    //-1, -2, -3          returns 0
    // 0, 1, 2, 3, -1     returns 6
    // -10, 1, 2, 3       returns 6
    // 1, 2, 3, -10, 20    returns 20
    // 1, 2, 3, -5, 20     returns 21
        return 0;
}


Please post any solutions. I will post mine in a few weeks.




If I have seen further than others, it is by standing upon the shoulders of giants.
~Sir Isaac Newton


If I have not seen as far as others, it is because giants were standing on my shoulders.
~Hal Abelson
Topic: Mulitplying two integers
Posted: Tuesday, July 26, 2005 11:08:58 PM
Anothe simple one for the entry level or internship candidates. The idea here is to watch them think through it and make sure they don't make any obvious mistakes.

Code:
/// <summary>
/// This method should return the product of the two given integers.
///
/// Do not use built in operators such as "*"
///
/// Please note that the solution should be as efficient as possible and not be breakable.
///
/// Do not worry about results that are out of the normal integer range.
/// </summary>
/// <param name="x">Integer to be multiplied</param>
/// <param name="y">Integer to be multiplied</param>
/// <returns>The product of the two integers</returns>
public static int Multiply(int x, int y)
{
    return 0;
}


Anybody see any obvious issues that might come up? Just curious as to what you think. I will post my solution in a few weeks.




If I have seen further than others, it is by standing upon the shoulders of giants.
~Sir Isaac Newton


If I have not seen as far as others, it is because giants were standing on my shoulders.
~Hal Abelson
Topic: Solving for prime numbers
Posted: Tuesday, July 26, 2005 11:04:21 PM
This is a simple interview question I often use for potential interns or entry level candidates. Write a function (language is arbitray; I always use C#) that takes an integer as a parameter a boolean indicating whether or not the numnber is prime.

Code:
/// <summary>
/// This method should return whether or not an integer is a prime number
///
/// Please note that the solution should be as efficient as possible and not be breakable.
/// </summary>
/// <param name="number">Integer to be tested</param>
/// <returns>true or false</returns>
public static bool IsPrime(int number)
{
    return true;
}


Please post any solutions that you may want to try... I will post mine in a few weeks.




If I have seen further than others, it is by standing upon the shoulders of giants.
~Sir Isaac Newton


If I have not seen as far as others, it is because giants were standing on my shoulders.
~Hal Abelson
Topic: Which Corvette generations are your favorite from most liked to least liked!?
Posted: Monday, July 25, 2005 12:06:07 AM
C3
C6
C5
C1
C2
C4




If I have seen further than others, it is by standing upon the shoulders of giants.
~Sir Isaac Newton


If I have not seen as far as others, it is because giants were standing on my shoulders.
~Hal Abelson
Topic: What do you like about Corvettes???
Posted: Sunday, July 24, 2005 10:38:11 PM
After careful thought and consideration, I have come up with the following detailed list of things I like.

1) Everything




If I have seen further than others, it is by standing upon the shoulders of giants.
~Sir Isaac Newton


If I have not seen as far as others, it is because giants were standing on my shoulders.
~Hal Abelson
Topic: Post your favorite pic of a corvette!!
Posted: Sunday, July 24, 2005 10:37:10 PM
This one is pretty sweeeeeet. C3's are the bomb.






If I have seen further than others, it is by standing upon the shoulders of giants.
~Sir Isaac Newton


If I have not seen as far as others, it is because giants were standing on my shoulders.
~Hal Abelson

Main Forum Rss Feed : RSS

Powered by Yet Another Forum.net version 1.0.0 RC2 - 6/13/2005
Copyright © 2003-2005 Yet Another Forum.net. All rights reserved.
This page was generated in 0.970 seconds.

orum runat="server"/>