About Me

My photo
Northglenn, Colorado, United States
I'm primarily a BI Developer on the Microsoft stack. I do sometimes touch upon other Microsoft stacks ( web development, application development, and sql server development).

Friday, February 24, 2006

Ghetto Encryption I

Riddle From:http://www.ocf.berkeley.edu/~wwu/riddles/medium.shtml

You want to send a valuable object to a friend securely. You have a box which can be fitted with multiple locks, and you have several locks and their corresponding keys. However, your friend does not have any keys to your locks, and if you send a key in an unlocked box, the key could be copied en route. How can you send the object securely?


My solution, (4am in the morning), take the box and send your locks unlocked over inside the box with a question, that he should only know the answer to.

Have your friend put his own locks unlocked in this box, answer the question and then lock the box with your locks.

Put all your keys in the box, with his locks securing the outside. Then have him send back the box with nothing on or in it.

Put your item in the box and lock it with all your locks.


I think that covers it.

Monday, February 20, 2006

Old School: Sort Algorithms

http://linux.wku.edu/~lamonml/algor/sort/sort.html

Ok, this just brings back good ol' memories of my first two years in the computer science degree. I remember when I had to program all of these and their time results in C. This pages discusses the classic alogrithms:

Bubble sort
Heap sort
Insertion sort
Merge sort
Quick sort
Selection sort
Shell sort

I also did Bi-Directional Bubble Sort and Bucket Sort as two individual programs of sorting algorithms for my final project.

Sunday, February 19, 2006

A Microsoft Riddle:

One train leaves Los Angeles at 15mph heading for New York. Another train leaves from New York at 20mph heading for Los Angeles on the same track. If a bird, flying at 25mph, leaves from Los Angeles at the same time as the train and flies back and forth between the two trains until they collide, how far will the bird have traveled?

Ok, I developed a ad-hoc program to help solve this problem. The major variable in the question is the distance. The distance is the variable, in which just complicates the problem. I know the distance is greater 2000, so I tested with the values 2000, 2500, and 3000.


int NYLADistance = 2000;
int LATrainSpeed = 15;
int NYTrainSpeed = 20;
int BirdSpeed = 25;
int LAStart = NYLADistance;
int NYStart = 0;
int BirdStart = NYLADistance;
int hour = 0;
int BirdTrips = 0;
bool FlyingEast = true;
int TotalBirdTravel = 0;

while(LAStart >= NYStart)
{
   hour++;
   LAStart = LAStart - LATrainSpeed;
   NYStart = NYStart + NYTrainSpeed;
   if(FlyingEast)
   {
      BirdStart = BirdStart - BirdSpeed;
      if(BirdStart < NYStart)
      {
         FlyingEast = false;
         BirdTrips++;
      }
   }
   else
   {
      BirdStart = BirdStart + BirdSpeed;
      if(BirdStart > LAStart)
      {
         FlyingEast = true;
         BirdTrips++;
      }
   }
   TotalBirdTravel = TotalBirdTravel + BirdSpeed;
}



I came up with these values:
Distance 3000, bird flys 2150
Distance 2500, bird flys 1800
Distance 2000, bird flys 1450

So, by using these numbers I came up with the formula:
y = (7/10)x + 50
y is the bird travel
x is the distance from LA to NY

Wednesday, February 15, 2006

Microsoft's Interviews

Ok, I find it funny, strange, and quite interesting to hear about some of Microsoft's Interviews. This site shows some of the humorous questions and answer sesssion from Microsoft: http://www.sellsbrothers.com/fun/msiview/
"From "Pete" (not his real name):

I walked into my first technical interview at Microsoft, and before I could say anything, the woman says, Youre in an 8x8 stone corridor. I blink and sit down.

Interviewer: The prince of darkness appears before you.

Me: You mean, like, the devil?

Interviewer: Any prince of darkness will do.

Me: Ok.

Interviewer: What do you do?

Me: Can I run?

Interviewer: Do you want to run?

Me: Hmm I guess not Do I have a weapon?

Interviewer: What kind of weapon do you want?

Me: Um something with range?

Interviewer: Like what?

Me: Uh a crossbow?

Interviewer: What kind of ammo do you have?

Me: Ice arrows?

Interviewer: Why?

Me: Because the prince of darkness is a creature made of fire???

Interviewer: Fine so what do you do next?

Me: I shoot him?

Interviewer: No what do you do?

Me:

Interviewer: You WASTE him! You *WASTE* the prince of darkness!!

Me: Holy crap what have I gotten myself into.

She then tells me that she asks that question for two reasons. 1) Because she wants to know if the candidate is a gamer (which is apparently really important please note: Im not a gamer) and 2) because she wants her question to show up on some website. I hate to accommodate her, but this is definitely the weirdest interview question Ive ever heard of.
"



Here is another website, that list some of Microsoft's Interview Questions:
http://halcyon.usc.edu/~kiran/msqs.html

Sunday, February 12, 2006

The 3 ants on a triangle problem.

The question:

There are 3 ants at 3 corners of a triangle, they randomly start moving towards another corner. What is the probability that they don't collide?

Now, if I just simply look at the problem, I see that the three ants can simply go clockwise, or counterclockwise together. On the third possibility one ant could go clockwise, another counter clockwise, and the third ant wouldn't matter which way it went. This would be the collision making the answer 2/3, but this is wrong.

So lets take another look at it:

Lets name the ants A, B, C respectively, and to make it easier let 0 represent the ant goes clockwise, and 1 represent the ant goes counter-clockwise. We would end up with these possibilities:

0,0,0 = No Collision
0,0,1 = Collision
0,1,0 = Collision
0,1,1 = Collision
1,0,0 = Collision
1,0,1 = Collision
1,1,0 = Collision
1,1,1 = No Collision

This makes the correct answer of 2/8 = 1/4

Another way of looking at this is via the combinatorics way:
Each of the 3 ants has 2 possibilities, making it 2C1 for each ant. This comes out to 2*2*2 = 8 possibilities, now knowing that there are only 2 good outcomes this makes it 2/8 = 1/4.

Monday, February 06, 2006

Regular Expressions for RegularExpressionValidator

So, I've been reading up on my ASP.Net and trying to familiarize myself with everything real quick. I try searching for a Regular Expression tutorial, so that I can quickly brush up on the RegularExpressionValidator control. Of course I found the info on MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/paght000001.asp
which led to a link with great information http://www.regular-expressions.info/tutorial.html

I know some of the regular expressions from my use in VI in Unix/Linux environments, but I guess a refresher is in order. Here is a basic run down (quickly tutorial) of regular expressions in ASP.Net:

^ - the beginning of the input string
$ - the end of the input string
Note: If you omit these markers, an attacker could affix malicious input to the beginning or end of valid content and bypass your filter.
Note: If you try to represent a string of text with anything by just using ^,$, or ^$ then you will run into trouble if a newline is used

? - represents a variable string that may or may not be included
Example: Will(iam)? would represent my name Will and William
\ - represents the escape sequence from the meta-character.

\b - matches before and/or after an alphanumeric sequence
example: ^\bWilliam\b find the whole word "William" by it self at the beginning.
\B - matches before and/or after that isn't an alphanumeric
More info: http://www.regular-expressions.info/wordboundaries.html
\d - matches a single numeric value.
\D - matches anything that is not a numeric value.
[0-9] - represents one numeric digit
Example: \d\+\d would represent any number+number like 1+1 also the expression [0-9]\+[0-9]

\t - represents the non-printable representation of the tab.
\n - represents the non-printable representation of the line feed.
\r - represents the non-printable representation of the carriage return.
\s - represents a white space (tab, carriage return, etc..)
\S - represents not a white space.
\xHEX_VALUE - represents the hex representation of an ASCII character.
Example: \xA9 represents the copy-right symbol
More Info:http://www.regular-expressions.info/characters.html

* - represents zero or more occurrences
+ - represents one or more occurrences
{min,max} - represents a range of numbers of occurrences
Example: \d{0,} represents one or more numeric values
Example: {1,} is the same as +

[a-z] - represents one lowercase letter
[A-Z] - represents one uppercase letter
Example: ^*[a-zA-Z0-9'.]$ represents a single string of zero or more occurrences of lowercase, uppercase, numeric, single-quote, and/or a dot
Example: [WB]ill represents the word of Will or Bill

[^] - represents the negated
Example: Will[^y] represents any string with Will and some other character(s) as long it isn't y. So Willie and Williy would be ok, but Will and Willy would not be.

| - (veritical line) represents or
Example: Will(iam|ie) represents William or Willie

$number - represents a way referencing a previous string
Example: ([w*])(abc)=$1$2 Will always be true in cases like abc=abc , wabc=wabc , wwabc=wwabc , etc....

Be careful when it comes to using the \ -backslash since it is also used in C#. As an advice use the @ to represent your regular expression string as is, or you would be force to write something like \\\\ to represent \\ the literal backslash in the regular expression. Some additional important info on using Regular Expressions in .Net environments: http://www.regular-expressions.info/dotnet.html

Well I hope these are correct, sometimes the wording might not be as correct as it should, making it ambiguously wrong.

Sunday, February 05, 2006

How To: Use mySql with ASP.net/C#

Need to use:
using System.Data;
using System.Data.Odbc;

Define Global Variables:
private System.Data.Odbc.OdbcConnection OdbcCon;
private System.Data.Odbc.OdbcCommand OdbcCom;
private System.Data.Odbc.OdbcDataReader OdbcDR;

DataReader is a read only access, making communication to the database(s) a lot quicker.

Connection String all on one line:
ConStr = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;PORT=3306;
DATABASE=databasename;UID=username;PWD=password;OPTION=3";

Your Query:
string ComStr = "select * from agent where state ='" + TextBox1.Text + "'";

Make Connection:
OdbcCon = new System.Data.Odbc.OdbcConnection(ConStr);
Make Query:
OdbcCom = new OdbcCommand(ComStr,OdbcCon);

Now do your try block:

try
{
   if(OdbcCon.State == ConnectionState.Closed)
   {
      OdbcCon.Open();
   }

   OdbcDR = OdbcCom.ExecuteReader();
   while(OdbcDR.Read())
   {
      result.Text = "The results of the query are:";
      Label1.Text = "State: "+OdbcDR[0].ToString();
      Label2.Text = "Value: "+OdbcDR[1].ToString();
      Label3.Text = "Visted: "+OdbcDR[2].ToString()+ " times";
   }
   }OdbcCon.Close();
}
catch(Exception Ex)
{
   // An error occured, give details
   string warning = Ex.ToString();
   Page.Response.Write(warning);
}

Friday, February 03, 2006

Web Services

With programming and design being mostly controlled by business, the concept of Web Services, XML, SOAP, WSDL, and UDDI is becoming very popular. Most businesses that contact me for career opportunities not only want you to know C# and ASP.net technologies, but these others services that are apart of the new evolution of the web. These web webservices are rapidly changing the web, it was only about a year ago when Google Maps came onto the scene. This has dramtically changed the way people have been using the internet. The last half of 2005, a new concept was born.

Using multiple web services into one page, this concept is known as "mash-up". You might have come across these services recently, for example any website that uses Google's maps combining with another web service. Here is an example:
http://www.mywikimap.com/ of combining Google's map with gas prices in your area.

I personally like the way the future of the internet is going (in this aspect). Before Google Maps and their web service, finding directions was only done with Yahoo Maps and other services. Now we can find directions with gas stations, and food services on the way if necessary.

The following website does a nice defintion of what Web Services are and the other technologies behind the development of web services: http://www.webopedia.com/DidYouKnow/
Computer_Science/2005/web_services.asp

Thursday, February 02, 2006

Start: Development Blog

I decided it was better if I didn't clog my other blog with development material, so I decided to make a blog that deals with my daily development achievements of success and failure. I will also set up some links to useful resources and other blogs that deal with development. Here is my beginning website of some basic project that I have developed that I feel isn't that shameful to show others. At this point I'm developing a CSS Design Wizard, which is of course a lot of tedious work.
http://williamandrus.tripod.com/index.htm