Friday, May 30, 2008

 

Microsoft Source Analysis

Microsoft have released their previously internal tool Source Analysis (aka StyleCop). This allows project- and file- level source code analysis checking it meets a whole raft of style rules developed by Microsoft. Some you will agree with, some you won't. The good news is you can turn off rules you don't like, the bad news is you cannot develop your own.

blogs.msdn.com

Thursday, March 27, 2008

 

Visual Studio 2008 IDE C# - UK Launch Notes


 

C# Programming - Part 2 - Conditions

Scope of work

The work is split into two parts: the first is a training part where you are encouraged to use books and the Internet to help you complete the questions; the second is a test part where you should complete the questions with no external help. The pass score is 80%.

1. if, else if, else

2. Nested conditions

3. && and

4. switch statement

Training Questions

Create console applications to:

1. Read a number from the console (use ReadLine and Int32.Parse) and using if, else if and else output one of the following

“The number is negative”

“The number is lower than 100”

“The number is 100 or above”


2. Read two numbers from the console (one after the other) and by nesting if, else if and else output one of the following:

“The numbers are the same”

“The numbers are not the same”

– the first is lower than the second”

“The numbers are not the same

– the second is lower than the first”


3. Read two numbers from the console (one after the other) and using if, else if and else along with && output one of the following:

“The numbers are the same and are negative”

“The numbers are the same and are positive”

“The numbers are not the same”


4. Read a number from the console (use ReadLine and Int32.Parse) and using a switch statement with cascading, and depending on an input 1-10 output one of the following:

“You entered an even number” or

“You entered an odd number” or

“You entered a number that is not 1-10”

5. Read a number from the console (use ReadLine and Int32.Parse) and by nesting if, else if and else output one of the following depending on what range the number is in, and whether it is divisible by 5:

“The number is 0-25 and is divisible by 5” or

“The number is 0-25 and is not divisible by 5” or

“The number is 26-50 and is divisible by 5” or

“The number is 26-50 and is not divisible by 5” or

“The number is 51-75 and is divisible by 5” or

“The number is 51-75 and is not divisible by 5” or

“The number is above 75”


* Note. To check if a number is divisible by 5 you can use:

(number % 5 == 0)

Test Questions

Create console applications to:

1. Read two numbers from the console (one after the other) and using if, else if and else output one of the following:

“The first number is lower than the second”

“The second number is lower than the first”

“The numbers are the same”


2. Read two numbers from the console (one after the other) and by nesting if, else if and else output one of the following:

“Both numbers are negative”

”Both numbers are positive”

“The first number is positive, the second is negative”

“The second number is positive, the first is negative”


3. Read a letter from the console and by if, else if and else with (or) output one of the following:

“1” (if the letter is a, b or c)

“2” (if the letter is d, e or f)

“3” (if the letter is g, h or i)

“4” (if the letter is j, k or l)


4. Read a number from the console (use ReadLine and Int32.Parse) and using a switch statement with cascading, and depending on an input 1-9 output one of the following:

“You entered the number one, two or three” or

“You entered the number four, five or six” or

“You entered the number seven, eight or nine” or

“You entered a number that is not 1-9”


5. Read three numbers from the console (one after the other) and by nesting if, else if and else sort the three numbers and output them in order:

Example: input numbers: 2 5 and 1

Output: 1, 2, 5

Example: input numbers 100, 45, 30

Output: 30, 45, 100

Saturday, March 22, 2008

 

C# Programming - Part 1 - Strings

As languages become more high-level it seems training material focuses more on dragging and dropping components and interacting with the IDE than teaching fundamentals like problem solving and creating logical procedural code. From this deficit I created a set of C# Programming tasks that concentrate on problem solving and creating logical code. This work is made available by kind approval of Siemens AG Industry.

The tasks are provided free of charge but may NOT be copied or redistributed. The work is copyright and all rights are reserved.

Scope of work

The work is split into two parts: the first is a training part where you are encouraged to use books and the Internet to help you complete the questions; the second is a test part where you should complete the questions with no external help. The pass score is 80%.

1. Manipulating strings

2. Substrings

3. Upper/lower case

4. Concatenation

5. Locating a character in a string

6. Replacing characters in a string

Training Questions

Create console applications to:

1. Store your name as a string literal and output it to screen.

2. Read a string from the console and output it in upper case.

3. Read a name from the console (for example "Bob") and output the following:

"Hello, Bob!"

4. Use the following string:

string telephone = "0800 123 4567";

and replace the space with a - so that the output is:

0800-123-4567

5. Use the following string:

string alphabet = "abcdefghijklmnopqrstuvwxyz";

and output six letters starting from e, so that the output is:

efghij

6. Create a simple CSV (comma separated values) parser capable of dealing with a string read in from the console. The string will always be in the format:

firstvalue,secondvalue,thirdvalue

Some example strings:

"1,2,3"

"aa,bb,cc"

"apple,banana,pear"

The output (using the third string as an example) should be output to screen as follows:

First value: apple

Second value: banana

Third value: pear


Test Questions

Create console applications to:

1. Store your name in a string and output it to the screen in upper case.

2. Use the following strings:

string countryCode = “44”;

string areaCode = “1260”;

string number = “123456”

along with string literals to output:

+44-1260-123456

to screen

3. Use a string as follows:

string test = "siemens automation and drives";

Replace every i character with a 1 and then output the string in upper case as so:

S1EMENS AUTOMAT1ON AND DR1VES

4. Parse the following string:

string surnameforename = "Siemens, Werner";

so the forename appears before the surname as follows:

"Werner Siemens"

store it in a string variable and output it to screen.

5. Read in a string from the console that will always be in the following format:

+

This should be done using the substring function.

For example:

12+4

Where the example would output:

First number: 12

Second number: 4

Friday, November 23, 2007

 

Resizing a logical volume without unmounting in Linux

I had a problem where the logical volume our kickstart image created was too small, despite the disk having enough space. As you see it only allocated 4GB:
[root@example sbin]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
4128448 3716732 202004 95% /
/dev/sda1 101086 18598 77269 20% /boot
none 8203424 0 8203424 0% /dev/shm

The logical volume can be resized by running lvm (as root) at the command prompt and the following command (For 50GB):
lvm> lvresize -L 50G VolGroup00/LogVol00

The issue we then had is that this isn't committed! Exit lvm, and then type the following:
ext2online /dev/mapper/VolGroup00-LogVol00

After a few minutes of processing you will now find you have a larger volume:
[root@example sbin]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
51606140 3721676 45263616 8% /
/dev/sda1 101086 18598 77269 20% /boot
none 8203424 0 8203424 0% /dev/shm

Tuesday, August 7, 2007

 

Syntax highlighting in colour in HTML

I recently found a fantastic feature in GVIM that allows me to syntax highlight my code and turns it into HTML. I'm sure there are tools out there specifically for this job, but given the convenience of having this built into my editor I couldn't help but mention it.

You can get GVIM from their website. When you've loaded your code up (and practically every language is supported), click the Syntax -> Convert to HTML menu option.

Here's a sample:


<?php

if (isset($_GET['album']))
{
//echo 'gallery: ' . $_GET['album'];
$d = dir('Photos/' . $_GET['album']);

$bFirst = true;
while ( ($file = $d->read()) !== false)
{
if (strpos($file, 'tb.jpg') !== false)
{

Thursday, August 2, 2007

 

Search Engine Effectiveness - Practical Test

I've been wondering recently how effective alternate search engines are compared to Google. As a small test I decided to take 25 searches I had performed in the last week and search on Google, Yahoo and MSN Live Search to compare results.

The following table shows the results. A score of zero means the target info was found on the search page itself (I didn't have to click through to the site). A number 1-10 is the position of the search result with the target info. A blank score means the target info was not found on the first page of links.

The score is a sum of each search position negated from 11. As so:

Target info on search page: 11-0 = 11
Target info on page result 4: 11-4 = 7
Target info on page result 10: 11-10 = 1
Target info not found: 0



Conclusions:

I was pretty suprised Google was so far ahead compared to Yahoo and MSN. Google won because it was better at finding more niche searches, whereas Yahoo and MSN failed completely. For more obvious searches all three performed flawlessly and may do for day-to-day searches.

Google tended to either have the result first, or not at all. Yahoo had a few useful results in the top five. MSN had some results nearer the bottom of the top 10. This is significant for MSN because much lower results seriously increases the time taken to find what you want.

Some oddities included Yahoo having numerous entries that were highly irrelevant and MSN having a curious slant to open source results, particularly source code.

Subscribe to Posts [Atom]