Saturday, November 12, 2011

Text Lines Should Not Be Null Schema Compare

Text Lines Should Not Be Null
Schema Compare Error in Visual Studio
DACProjectSystemSetup_enu.msi

For the last 30 minutes I'm getting crazy trying to understand  what the error "text lines should not be null" means, and why it happens every time I try to compare databases schema in Visual Studio 2010 Ultimate.

It appears like my installation of the VS 2010 didn't execute correctly, so I have several packages missing.

A small package called "DACProjectSystemSetup_enu.msi" was probably missing.

After installing it, I can compare data and data schema easily :)

The Package is available here.

Hope it helped,
Elad Shalom,
CTO at ITweetLive.com

Sunday, November 6, 2011

The Path is Already Mapped in Workspace

The path is already mapped in workspace error.
The path x is already mapped in workspace.
Error The path is already mapped in workspace. 
TFS 2010 Mapping Issues.

I've lately reinstalled my TFS 2010 and after do so, I encountered an extremely annoying error:
"The path is already mapped in workspace".

I searched for almost everywhere, I tried changing Visual studio files and nothing.
It was only then I found out where was the problem - in my Team Foundation Cache.

After realizing that - the rest was fairly easy.
Simply go to this folder: C:\Users\{UserName}\AppData\Local\Microsoft\Team Foundation\3.0\Cache and delete all that's in the folder.

This was a rather quick solution to a problem that was keeping my mind busy :)

Hope it helped,

Elad Shalom,
CTO at ITweetLive.com

Friday, October 7, 2011

Failed to Execute Url

Failed to Execute URL Exception.
Isapi Rewrite and Asp.Net 4 on IIS6.
Failed to Execute URL asp.net 4 IIS 6 Windows Server 2003.

Currently working in ITweetLive, I encountered what seemed to be a massive problem while trying to upgrade my website from .Net 3.5 to .Net 4.

First thing first.
Our website was compiled with .Net 3.5 up until couple of days ago when I wanted to start working with .Net 4.  A short conversion made by Visual Studio 2010 and then recompile.  The localhost works like a charm.

Next step was to create a different application pool in IIS6 (I named it ".Net4") which will be only for the websites who have been converted to .Net 4 framework.
After that it was simply assign the new application pool to the website and change its version to .Net 4, as simple as it sounds.

But, and here came the real problem, when trying to reach the website's root without the "default.aspx" I encountered a "Failed to Execute URL" exception.

After couple of hours digging the web, I found what I wanted in the form of a great post made by Rhys Godfrey.

Long story short, these are the steps you need to do if:
  1. You got an "Failed to Execute URL" exception.
  2. You are running on Windows Server 2003 and IIS6.
  3. You're using the Isapi Rewrite.
  4. You just updated you're website from .Net 2 (and it's versions: 3, 3.5) to .Net 4.
Steps to do:

1. Type "REGEDIT" on the run window and click enter.


2. Go to this directory: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\4.0.30319.0 

3. Create a new DWORD value and name it "EnableExtensionlessUrls".
4. Set "EnableExtensionlessUrls" to 0.  This will disable extensions URL behavior.
5. Save the registry value and close the editor.
6. Type iisreset on the run window and click enter.
    Now you have a functioning website using both .Net 4 and Isapi Rewrite on Windows Server 2003 and IIS6.

    Hope it helped,
    Elad Shalom,
    CTO at ITweetLive.com

    Tuesday, September 27, 2011

    Split String in SQL Server

    Split String in SQL Server.
    NVARCHAR and VARCHAR Split in MS SQL.

    For all of you there who wishes to preform a simple "split" on a varchar on nvarchar input in ms sql (sql server) this is for you:

    Basically, this post's gonna contain a Create Function Script which you will to execute in your server.  It will also contain the simplest way to use it.

    There will be more examples in a different post I'll upload soon...

    CREATE FUNCTION dbo.Split
    (
        @RowData nvarchar(2000),
        @SplitOn nvarchar(5)

    RETURNS @RtnValue table
    (
        Id int identity(1,1),
        Data nvarchar(100)
    )
    AS 
    BEGIN
        Declare @Cnt int
        Set @Cnt = 1

        While (Charindex(@SplitOn,@RowData)>0)
        Begin
            Insert Into @RtnValue (data)
            Select
                Data = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))

            Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))
            Set @Cnt = @Cnt + 1
        End
       
        Insert Into @RtnValue (data)
        Select Data = ltrim(rtrim(@RowData))

        Return
    END


    Pay attention that the two parameters are mandatory:
    1. nvarchar to split.
    2. nvarchar which will be the delimiter.

    Hope it will help,
    Elad Shalom,
    CTO at ITweetLive.com

    Submit Blogger Sitemap to WebMaster Tools

    Submit Blogger Sitemap to Webmaster Tools.
    Submit Blogger Sitemap to Google Webmaster Tools.
    Atom.XML Error in Google Webmaster Tools.

    Hey there.
    Couple of hours ago I entered my Google Webmaster Tool account only to find out that my sitemap hasn't been indexed lately.

    After a click on the link, I found out that /atom.xml has an automatic redirect, which doesn't allow the webmaster tool to index it correctly.

    The fix is quite simple though.
    remove your current sitemap and replace it with this link:
                        /atom.xml?redirect=false

    Also, enter this sitemao:
                        /feeds/posts/default?=rss  


    These two sitemaps will make sure your blog will be indexed correctly. 

    Have fun and keep up the good work,
    Elad Shalom,
    CTO at ITweetLive.com

    Thursday, September 22, 2011

    Date Validation in JavaScript

    Date Validation in JavaScript.
    Date Time Validation in JavaScript.

    Couple of days ago I had the need to validate an input as a Date in JavaScript.  I though for some time on the best way to do it so it would be as generic and stable as possible.

    After finalizing my method, I decided to add it to our jsValidation.js file as well as uploading the method to my post to help others in need...

    The method returns true if the date is a valid date and false if it's not.
        function isValidDate(d) {
            if (Object.prototype.toString.call(d) !== "[object Date]")
                return false;
            return !isNaN(d.getTime());
        }

    The way to use this method will be:
        function Demo() {
            var d1 = new Date("invalid");
            var d2 = new Date("1985");
     
            var result_false = isValidDate(d1);
            var result_true = isValidDate(d2);
        }

    Have fun with it,
    Elad Shalom,
    CTO at ITweetLive.com

    Tuesday, September 13, 2011

    Enabling JavaScript on Your Computer

    Enabling JavaScript on Your Computer
    Enabling JavaScript on Your Browser

    Lately I'm getting tons of questions from our Twitter users regarding a problem their having with their javascript.

    Basically, this problem says that they can't surf the web (mainly surf Twitter) because javascriupt is not enabled for their browser/computer.

    Well, I'm here to fix it:

    How to Enable JavaScript in IE (Internet Explorer):
    • Tools > Internet Explorer > Security
      • Internet Zone
        • Custom Level
          • Scripting > Active Scripting > Enable

    How to Enable JavaScript in FF (Fire Fox):
    • Tools > Options
      • Content

        • Enable JavaScript
     
















    Hope it helped,
    Elad Shalom,
    CTO at ITweetLive.com

    Monday, September 12, 2011

    (new Date).zeroTime is not a function jQuery Error

     "(new Date).zeroTime is not a function".
    jQuery DatePicker JS Error.

    One of my developers recently encountered a jquery issue.  He tried to use the jquery DatePicker.js and for some reason (this error) couldn't make it work.

    When he tried to open the DatePicker.js calendar he got the error: "(new Date).zeroTime is not a function".

    This error happens because the function "zeroTime" is not being added to the data prototype.  it should be added in the date.js file, which was not updated.

    After updating the date.js (available here) it all went smooth.


    Hope it helped,
    Elad Shalom,
    CTO at ITweetLive.com

    Monday, March 14, 2011

    Looping through Object's properties in C Sharp

    Loop to Find All Properties Info of an Object In C Sharp..
    Loop to Find All Properties Info of an Object In C#.

      Have you ever tried to make a dynamic test page? To build and HTML element contains all the properties of a specific .Net object?

      Well, I encountered this problem couple of days ago and while searching Google I barely found good matches.  So I decided that for my sake, and yours, I will simply post a short explanation about how to do it, followed by a quick and simple example of how to loop though object properties in C#.

      First I'll provide a short explanation about Reflection:
      Reflection enables you to discover an object's properties, methods, events and properties values at run-time.  Reflection can give you a full mapping of an object (well, it's public data).

      In order to use reflection, and to loop through the object's properties, we'll first have to import the namespace:
      using System.Reflection;

      Now, lets say I have an object called User and this object has 2 public properties:
      1. UserID.
      2. Name.
      My code will look something like this:

      int testID = 123456;
      User usr = new User(testID); // this is constructor to get user by ID
      StringBuilder sb = new StringBuilder();

      PropertyInfo[] properties = user.GetType().GetProperties();
      foreach (PropertyInfo pi in properties)
      {
          sb.Append(
              string.Format("Name: {0} | Value: {1}", 
                      pi.Name, 
                      pi.GetValue(user, null)
                  )
          );
      }
      divResults.InnerText = sb.ToString();

      This little piece of code will fill your HTML element with the properties names and values.

      Have Fun,
      Elad Shalom,
      CTO at ITweetLive.com

      Sunday, March 13, 2011

      JavaScript Looping Through Object Properties

      Looping Through JSON Object Properties in JavaScript.

      My previous post contained a small piece of code explaining how to loop through object properties with the Reflection namespace in C#.

      In this post I'd like to explain how do loop through JavaScript object.

      Let's create an object in JavaScript:

      var myObject = {
          Name: "Elad",
          LastName: "Shalom",
          Age: 26,
          Kids: ["Daniel"]
      };

      This object contains 4 properties:
      1. Name (string)
      2. LastName (string)
      3. Age (int)
      4. Kids (array)
      Now  for the loop part:

      function LoopThroughProperties(obj)
      {
          for (var propName in obj)
          {
              alert(propName + ": " + obj[propName]);
          }
      }

      The function will receive an object and loop through all of it's properties.

      I'd like to take 2-4 more lines to explain a bit about the for syntax I used.
      Those of you who write in C# / VB / Java will find it very similar to foreach loop in JavaScript.

      Since an object in JavaScript is a form of array, I can easily call every one of it's properties the same way (almost) I'd call them when looping through array.
      This type of forach loop in JavaScript is also very useful when going through a hash table.  since we don't know the numbers the hash contains, we can simply loop through it.

      Thanks,
      Elad Shalom,
      CTO at ITweetLive.com

      Tuesday, March 1, 2011

      Test Driven Development In C Sharp

      Test Driven Development in C#.
      This is a Short Introduction for Test Driven Development in Visual Studio 2010.

      This tutorial will contain short and basic explanation of Test Driven Development followed by a quick walk through in Visual Studio 2010 written in C Sharp.

      For those of you who don't know, Test Driven Development is a different way of coding.  Some say a different way of life.  Instead of first developing your software and then test it, What Test Driven Development Methodology offers is to first test, then code.

      Basically it allows us to cover a variety of User Stories and Test Cases, build the tests for them and only after all is covered - start coding while testing our code every step of the way. 

      Some principles of Test Driven Development:
      1. Tests serve as examples of how to use a class or method.
      2. Naming. be explicit as possible so that everyone will be able to understand, rewrite and maintain your tests.
      3. There's a simple "3 A's" pattern for test driven development:
        1. Arrange - Variable Deceleration.
        2. Act - invoking the code under test.
        3. Assert - using the Assert Method to verify that expectations were met.

      This short video walk-through will try to give you a basic understanding of the Test Driven Development.

      This  walk-through will include a CalcTest project and a Calc project which will have one basic method:
      • Add.


      Good luck,
      Elad Shalom,
      CTO at ITweetLive.com

      Monday, February 21, 2011

      MSSQL Advanced Join Statements

      Advanced Join Statements in MS SQL Management Studio.

      There are several different Join types in here I will discuss them:
      Cross Join Statement
      Full Join Statement

      Joining tables is one of the most useful operations we have. Large data should be divided to several tables (see Normalization Rules) for maximum flexibility and minimum resources usage.

      Cross Join Statement:

      In the Cross Join statement, based on the two tables within the Join, a Cartesian product is created if a 'Where' statement filter the rows.  The size of the Cartesian product is based on multyplying the number of rows from the left table by the number of rows from the right one.
      Be careful when using the Cross Join.  it might cause more damage than good.

      Example:
          SELECT  TOP 100 P.ProductID,
              P.Name,
              P.ListPrice,
              P.Size,
              SOD.UnitPrice,
              SOD.UnitPriceDiscount,
              SOD.LineTotal
          FROM Sales.SalesOrderDetail SOD
          CROSS JOIN Production.Product P
              WHERE SOD.UnitPrice > 3500
          ORDER BY SOD.UnitPrice DESC


      Full Outer Join Statement:

      As you remember, the Left Join and Right Join statements where basically the same Select with different Join statements.  In this example, the result is the same as the Left Join, with mile changes.

      Example:
          SELECT C.ContactID,
              C.FirstName,
              C.LastName,
              SP.SalesPersonID,
              SP.Bonus,
              ST.TerritoryID,
              ST.Name
          FROM Person.Contact C
          INNER JOIN Sales.SalesPerson SP
              ON C.ContactID = SP.SalesPersonID
          FULL OUTER JOIN Sales.SalesTerritory ST
              ON ST.TerritoryID = SP.TerritoryID
          ORDER BY ST.TerritoryID, C.LastName



      Good luck,
      Elad Shalom,
      CTO at ITweetLive.com

      Monday, February 14, 2011

      MSSQL Join Statements

      Join Statements in MS SQL Management Studio.

      There are several different Join types in here I will discuss them:
      Inner Join Statement
      Left Outer Join Statement
      Right Outer Join Statement
      Self Join Statement

      Joining tables is one of the most useful operations we have. Large data should be divided to several tables (see Normalization Rules) for maximum flexibility and minimum resources usage.

      Inner Join Statement:

      Inner Join is meant for combining rows between two tables, based on at least one column with the same data.
      Although columns with the same data are the most common way to use the Inner Join, there is also a possibility to conduct it with "greater then", "not equal" etc.

      Example:
          SELECT TOP 10 P.ProductID,
              P.Name,
              P.ListPrice,
              S.UnitPrice,
              S.OrderQty
          FROM Sales.SalesOrderDetail S
          INNER JOIN Production.Product P
              ON S.ProductID = P.ProductID

      This is an example about a simple join which takes columns from two tables and combine it into one table when the mutual column is ProductID (on both tables).

      Left Outer Join Statement:

      In the Left Outer Join statement, all data is returned from the left table while on the right table, the matching data is returned as addition or as NULL where the record exists in the left table, but not in the right one.

      Example:
          SELECT C.ContactID,
              C.FirstName,
              C.LastName,
              SP.SalesPersonID,
              SP.Bonus,
              ST.TerritoryID,
              ST.Name
          FROM Person.Contact C
          INNER JOIN Sales.SalesPerson SP
              ON C.ContactID = SP.SalesPersonID
          LEFT OUTER JOIN Sales.SalesTerritory ST
              ON ST.TerritoryID = SP.TerritoryID
          ORDER BY ST.TerritoryID, C.LastName


       This is an example about a little complex join.  This one involves both the Inner Join (which we saw earlier) and the Left Outer Join.
      The syntax "Left Join" is also correct.
      Also, I added an "Order By" command.

      In the Right Outer Join statement, all data is returned from the right table while on the left table, the matching data is returned as addition or as NULL where the record exists in the left table, but not in the right one.
      Basically, exactly the opposite of Left Outer Join.

      Example:
          SELECT C.ContactID,
              C.FirstName,
              C.LastName,
              SP.SalesPersonID,
              SP.Bonus,
              ST.TerritoryID,
              ST.Name
          FROM Person.Contact C
          INNER JOIN Sales.SalesPerson SP
              ON C.ContactID = SP.SalesPersonID
          RIGHT OUTER JOIN Sales.SalesTerritory ST
              ON ST.TerritoryID = SP.TerritoryID
          ORDER BY ST.TerritoryID, C.LastName



      In this example I made the same Select as in Left Outer Join, but with the Right Outer Join. The point is for you to see the result for your self and be able to understand the exact difference between the two.

      Self Join Statement:

      In the Self Join statement, the same table is specified and "used" twice with two different aliases in order to match the data within the same table.

      Example:
          SELECT M.ManagerID AS 'ManagerID',
              M1.ContactID AS 'ManagerContactID',
              M1.FirstName AS 'ManagerFirstName',
              M.Title AS 'ManagerTitle',
              E.EmployeeID AS 'EmployeeID',
              E1.ContactID AS 'ContactID',
              E1.FirstName AS 'EmployeeFirstName',
              E.Title AS 'EmployeeTitle'
          FROM HumanResources.Employee E
          INNER JOIN HumanResources.Employee M
              ON E.ManagerID = M.ManagerID
          INNER JOIN Person.Contact E1
              ON E1.ContactID = E.ContactID
          INNER JOIN Person.Contact M1
              ON M1.ContactID = M.ContactID
          ORDER BY M1.LastName



      Good luck,
      Elad Shalom,
      CTO at ITweetLive.com

      Thursday, January 27, 2011

      Asp.Net Configuration - Open Broswer When Debug

      Configuring Asp.Net To Open New Browser Window When Start Debugging.

      Not too long ago I encountered a small problem that occurred to one of the developers in my team when he got a new computer.
      Previous to the new PC, whenever he clicked on "Start Debugging" (also known as F5) the solution compiled and opened a new browser window with the default page.


      After the new PC arrived the configurations in his Visual Studio 2010 were different. Meaning - Whenever he clicked F5, the project was compiling, but no browser windows appeared.


      With a short phone call I explained the steps he needs to do, but in order for it to be clear for all of us, I decided to upload it as a brief post.

      1. Right click on the project's name.
      2. Click on "Properties".
      3. A configuration manager window will open.
      4. Click on the third tab called "Web".
      5. On that tab you will have several sections, the first the is what we're interested in.
      6. on "Start Action" section (the first one) you will see many options:
        1. Current Page - Will open the page you're at.
        2. Specific Page - Will open a specific page.
        3. Start external program - Will run a specific ".exe" file.
        4. Start URL - Will allow you to choose URL to open.
        5. Don't open a page. Wait for a request from an external application - Kinda explain itself.

      Good luck, and thank to Noam from our Bulgaria office,
      Elad Shalom,
      CTO at ITweetLive.com

      Tuesday, January 25, 2011

      Configuration and Environment Variables - Visual Studio 2010

      How to create configuration or Environment variables in Visual Studio 2010.

      Environment variables are a great thing for when you publish your website to multiple places.
      It doesn't matter if you publish it to testing / staging / production environment or if you're publishing your site to several servers which require different methods to be called / different values assigned to parameters.

      Lets create a web application project (further explanations will be granted later)
      1. Open Visual Studio 2010
      2. Create New Project -> ASP.NET Web Application

      As you can see, you automatically have two configuration options:
      • Debug
      • Release
      Right click on the project in the Solution Explorer.
      Click on Properties.
      Click on Build tab.


      Under that tab you have many configuration options (which will be discussed in another post).
      The field we're interested in is "Conditional compilation symbols".

      While on Debug mode, we will write a variable name in this field.
      Example: "vDebug"
      After saving, you will have an identifier for when in Debug mode.

      Before testing our work, we're gonna create another Configuration.
      Click on the configuration drop down list and choose Configuration Manager


       Add new Configuration - TestRelease:

      Now place the variables in Release Configuration and in TestRelease Configuration.
      I've placed the variables: vRelease and vTestRelease

      Now for the test.
      Create a similar code on your Default.aspx.cs page:

      When you will run the code, you'll see that for each configuration option it will it the correct method.

      Hope it helped,
      Elad Shalom,
      CTO at ITweetLive.com

      Monday, January 10, 2011

      How To Write Good Code - Diagram

      How To Write Good Code Funny Stuff...



      source.

      Hope you're having a good time,
      Elad Shalom,
      CTO at ITweetLive.com

      IronRuby and Visual Studio 2010 - Integration

      IronRuby and Visual Studio 2010.

      The IronRuby represents another one of Microsoft's attempts to have it all under one development environment.
      • C / C++
      • VB.Net / C# / F#
      • J#
      • Their latest integration with jQuery
      • IronPhyton
      And now - IronRuby.

      This addition is brand new and a very cool one.  The add-on for Visual Studio 2010 is exactly for those who like Ruby and wish it to be implemented in their .Net environment when needed.

      This IronRuby release (1.1.1) with Visual Studio 2010 integration includes:

      1. Ruby colorized and syntax checker.
      2. Interactive loop window.
      3. Directory based projects.
      4. Templates for common Ruby applications (including Ruby on Rails 3, Sinatra, Gems and Silverlight based browser scripting app) 

       Source by Christopher Bennage.

      Thanks,
      Elad Shalom,
      CTO at ITweetLive.com

      Multiple Solutions with the Same Structure - Visual Studio 2010 How To

      Duplicating Solutions in Visual Studio 2010.

      As you probably know, I work in a company that provides sports betting solutions for many companies.  Each company has its own GUI and sometimes different flows inside the site.

      This is basically not hard to manage as long as you create a proper Skeleton Solution.

      A Skeleton Solution is a solution contains only the most relevant files and folders.  The same classes and JavaScript files that exist in every other solution.
      A Skeleton Solution will contain, in most of the times, several projects.

      I believe you've read my article about File Sharing in VS 2010.
      This article is in some way an extension of the one I just mentioned.

      How to Create a Skeleton Solution from an Existing Solution:
      It's even easier then you think.
      1. Create a folder named: "Base Solution" or "Skeleton Solution".
      2. Copy the content of your existing solution's folder.
      3. Paste the content inside your Skeleton Solution's folder.
      4. Change the names of:
        1. ".sln" file to "Skeleton.sln"
        2. ".vssscc" file to "Skeleton.vssscc"
        3. You can delete the ".sue" file.
      You now have a working copy solution of your existing one.
      Now you have to make it a truly Base Solution:
      1. From the Skeleton Solution, delete the files you intend to share.
      2. Now add them from your existing solution "as Linked Files".
      That's it.
      Your Skeleton Solution is ready. Every solution you will create from it will have the same files and projects is the Skeleton Solution.

      More over...
      The copied solutions will also have the same linked files as the Skeleton Solution in the exact same format.

      This method will save you lots of precious time and even more important - will save you potential errors.

      Thanks,
      Elad Shalom,
      CTO at ITweetLive.com

      Sunday, January 9, 2011

      Refactoring - Manage Your Code and Layers

      Refactory - Design Improvement of the Existing Code.

      When I say Code Management most people tell me "I know exactly what I wrote... I know exactly where everything lays".

      Well.. This sentence usually takes me back to when I was 6 or 7 years old.  My mother used to tell me to clean and organize my room  and that's exactly what I told her...:

      "But mom...  I love it when my soldiers are under the carpet, my school books are in the closet, my clothes are on my library and my shoes are where my action figures were.

      I'm pretty sure most of you are nodding and agreeing with me.
      But this is wrong.

      Back to development then...
      There are several file types that should be in a unique folder (for each) in every project:

         1. JavaScript
         2. HTML
         3. CSS

      JavaScript should not be inside "script" tag.
      CSS should not be inside "style" tag nor inside the element it's affecting.
      And HTML... Well... HTML should be on his own.

      Now I want to talk a little about Classes.
      In every language we write we should have different classes to achieve different functionality.

      One of the most important Classes out there is the DB Layer - Data Base Layer.
      Lets go over the basic terms:
      1. DBLayer - a class containing calls for the Views or Stored Procedures in the database.
      2. Stored Procedure - SP - a function inside the database which designed to insert / update / delete / select from a table or from a number of tables.  Stored Procedures can also return DataSet / DataTable / String / Int / DateTime according to specific parameters.   
      3. Views - A View is a static query designed to be activated without any major changes (a view won't usually accept parameters.  Store Procedure will).
      So, Back to the Management of the Code.

      The basic level is the GUI - Graphic User Interface - Meaning, what the user see and work with.
      The GUI is basically the HTML and CSS (in website development).

      After that, we have the Client side code - Scripts - JavaScript.
      The JavaScript should usually be the one (or plain HTML elements "OnClick" attributes) to activate the code behind functions.

      After a Client Side element calls a Server Side function - the function should preform it functionality.  Meaning, run through the code.
      In most of the cases, a large part of the functions involve calling the datalayer.

      The Data Layer Class (or as I call it "DBLayer") contains all the functions that should call the database.  Since we want a neat and tidy code, we wont write Select / Insert / Update / Delete / Drop inside the code.
      This is not meant only for a clean code, this code moderation is basically for security reasons.

      Example?
      Lets say you have several projects that use the same data base.  On one of these projects you have a friend working with.
      Giving him full access permissions to Drop and Truncate Tables is not the best idea.

      Eventually, the whole point of this post was to give a short explanation of how to correctly moderate your code.  How it should be designed.

      If your code isn't designed that way - That's the exact point of Refactoring..
      Changing the design of the existing code without altering it's functionality.

      Thanks,
      Elad Shalom,
      CTO at ITweetLive.com

      Thursday, January 6, 2011

      SEO One On One - Web of Links

      Creating Links, Connecting other sites to yours.

      The term Web of Links refers to creating multiple sites, each connected to the other one, in order to promote a specific website.

      This is exactly what a website owner would like, an hour work (and about 50$  investment) which will generate his website 25 links.

      Web of Links is mainly for indexing purposes and less for getting a higher page rank (PR) in search engines (Google).

      I'll start by explaining the benefits of the Web of Links method:
      Let's say you just created a website.

      You've made all the right things...
      Listed your site in all the indexes websites, registered to Google Analytics and Google Web Master Tool and even wrote some content pages in order to attract visitors.

      This is good, the only problem is that Google may have not indexed all you pages yet.  If you're a small new website, this process can take awhile.

      The Web of Links idea simply makes the linking process smoother.

      Enter a domain selling website (with free hosting) like GoDaddy.
      Buy a ".info" domain (costs 1.99$.  GoDaddy usually have bulk discounts).
      Create a simple HTML page.

      In this page you should right content which is related to your site.
      Place a link to your website under the desired phrase.

      After doing that, do the whole process again.
      This time, make sure you link to your main website and to a secondary website.

      Do that with 25 domains (as I said - 50$).
      Make sure not to have sites exchanging links with each other (Google will ignore this linking).

      People may tell you that this is black hat SEO...
      Well...  It's not!

      As long as you supply with rich, meaningful and unique content, Google doesn't care how you promote your website as long as it doesn't damage the user's surfing expirience.

      Now, all you have left to do is keep up the good work as Al Bundy said:
      "If you build it - They will come..."

      Thanks,
      Elad Shalom,
      CTO at ITweetLive.com

      Linked Files in Visual Studio 2010

      File Linking, File Sharing and Shared Projects.

      You know how it feels to have shared files on VSS?
      Gooood.
      Actually it felt so good that my beloved CTO (who said something about promotion?) switched to TFS just 4-5 months ago.  And ever since - I cry myself to sleep every night.

      Instead of one file, shared between 5,6,7 or 10 projects, we now have a copied file for each project.  This is due to Microsoft "Best Practice" which says - No Shared Files.

      Meaning...?
      If I have a JavaScript file called Arrays.js.  It's all purpose is to handle arrays in JavaScript.  This file exists in 6 different projects, which mean, that if I have another addition to this small JavaScript library, I have to copy it to 6 different files in 6 different projects...

      JUST SHOOT ME!!!

      Finally, I have the fix we've all been waiting for, courtesy of VS 2010:
      "Add File As Link"

      How to Link Files to Different Projects:
      Let’s say we have 2 completely different web sites.
      One is 10Bet and the other is SportsBettingTech.

      I will usually place the original file inside the main project, in this case - 10Bet. 
      I click on the project name ->     Add ->  New Item...

      A dialog box will open.

      I will choose a JavaScript file.  Just for testing.  We will call it:  "LinkedFile.js".
      I will place a small comment in this file, and Check In.


      Now I will go to my second project.
      Click on the project's name ->    Add -> Existing File...

      A dialog box will open.

      Go to the file you'd like to link to (hint: it's in a different project's folder) choose it, and instead of clicking the "Add" button click on that small arrow to the left.
      Choose "Add As Link".
      And you're done.


      How File Linking Works:
      The point of file linking is that you have one file.  This file physically exist in one place (the project it was created in) but has virtual copy of it wherever you want.
      If you choose to change this file from the mother project -> after you check in -> you will be able to see the changes wherever you linked it to.

      The Million Dollars Question:
      "What happens if I change the file from elsewhere?"
      That's a great question.
      And the answer is: With a very (very) simple solution.
      The original copy of the file is being checked out.  You will still be your secondary website's solution, but this file will automatically be checked out and displayed on your Visual Studio.
      After you change it, simply check in and that's it.

      Lots of luck and happiness and good night sleep,
      Elad Shalom,
      CTO at ITweetLive.com

      Monday, January 3, 2011

      First Steps In F Sharp

      F# - also known as F Sharp.

      As you know, there are some OOP languages out there. You probably know VB.Net, C# and Java but I'm about to talk about relatively new one.

      I would like to talk a little about F Sharp.

      Similar to C Sharp and VB.Net, F# is also targeting the .Net Framework and is also Object Oriented.
      The main difference in F# is not it's unique syntax but rather the new point of view and better state of mind it brings to the Object Oriented Programming.

      F Sharp uses "type inference" - meaning, the programmer doesn't need to keep his mind in the needed data type parameter and can just use the word "let" (similar to "var").
      The data type will be deduce by the compiler itself during compilation (F# also allows explicit data types declaration).

      After this short introduction to F# (very short) I would like to start the practical section.  and this post will be all about Lists in F Sharp.

      Let’s make a small experiment:
      Create a List of Ints in C#
      List<int> newList = new List<int>();

      Add the following values to this list:
      newList.Add(5);
      newList.Add(2);
      newList.Add(-3);
      newList.Add(1);

      Now please try to sort it using "Absolute Value".
      You'll probably find out that if you -did- manage to do this - you've used functionality programming.

      In F# it's almost the same and as easy as can be once you get the point:
      [5; 2; -3; 1] |> List.sortBy(fun intElem -> abs intElem)

      Let’s test our C# abilities again by mapping that List of ints (each number will be powered by 3)
      Again, most of you, who succeed used LINQ or other functional programming that C #allows, this is how it's don’t in F Sharp:
      [5; 2; -3; 1] |> List.map(fun x-> x * x * x)

      Another test for our C# (or Java) strength will be to try and filter that list for all ints that returns 0 when divided by 2.  In F Sharp it as easy as they come:
      [5; 2; -3; 1] |> List.filter(fun x -> x % 2 = 0)

      These were just couple of examples about F# and it's usability.  Hopefully it will help you understand the syntax and even more important - it will help you to think in functional programming.

      BTW
      How can we forget the immortal first program: "Hello World!" ?
      printfn "Hello World!"


      Good luck,
      Elad Shalom,
      CTO at ITweetLive.com

      Sunday, January 2, 2011

      String Manipulation - IsNullOrEmpty Method

      I guess we all need to check strings all around the code. And for that, we have about gazillion ways, and here are some -BAD- examples:
      1. if (ourString == null)
      2. if (ourString == "")
      3. if (ourString.trim() == "")
      4. if (ourString == string.empty)

      Luckily, Microsoft have came up with this great method "IsNullOrEmpty" which has something like this:

      return val == null || val == String.Empty;

      This is a great function thought it doesn't cover 100% of the cases.  Lets say, for example, that I have this string: "    ".

      Now, according to Microsoft the IsNullOrEmpty method will return false.
      Unfortunately, this is not a good result for us.

      In order to fix this in our projects, we added this small method:
      public static bool IsNullOrEmpty(this String val)
      {
          return val == null || val.trim() == String.Empty;
      }

      This will resolve our problem.
      So now we can use:
      bool b = String.IsNullOrEmpty("  ");
      And we will get true.

      .Net 4 Users:
      For you guys Microsoft fixed that thing in the form of
      bool b = string.IsNullOrWhiteSpace("   ");
      Which will return true.

      Good luck
      Elad Shalom,
      CTO at ITweetLive.com

      Get Query String

      There are enormous number of ways to get a specific key value that lays in the query string.

      JavaScript:
      function getQueryString(key, default_)
      {
          if (default_ == null) default_ = "";
          key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
          var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
          var qs = regex.exec(window.location.href);
          if (qs == null)
              return default_;
          else
              return qs[1];
      }

      This means the default value of this key (in case it does not exist) will be "en".
      var language = getQueryString("lng", "en");

      ASP.Net:
      string language = Page.Request.QueryString["lng"];

      PHP: 
      $var = "lng";
      $language = isset($_GET[$var]) ? $_GET[$var] : "en";

      Hope this was helpful and / or saved you some time,
      Elad Shalom,
      CTO at ITweetLive.com

      JSON Object Code Example

      The first example is to demonstrate the power and the accessibility JSON offers to developers.
      This is a JavaScript code designed to make things easier for the -new to JSON- developer:

          function User(fName, lName, age, friends)
          {
              var UserObject = {
                  FirstName: fName,
                  LastName: lName,
                  Age: age,
                  Friends: [],
                  IsUnderAge: function()
                  {
                      return this.Age > 21 ? true : false;
                  }
              };
             
              var FriendsCounter = 0;
              for (var frnd in friends)
              {
                  UserObject.Friends[FriendsCounter] = friends[frnd];
                  FriendsCounter++;
              }
             
              return UserObject;
          }

      This is the constructor.  Same as in every OOP language, each object needs to have constructors.

      Now, lets say I let a user named Igor fill an information form containing the following fields:
      1. First Name
      2. Last Name
      3. Age
      4. Friends - each friend will have the same fields.
      On the "Submit" button I have a call for a "CreateUser" function which will take the needed fields (using jQuery - but that's for another post) and send to the User constructor.

               function createUser()
              {
                  var IgorsFriends = [];
                  IgorsFriends[0] = new User("Uri", "GamingTech", 29, []);
                  IgorsFriends[1] = new User("Sergey", "
      GamingTech", 35, [
                      new User("Noam", "
      GamingTech", 27, [])
                  ]);
                 
                  var Igor = new User("Igor", "
      GamingTech", 33, IgorsFriends);
              }


      The outcome of this function will be a varaible named Igor which will have the following attributes:
      1. First Name
      2. Last Name
      3. Age
      The following methods:
      1. IsUnderAge
      And the following Arrays:
      1. Friends - which will contain list of friends as User objects. 

      Good luck,
      Elad Shalom,
      CTO at ITweetLive.com

      Quick JSON Tutorial

      JSON.

      In my first 2-3 year as developer I defined myself as a "Control Developer". The definition for Control Developer is a very simple one. 
      A developer who believes that anything and everything can be created using Ctrl + C and Ctrl + v (meaning copy and paste).

      This approach was working great as long as I didn't need to create brand new solutions for brand new features with brand new problems.

      As I was saying,
      About 15 months ago when I was working in my old company (FixYa) I was asked by my team leader to pass a JSON object to the server and to expect to get a different JSON object back.

      As a young proud developer the first thing I said was - “sure.  No problem".  And then the problem started.
      I couldn't find any good quick tutorial for JSON. What I needed was how to write a JSON object easily, not a full explanation of the JSON parser.

      Now, 15 months later I'm proud to present what I was looking for then - a very quick and usable tutorial for JSON:

      JSON - JavaScript Object Notation.

      The data types a JSON object can contain are:
      * Number.
      * String.
      * Boolean.
      * Array.
      * Another JSON Object.
      * Functions.
      * Null.

      Here I'm about to slowly fill a JSON object called: User.

      var User = {};

      This is the definition of User object.
      I can write also this:

      User.Age = 15;
      User.Name = "Igor";
      User.IsUnderAge = true;

      of course, a better way would be:
      var User = {
                      Age: 15,
                      Name: "Igor",
                      IsUnderAge: true
      };

      As I mentioned earlier, you can also insert arrays inside the JSON object:

      var User = {
                      Friends: [
                                      "Sergey",
                                      "Uri",
                                      "Noam"
                      ]
      };

      If you wanted to make things more complicated you would make each friend as a User object:

      var User = {
                      Name: "Igor",
                      Age: 15,
                      Friends: [
                                      {Name: "Sergey", Age: 15},
                                      {Name: "Uri", Age: 15},
                                      {Name: "Noam", Age: 15}
                      ],
                      IsUnderAge: function() {
                                      return this.Age > 21 ? true : false;
                      }
      };

      Now you have Igor as a very detailed and easy to read user object.


      In order to understand how to make "User" a generic system object, read "JSON Midsection".
      You  can also view my post called "JSON Object Code Example" for a clean code example.

      Good luck,
      Elad,
      Lead Developer at Sports Betting Tech.

      IE CSS Hacks

      Internet Explorer.

      It doesn't matter if it's IE 6, IE 7 or IE 8, they all suck.
      Even though IE 8 has made some progress concerning CSS issue, IE 7 and obviously IE 6 are the worst browsers.

      With CSS compatibility issues from here to Bill's office it takes too much work to make one CSS file fit all. That's why I thought of a small hack that I make in every HTML / XSLT / ASPX document I'm working with.

      at the body tag of each page I insert a small html if:

      <!--[if IE 6]>
      <body class="ie6">
      <![endif]-->

      <!--[if IE 7]>
      <body class="ie7">
      <![endif]-->

      <!--[if IE 8]>
      <body class="ie8">
      <![endif]-->

      After placing that, you can easily create inside your general CSS file an inherited styling such as:
      body
          { margin: 0 0 0 0; }
      body.ie6
          { margin: 0 5px 0 0; }
      body.ie7
          { margin: 0 0 5px 0; }
      body.ie8
          { margin: 0 0 0 5px; }


      This is the easiest way for me to work with IE 6 and IE 7 (and sometimes IE 8).  There is another way to make style compatible with IE browsers which involves creating different CSS file for every IE:


      <link rel="stylesheet" type="text/css" href="general.css" />

      <!--[if IE 6]>
          <link rel="stylesheet" type="text/css" href="generalIE6.css" />
      <![endif]-->

      <!--[if IE 7]>
          <link rel="stylesheet" type="text/css" href="generalIE7.css" />
      <![endif]-->

      <!--[if IE 8]>
          <link rel="stylesheet" type="text/css" href="generalIE8.css" />
      <![endif]-->


      Good luck, and hopefully we won’t need any CSS hacks for Internet Explorer 9,
      Elad Shalom,
      CTO at ITweetLive.com

      IE Blocking IFrame Cookies

      Microsoft.
      A company wishes to set development standards.
      A company you must know how to work with.
      A company we all hate to love.

      A little story, if I may.
      I work in a company that supply sports betting solutions for online gaming web sites.  About 2 months ago we got a new client with a slightly weird request - The solution should be placed in an existing site's IFrame.

      The minute I heard that request I thought to myself that the amount of problems we'll encounter will give us tremendous amount of work.  But as always - The client's always right.

      Three weeks ago we were almost ready for beta when our QA discovered some small issues regarding user preferences: Odds, Time Zone and Languages are not displayed correctly only on IE 7 and IE 8.

      After wishing some bad things to happen to Bill, my next action was to open the HttpWatch tool IE has and locating where the cookies are being set.  I saw that whenever the cookies are set as Session Cookie i all work as it should, the problem then lays with cookies that have expiration date.

      Since I was responsible for deploying 3 white labels (each project is called white label) this whole process took me about 2 weeks!

      So, after writing some angry emails to Microsoft (but not sending them) I started looking for someone's solution to that problem.  And that it was when I encountered a very small and cute article talking about P3P or as you might know it: "Platform for Privacy Preferences (P3P) Project".

      In short, unless you have some identifier in the page's header - IE wont except you third-party cookie.  So you need to set the P3P header in every page you wish the cookie to appear.

      I took the time to write the header addition in some languages / platforms:

      PHP:
         header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');

      ASP.Net:
         HttpContext.Current.Response.AddHeader("p3p","CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");

      Django:
         response = render_to_response('mytemplate.html')
          response["P3P"] = 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'

      JSP:
         response.addHeader("P3P","CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"")


      If you want to read more about these boring technical stuff (and I know you do) you can enter Platform for Privacy Preferences (P3P) Project.
      Good luck,
      Elad Shalom,
      CTO at ITweetLive.com