Category Archives: Software

Microsoft Award

Today is a special day — I was awarded for my work (related to NIC Teaming) and I am enjoying this day thoroughly :)
Some thoughts: the people I work with are … scary smart, and at the same time very kind (a rare combination).
I am very fortunate to have both: opportunity and means to contribute.

Thank you!

Dmitry_Kalashnikov_Microsoft_Award_2010

Sieve (of Eratosthenes) algorithm for generating prime numbers

A prime number is divisible by 1 or by itself. To generate prime numbers to 20 we’ll use Sieve (of Eratosthenes) algorithm, which is really simple to explain:

Strike out all multiples of 2′s:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Strike out all multiples of 3′s:

2 3 5 7 9 11 13 15 17 19

And so on. Here is a C# code that does exactly that:

      
private static void PrintPrimesTo(int num) {
            var primes = new bool[num + 1];

            // init candidates
            for (int i = 2; i <= num; i++) { primes[i] = true; }

            // cross-out 2's:
            //   2, 4, 6, 8, 10...
            // cross-out 3's:
            //   9, 12, 15...
            for (int i = 2; (i * i) <= num; i++ ) {
                Console.WriteLine("Crossing out {0}'s to {1}:", i, num);

                for (int j = i * i; j <= num; j = j + i) {
                    Console.WriteLine(" * crossing-out: {0}", j);
                    primes[j] = false;
                }
            }

            Console.WriteLine("Results: prime numbers between 2 and {0}:", num);
            for (int i = 2; i <= num; i++) {
                if (primes[i]) Console.WriteLine(" * {0} ", i);
            }
        }

Continue reading

How to display song lyrics on iPhone/iPod

Did you know your iPhone/iPod software can display lyrics for songs?

Adding lyrics to your songs

You just need to make sure your mp3 files have “lyrics property” populated.

On your computer, open iTunes, right click on a song and choose “Get Info”. You should see this dialog:


Now click on “Lyrics” tab and add your text.

You can copy and paste lyrics text from websites, such as:

(Also, if you look around you’ll find jailbreak iPhone 5 software that will automatically add lyrics to all of your songs)

How to view lyrics on iPhone:

Once you’ve added lyrics to your songs and synced your phone, here is how you view it: when the song is playing, simply tab the screen once and it will overlay lyrics over album art!


Regex Notes

Regular expressions (regex) let you search for a particular pattern. Regex consist of literal characters, and special characters, also called meta characters. Regex syntax has 2 modes, one inside of character classes, which is inside [ ] and one outsided of character classes. Continue reading