“Algorithm” is not a four letter word…

I bumped into this presentation by Jamis Buck about understanding and experimenting with algorithms. I am impressed the way he presented various algorithms for generating mazes and puzzles. Well the intent behind his presentation is to try out something new so that you keep outdoing yourself every now-and-then.

"Algorithm" is not a four letter word

How to arrange and sort files in Lion Finder

by Kirk McElhearn

Like its predecessors, Lion’s Finder gives you four ways to view your files: icon view, list view, column view and Cover Flow view. But it also gives you some new ways to arrange files within those views: In addition to Arrange By, Lion adds Sort By and Clean Up By. Unfortunately, those arrangements aren’t so straightforward.

The three sorting tools do have three distinct functions: Arrange By lets you organize files into groups. The new Sort By option does much of what Arrange By did in the past. And Clean Up By is a kind of impermanent Sort By. But the three options aren’t always available in all Finder views. Sometimes you can combine them; sometimes you can’t. There are multiple ways of invoking them. In other words, they aren’t Apple’s smoothest bit of interface design. But here’s a rough guide to the way they work. (more…)

Secrets of Lion’s Spotlight menu

by Sharon Zardetto,

The handy Spotlight menu, at the far right of your menu bar, is even handier in Lion because it offers new ways to work with the list of search results. Click the magnifying glass icon or use the default Command-Spacebar shortcut to open the menu, and type in your search term. Then, use these tips to go from searching to doing.

Control which categories you see in the menu

Want to see PDFs in your Spotlight results, but not music files? Control what results show in the Spotlight menu by tweaking your Spotlight Preferences. Go to System Preferences and select Spotlight; click the Search Results button and then check the categories you want listed in the menu. (This limits only what shows in the Spotlight menu, not the results in a Finder window search.) You can also drag a category up or down in the list to change the results order. You might, for instance, want presentations listed at the top of the menu because you work with them so frequently. The Spreadsheets category is new in Lion; it hides or shows both Numbers and Excel documents.

Take a Quick Look at files

If you’re not sure that a result you see in your Spotlight menu is what you’re looking for, take a quick look. Point to an item in the results list and a Quick Look “popover” appears next to it. This means you won’t have to head to the Finder or open the item to see such things as images, the contents of a document, contact information in Address Book, iCal events, a font sample, or an email.

To do it all from the keyboard, use the Up or Down arrow key to navigate the results list and pause on the item you want to see.

Peek at your Top Hit

The Spotlight Menu automatically picks a “Top Hit” for your search, displays it at the top of your results, and selects it. That’s convenient when you want to open the Top Hit, because all you have to do is hit Return. But what if you want to preview the item first? Pointing to the Top Hit, or using an arrow key to move away from it and then back again, displays the popover, but there’s quicker way: just hold down the Command key.

In Spotlight preferences, check the categories you want in the results list, and drag them into the order you prefer to see them.

Continue Reading…

Multithreading in C++11 – part 2

In previous post we saw briefly how to create threads with various constructors. In this post I want to continue along the same lines.

Note: you will need to install Visual Studio 2011 Developer Preview to tryout the code.

In last post we saw how to spawn the threads with simple execution code like functions, functors and labmda functions. In this post we will briefly explore invoking member-functions on objects as execution units of code.

Lets start with the simple code to invoke non-virtual member function:


#include <iostream>
#include <thread>

class Object
{
private:
    double d;
public:
    Object(double val = 10) : d(val)
    {}

    void Invoke() const
    {
        std::cout << "From thread 1: val of d is - " << this->d << std::endl;
    }

};

int main()
{
    Object obj(25);

    //  here we specify the function to be invoked on the object
    //
    std::thread t(&Object::Invoke, &obj);

    t.join();

    std::cin.ignore();
    return 0;
}

It seemed nice to be able to invoke member functions on objects. But lets try to be a bit more adventurous and see how to invoke virtual member functions: (more…)

Multithreading in C# – part 1

Here I posted multithreading in C++11. Well I did ran into issues with C++ library. To validate I tried the same dotproduct example in C#.

Here is the code for the same:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class DotProduct
    {
        double[] a;
        double[] b;
        double[] res;
        int id;
        int numElems;

        public DotProduct(double[] aa, double[] bb,
            double[] r, int nElems, int ident)
        {
            a = aa;
            b = bb;
            res = r;
            id = ident;
            numElems = nElems;
        }

        public void Evaluate()
        {
            res[id] = 0;
            for (int idx = id * numElems, end = (id + 1) * numElems;
                idx < end; ++idx)
            {
                res[id] += a[idx] * b[idx];
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int numElements = 100000;
            double[] a = new double[numElements];
            double[] b = new double[numElements];

            for (int idx = 0; idx < numElements; ++idx)
            {
                a[idx] = idx;
                b[idx] = numElements - idx;
            }

            double[] result = new double[4];
            int numElems = numElements / 4;

            DotProduct dp1 = new DotProduct(a, b, result, numElems, 0);
            System.Threading.Thread thread1 =
                new System.Threading.Thread(new System.Threading.ThreadStart(dp1.Evaluate));

            DotProduct dp2 = new DotProduct(a, b, result, numElems, 1);
            System.Threading.Thread thread2 =
                new System.Threading.Thread(new System.Threading.ThreadStart(dp2.Evaluate));

            DotProduct dp3 = new DotProduct(a, b, result, numElems, 2);
            System.Threading.Thread thread3 =
                new System.Threading.Thread(new System.Threading.ThreadStart(dp3.Evaluate));

            DotProduct dp4 = new DotProduct(a, b, result, numElems, 3);
            System.Threading.Thread thread4 =
                new System.Threading.Thread(new System.Threading.ThreadStart(dp4.Evaluate));

            thread1.Start();
            thread2.Start();
            thread3.Start();
            thread4.Start();

            thread1.Join();
            thread2.Join();
            thread3.Join();
            thread4.Join();

            System.Console.WriteLine("Dotproduct is {0} ",
                (result[0] + result[1] + result[2] + result[3]));

            System.Console.ReadKey();

        }
    }
}

First we create DotProduct class that holds the arrays and result array. Every DotProduct class has an id to identify the range of array it is going to operate on. Next we create 4 threads and pass-in for instances of DotProduct and the method to be executed on the thread. Unlike C++11, creating thread does not start the thread, it has to be called explicitly. Then as discussed in C++11 multithreading post we wait until all the threads have completed the execution. That’s it. Quite simple. :)

More to come. Stay tuned…