Monday, June 27, 2016

Zen Coding quick examples.

Ever heard of zen coding. This is very exciting. I had been living in the dark. I was working on visual studio 2015 and writing asp.net mvc web applications. I haven't heard of zen coding till recently and figured out it was awesome. For zen coding you need to have web essentials installed. Once you have the web essentials installed you can try few things out. Copy and paste these examples in your html file see the magic for yourself.


    div#mainDiv>div#innerDiv>ul#mainList>li#items>p#$*3>lorem10

    table#mainTable>tr.span4*3>td*3>p>lorem10

.messages>(.message.row>(.title.span10>lorem5)+(.date.span2{Feb 12 2015})+(.contents.span12>lorem)+(.toolbar.span12>button.btn.btn-primary.reply-button{reply})+.replies.span12)*5

(.col-md-4>.panel.panel-default.ui-ribbon-container>.ui-ribbon-wrapper>(.ui-ribbon{30% Off})+.panel-heading{Ribbon}+.panel-body>p>lorem10)*4

At the end of each line press a button and see the magic. If you play with it you will have lot of fun designing UI mocks. 

Thursday, June 23, 2016

Sum of number Recursively and Fibonacci numbers recursively.

When you attend interview, people would ask you to write a program in visual that would sum the numbers from 10 and ask you to write a program that prints fibonacci numbers. So I thought I should put up something that is easy dirty and quick.

Sum of numbers is just one line or recursive code and fibonacci is fairly simple. These both programs uses recursive calls to calculate the sum or print numbers.  In the next blog I am going to write about FizzBuzz, Sorting numbers and Singleton class.


using System;
using System.Runtime.Remoting.Messaging;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter a number");
            int inputVal = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(Sum(inputVal));

            Console.WriteLine("0");
            Console.WriteLine("1");
            PrintFibonacci(0, 1, inputVal);

            Console.ReadKey();

        }

        private static void PrintFibonacci(int first, int second, int inputVal)
        {
            if (inputVal < 3) return;
            int third = first + second;
            Console.WriteLine(third);
            PrintFibonacci(second,third,inputVal - 1);
        }


        static int Sum( int value)
        {
            return  (value == 0) ? 0 : value + Sum(value - 1);
        }
    }
}