Start-up Nation: The Story of Israel’s Economic Miracle

By Eitan Magid’s recommendation, I’ve been reading ‘Start-up Nation: The Story of Israel’s Economic Miracle’ in the past few weeks. Though I’m only half way into the book, I must admit, it is one of the more inspiring books I’ve read lately. Guess that being an Israeli has something to do with it, but even objectively speaking, you just can’t ignore the strong points the book trying to pass as for how did Israel became such a prominent start-ups nation.

Dan Sanor (the author), is trying to explain our critical thought process after a military training and service, how Israeli were wired a bit differently due (or thanks) to an utter unique set of challenges, and risks. Bringing very good and current example for very successful startups launched in Israel, and at the same time how Israeli teams changed the direction for giants such as Intel, taking them to the next level.

Guess I have more understanding, and sympathy to that book coming from my vantage point, but I do believe you will all enjoy it, and everybody and take something out of it just the same.

Grab your copy, and let me know what are your thoughts…..

My recipe for a paged list / DataModel with strong type

I needed to create some sort of IList that can handle a data source that supports paging.

Let’s start with the basics –
our class :

public class MyPagedDataModel<T> {
 /// ... code goes here....
}

Let’s continue by allowing us to determine the page size, current page index, and our data source.

        /// <summary>
        /// how many records per page
        /// </summary>
        public virtual int PageSize { get; set; }

        /// <summary>
        /// Current page index - offset 1 (first page is 0)
        /// </summary>
        public virtual int CurrentPageIndex { get; set; }

        public virtual object DataSource { get; set; }

To determine the number of records, and pages, I will have to skip one step, I trust you can keep up, but feel free to contact me if you have questions –


private IEnumerable<T> _list;

 public virtual IEnumerable<T> DisplayItems {
            get {
                ParseData();
                return _list;
            }
        }

internal override void ParseData()
        {

            if (_list == null)
            {
                _list = (IEnumerable<T>) DataSource;
                ApplyFilters();

                if (!PrePaged)
                {
                    TotalRecords = ((IQueryable<T>) DataSource).Count();

                    _list = _list.Skip(CurrentPageIndex * PageSize).Take(PageSize);
                }

            }
            base.ParseData();
        }

/// <summary>
        /// Total data records
        /// </summary>
        public virtual int TotalRecords
        {
            get
            {
                if (_totalRecords>0)
                    return _totalRecords; 

                ParseData();
                return _totalRecords;
            }
            set
            {
                _totalRecords = value;
            }
        }

        /// <summary>
        /// Compute the pages count.
        /// </summary>
        public virtual int TotalPages{
            get {
                if (PageSize == 0)
                    return 0;

                return (int)Math.Ceiling((decimal)TotalRecords / (decimal)PageSize);
            }
        }

Let’s see the complete class

public class MyPagedDataModel<T> {
        /// <summary>
        /// how many records per page
        /// </summary>
        public virtual int PageSize { get; set; }

        /// <summary>
        /// Current page index - offset 1 (first page is 0)
        /// </summary>
        public virtual int CurrentPageIndex { get; set; }

        public virtual object DataSource { get; set; }

private IEnumerable<T> _list;

 public virtual IEnumerable<T> DisplayItems {
            get {
                ParseData();
                return _list;
            }
        }

internal override void ParseData()
        {

            if (_list == null)
            {
                _list = (IEnumerable<T>) DataSource;
                ApplyFilters();

                if (!PrePaged)
                {
                    TotalRecords = ((IQueryable<T>) DataSource).Count();

                    _list = _list.Skip(CurrentPageIndex * PageSize).Take(PageSize);
                }

            }
            base.ParseData();
        }

/// <summary>
        /// Total data records
        /// </summary>
        public virtual int TotalRecords
        {
            get
            {
                if (_totalRecords>0)
                    return _totalRecords; 

                ParseData();
                return _totalRecords;
            }
            set
            {
                _totalRecords = value;
            }
        }

        /// <summary>
        /// Compute the pages count.
        /// </summary>
        public virtual int TotalPages{
            get {
                if (PageSize == 0)
                    return 0;

                return (int)Math.Ceiling((decimal)TotalRecords / (decimal)PageSize);
            }
        }

}
As always, feel free to contact me with suggestions or questions

The 10 things you should never tell your man

There are only few things you should never tell your guy. Some questions and talks might even cost you your relationship.

Speaking as a guy with the weirdest dating history, and a guy that got divorced more times than he got married, I feel I’m some sort of an authority when it comes to doing the wrong thing.

Let’s go over the ‘don’t do list’ :

1) “When will I see you again?”
Every beginner HR personnel knows that when a candidate ask about their salary during the first interview, they are probably the wrong person for the job.
Same rule applies to dating. Don’t ask us when will I see you again, let us ask you out, leave us with a new peak to conquer – a second date!

Once you asked us that question, the manly gland ( a simple gland that controls our live – get laid, get paid, die), naturally switches to the ‘let’s hook up’ mode… or something more like – ‘oh yeah, I’m in… Let’s meet tomorrow, my apartment is shiny and I just restocked my stash of condoms.’

2) “Do you think that she’s pretty?”
‘She is cute, but not as pretty as you!’ (lie! lie! lie!) … Please never ask us that question.
No reasonable man would honestly answer that question (just FIY). Guys don’t like you trying to compare yourself to every hot woman that is walking by (coincidentally, all of them are very very young, way younger than you!).

I understand competition as much as the next person, I even admire competitive nature; But in that specific instance you are asking a question that every man on earth (at least the mildly sane and above) will give you the same answer (and since you usually pick the most outrageously hot girl that walked by, lie).

3) “Don’t worry about it, it’s fine, nothing happened”
During instances of misscommunication, you result to ‘nothing happened’, while what you actually think is closer to ‘he doesn’t get me. No point in telling him’. Our brain is painfully simple, when you tell us it’s OK, we actually believe you!
In fact, you are more likely to get our back that night, than an attempt to understand what we did wrong.

Don’t get me wrong, guys are trained (or rather both designed by nature and nurtured) to take whatever you say as a cleaver mask, we know that there is always an hidden agenda, but please – give us a hint/ sign.
Keep one thing in mind, by the time you finished that sentence, we actually believe that everything is fine, and free as much brain space as possible to think about sex.

4) “…. we need to talk”
First thing that jump to our mind – ‘Was don’t need to talk!’
Whenever you say the above phrase, expect your guy to shut down, and avoid a serious conversation at any cost.

If what you had in mind is a talk about him leaving clothes all over the place; You must find another opening .

5) “I want to try anything, at least once”
Oooh, that one is tricky .
Don’t say it unless you really mean it. Trust me, your guy has way more fantasies than you could ever imagine.
When we start acting on our fantasy, and you back down, it could be really disappointing .

So…. let’s change ‘anything’ to ‘anything but…’

6) “What are you thinking about right now?”
Never ask us that question!.
Most of the time, we don’t think, we react. Other times we are trying to find the perfect strategy for how to make todays’ date successful .

Either way – we just don’t have an answer to that particular question!

7) “You are just like my ex”
Bad Bad Bad date!
What would you think if I told you that you were just like my ex?

Yes factoring your taste, features you find attractive, and your unique chemistry with potential mates, it is safe to assume we share few qualities with (all) your ex (es).
But we want to feel like we are the first, don’t bring up previous relationships!!!!

8) “I don’t trust you yet”
wrong thing to say in any situation. Why bother if you start from a negative place.

9) “What are you thinking about right now?”
The most annoying question for a first (or one of the firsts) date .
While you spend a lot of brain power figuring out what we might be thinking about at the moment, we don’t think about anything!!
But when you ask us that we do feel compelled to come up with something so we spend time and a lot of energy coming up with something we think you might like.

10) “How many girls have you slept with?”
No No No No! we don’t want to know with how many guys you’ve been with, and we will NEVER EVER give you a real number!
But you do come across as an easier target to conquer. After all you mentioned sex first!

Hope that helps
Let’s hear question that you don’t want to hear during one of the first dates….

How to convert an object in C# to JSON

While working on one of my favorites eMagid projects – rentalengine, one of our technicians had to deal with a small hurdle – How to convert custom object into JSON, so it can be consumed by our rich JavaScript UI.

The solution is actually way more simple than you’d imagine – There is a built it serializer just for that in the System.Web.Script.Serialization namespace.

So… let’s see it in action :

First – let’s built our object:

[Serializable()]
public class MyObject {
    public string StringField { get; set; }

    public int[] Numbers { get; set; }

    public String[] Names { get; set; }

}

Now the fun part – Convert to JSON

Step 1. Import the namespace

using System.Web.Script.Serialization;
Guess the namespace implies what assembly to import



Step 2. Let’s JSON it!

Your are going to LOVE how simple it is
JavaScriptSerializer o = new JavaScriptSerializer();
string json = o.Serialize(Images);

Is that all???

YES! that’s all. You just converted your object (custom, ADO, Linq object, or otherwise) to JSON!!

Files and photos storage, Filesystem vs DB

A question that I hear too frequently is “Whether I should save uploaded files, and photos to the DB or to my file-system”

First, let me give you my answer – FileSystem!!! 

… and here is why-

*  Though, wish modern DB engines such as MSSQL 2008, the access to either is as fast, storing your files on the DB requires an extra step of translating the query to a stream output. A step that can be easily avoided by letting the browser and the IIS handle the file fetching .

* Using the same repository to store your files and data will be very costly if you ever decide to improve your application performance by  moving photos to a CDN (Content Delivery Network).

* For shared hosting – usually your DB space is limited, storing the files there will increase the DB size significantly.

* The dreadful word, every DBA hates – bottleneck! A major consideration when designing a software is to keep the queries to a minimum. Thus reducing bottlenecks, and ensuring rapid execution of queries. Saving files to your DB will create too many necessary queries, and potentially bottlenecks.

* Caching – though you can cache data fetched from your DB as well, letting the IIS treat files as static will save you a lot of space, code and headache.

* On a more personal note – sometimes we build websites (mostly ecommerce, or photography) that requires images in different sizes (thumbs), re-creating and resizing on the fly may proof very costly, what we usually do is resize the photo upon the first request, and save it as a file in the filesystem, the second time a visitor request for that image in that size, the file already exists, so the IIS will deliver it as an ‘unchanged’ file, reducing execution time, use resources .

Would love to hear your thoughts…

Photographer’s guide to buying a camera

About two years ago I published the following tutorial on fotoshoot.com for beginner photographers, trying to help you find the right camera for you -

What is the perfect camera?

The answer to that is rather simple – there is none !

There is a better camera for every photographer, subject, there are cameras that are better than others in one feature or another, but there is no camera that is superior to all others in every situation, and in every feature, and for every photographer. Therefore, you must choose carefully the most appropriate camera for your needs, your knowledge of photography and most importantly – budget…

Today there are hundreds and perhaps thousands models of compact digital cameras and SLR or DSLR professional cameras. So choosing the best camera for you is not an easy choice.

Just remember that after all the buttons, screens and other nice toys, this is a camera, and it should posses few basic elements and features that will enable the production of good photos. That’s it, nothing more, nothing less.

First, lets try to match the camera to our subject :

1. Landscape and nature photography :

I recommend a lightweight camera lens wide angle lenses or other adapters that enable a wider angle, and let you capture a wider scene. Should also be larger focal length (zoom, for example, optical zoom x10 or even X12) It will allow close-up of trees, buildings or animals. Get one before your next safari.

2. Portraits Photography : 

You should purchase a camera with a medium focal length lens (For example, optical zoom x6), it will enable you to capture people from a reasonable distance.

More experienced photographer will use a wider angle, to capture more details from the wider scene, but I wouldn’t recommend it to a beginner. It is also highly recommended to make sure that you can control the camera’s depth of field !

3. Close-ups (macro): 

Choose a camera with a close-up and a large depth of field. There should be a possibility to add a dedicated close-up lens. In some digital cameras you can get as close as one centimeter (1inch = 2.54cm) from the object! A camera that allows an external flash will weight few pounds more, but will yield great results next time you decide to try to see how a bee looks like on a flower, colorful sunny day.

There are two more points, but for that you must visit the original post…

Photographer’s guide to buying a new camera

How To: Start a process from c# code

Working for eMagid does require from time to time an original solution for a common, or more frequently non-common problem.

Problem at hand required us to build a Console Application, that intelligently crawl website, and scrap key information.
The follow up was to allow the admin to launch that application directly from their website.
There are three parts for the solution -

  1. Allowing the admin launch the console application
  2. Thread it! make sure that running the process doesn’t throw the website to a timeout .
  3. Ensuring that the application cannot be launch while a previous instance is still running.
Now let’s see how it should be done!



Running the process

In our case we had to provide the application with arguments, but that’s not always the case, so let’s create a method that can support either way.
All the following code does is run the application / process.

public void ExecuteApp(object o)
        {
            try
            {
                ProcessStartInfo ProcessInfo;
                System.Diagnostics.Process Process;

                ProcessInfo = new ProcessStartInfo("C:\MyApp.exe");

                // Check to see if there are arguments to pass along to the app
                if (o != null)
                {
                    ProcessInfo.Arguments = o.ToString();
                }

                // The console application will be launch, 'false' means that it will run without the user seeing a window popping up.
                ProcessInfo.CreateNoWindow = true;
                ProcessInfo.UseShellExecute = false;
                Process = System.Diagnostics.Process.Start(ProcessInfo);

            }catch
            {

            }

        }



Thread it

In this part we are making sure that the process runs as an independent thread (still inside the AppDomain, but it will allow us to continue using the site normally, without waiting for the ‘server side process’ to finish).

public void RunReader(object o)
{
    var ts = new ParameterizedThreadStart(ExecuteApp);

    (new Thread(ts)).Start(o);
}

public void ExecuteApp(object o)
        {
            try
            {
                ProcessStartInfo ProcessInfo;
                System.Diagnostics.Process Process;

                ProcessInfo = new ProcessStartInfo("C:\MyApp.exe");

                // Check to see if there are arguments to pass along to the app
                if (o != null)
                {
                    ProcessInfo.Arguments = o.ToString();
                }

                // The console application will be launch, 'false' means that it will run without the user seeing a window popping up.
                ProcessInfo.CreateNoWindow = true;
                ProcessInfo.UseShellExecute = false;
                Process = System.Diagnostics.Process.Start(ProcessInfo);

            }catch
            {

            }

        }



Last part – One is not necessarily a lonely number

So let’s make sure there is only one single instance of the process running at a time

Shall we start with adding a static flag?!

public static bool AppIsRunning = false;

And let’s put it all together.


        public static bool AppIsRunning = false;

        public void RunProcess(object o)
        {
            // Making sure the process is not already running.
            if(MyController.AppIsRunning)
                return ;

                var ts = new ParameterizedThreadStart(ExecuteReader);

                (new Thread(ts)).Start(o);
        }

        public void ExecuteProcess(object o)
        {
            try
            {
                // changing the 'current running' flag to true
                MyController.AppIsRunning = true;

                ProcessStartInfo ProcessInfo;
                System.Diagnostics.Process Process;

                ProcessInfo = new ProcessStartInfo("C:\MyApp.exe");

                // Check to see if there are arguments to pass along to the app
                if (o != null)
                {
                    ProcessInfo.Arguments = o.ToString();
                }

                // The console application will be launch, 'false' means that it will run without the user seeing a window popping up.
                ProcessInfo.CreateNoWindow = true;
                ProcessInfo.UseShellExecute = false;
                Process = System.Diagnostics.Process.Start(ProcessInfo);

                // Hey, that line wasn't there before !!
                // Well this is where we register the delegate to handle the event fired after the process finished its work.
                Process.Exited += new EventHandler(Process_Exited);
            }catch
            {
                // Obviously the process is no longer running.
                MyController.AppIsRunning = false;
            }

        }

        void Process_Exited(object sender, EventArgs e)
        {
            MyController.AppIsRunning = false;
        }