Sunday 29 March 2015

Free .net cloud hosting for small applications

Few days back, I was searching for new upcoming technologies in .net on ASP.Net official website , I seen hosting suggestion there and when investigated all options, I found those really cool. Among all of those "GearHost" is best because it is giving unlimited sites and databases in its Free package. Detail can be found here: GearHost
Enjoy :)

How to be most productive developer

After a very long time just thought to spend some time on surfing internet on "Why best developers are best or seems to be best ". Eventually while searching, my mind was filled with some random questions and those are :

Relationship between effort/handwork and goal achievement
Relationship between more skillful and hardworking
Relationship between success and time spend
etc..]

While querying and making my perceptions and thoughts, I found a very nice collection of "
Top 10 Habits of Super Productive People " can be read right here : http://writing4success.com/blog/wp-content/uploads/2013/12/Top-10-Habits-of-Super-Productive-People_W4S.pdf .
I found it really cool , hope you will enjoy it too :)

Saturday 11 October 2014

How to possibly fix your Android apps refusing to sync or repeated security certificate errors

Recently I have faced an issue with my android device that all my apps ( https based ) were refusing to sync( like facebook, twiter, chrome etc ) and some were giving security certificate error ( like Email app ).
Actually it was due to the date-time settings of my android device. It was set to 2010 that's why all secured apps were giving errors.

 Quick fix is : just reset your date-time setting to current date and again launch your applications and enjoy :)

Thursday 21 August 2014

Back to Java classes , J2SE development , Environment setup with first HelloWorld example

Hi friends, today I am going to setup J2SE environment for java development to revise what I learned back from my BS degree.

  • To start first we need to install jdk to our system, download latest jdk from : http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html, I just downloaded windows x64 ( for windows 8 ).
  • After installation, need to add jdk's bin location to path Environment veritable. To do that right click "My Computer", then go to "Advance System Settings", click "Environment Variables", under System Variables grid, double click path record, as shown in figure :


and append the full path to the bin folder in jdk after installation at the end of path value separated by semi-colon and click OK.
  • To check everything working fine, just open command prompt and type and enter "javac", if you find screen as shown below, then everything working properly : 


  • Now to compile and run your first java program, open note pad, copy-paste following lines in it and save it as HelloWorld.java to some location in the drive.


public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello, World");
    }

}

  • Then go to location where you save above file in command prompt and then run following two commands one by one :
  1. javac HelloWorld.java
  2. java HelloWorld

  • After second command, you will see output like "Hello, World".
That't it, you are already a java developer now and have written and executed your first java program successfully.

Whats Next :

Will going to present different tutorials and links on J2SE developement soon, so stay tuned, keep codding and enjoy :)

Monday 18 August 2014

SQL Server 2008 R2 Profiler Tutorial

Hi guys, just revising my profiler skills , found a very nice article on "SQL Server 2008 R2 Profiler",



you can find it here : SQL Server 2008 R2 Profiler Tutorial, enjoy :)

Generate POCO Code First from existing database from in .NET ( Entity Framework 6 Tools for Visual Studio 2012 & 2013 )

Code First is best approach when starting your coding first and generate your database from your written code i.e. Plane Old CLR Objects ( POCO ) classes. But there might be a situation, when you want to use your existing database to develop your .net application using it, in that scenario one option is to use .edmx to generate your context and designer view but some people only used to work with pure poco's don't want to get into designer or database directly, so in that case we could visual studio extension/tool at

Entity Framework 6 Tools for Visual Studio 2012 & 2013 , just need to download .msi file and install it in your system.

After installation, to generate poco's from your existing database do following easy steps :

1 ) Right click to your project/project's folder and click add new item 

 2 ) Then select ADO.NET Entity Data Model and click Add


3 ) Where you can see new Model Content type i.e. Code First From Database, select it and click next


4 ) Establish connection with your database


5) Do next , select the tables you want to enter and click finish and finally you will see following kind of result, where Address and User are POCOs from database and Model1.cs is context class.


That's how you can create pure POCOs and context from existing database and use it in code first fashion, so enjoy :)

Saturday 16 August 2014

PTCL EVO 3g issue , modem is already in use or not configured properly

Today I faced very annoying issue with PTCL EVO 3g, that is when I connected evo to may laptop ( with OS Windows 8 pro ) first time it configured well and was started working fine but when second time I plug-in the device it starting giving me error " Error:633 modem is already in use or not configured properly " , even I have uninstalled the driver and evo 3g software but still issue was giving me headache, after hours of brain burning I finally got succeed to configure it again to work properly.


Following are steps which needs to follow :


  • First go to Control Panel , then open Device Manager
  • Double click Modems and double click evo USB Modem
  • This will open a new tabbed window, then go to Advanced tab
  • On that tab click Advanced Port Settings and change the COM Port Number to COM1 or COM3 provided that which one is free.

Then restart your system and you have done it.

Friday 15 August 2014

PetaPoco .Net light weight ORM

Last night I was having discussion on Asp.net MVC4 with my friend from Morocco who is new in Asp.net MVC and I got introduced with PetaPoco ( i.e. ORM kind of thing for .net ), my friend was using PetaPoco to map database entities to models. Later on I got little R&D on it and found it amazing as this is just a single file with 1500 lines of code and giving us following top features we usually used to be interested in :

  • Tiny, no dependencies... a single C# file you can easily add to any project.
  • Works with strictly undecorated POCOs, or attributed almost-POCOs.
  • Helper methods for Insert/Delete/Update/Save and IsNew
  • Paged requests automatically work out total record count and fetch a specific page.
  • Easy transaction support.
  • Better parameter replacement support, including grabbing named parameters from object properties.
  • Great performance by eliminating Linq and fast property assignment with DynamicMethod generation.
  • Includes T4 templates to automatically generate POCO classes for you.
  • The query language is SQL... no weird fluent or Linq syntaxes (yes, matter of opinion)
  • Includes a low friction SQL builder class that makes writing inline SQLmucheasier.
  • Hooks for logging exceptions, installing value converters and mapping columns to properties without attributes.
  • Works with SQL Server, SQL Server CE, MySQL, PostgreSQL and Oracle.
  • Works under .NET 3.5 or Mono 2.6 and later.
  • Experimental support for dynamic under .NET 4.0 and Mono 2.8
  • NUnit unit tests.
  • OpenSource (Apache License)
  • All of this in about 1,500 lines of code



PetaPoco can be downloaded from following sources :

  • NuGet -http://nuget.org/List/Packages/PetaPoco
  • GitHub -https://github.com/toptensoftware/petapoco

More detail's can be found on their official site : http://www.toptensoftware.com/

Whats next :
Console based .Net project with basic crud operation using PetaPoco.

Till then stay tuned and enjoy codding :)




Monday 11 August 2014

MongoDB Setup ( installation ) and access through command line too and GUI based client

One of the most commonly used Non-Sql database these days is MongoDB. Last week I had a chance to try on it and have found it so easy to make it setup in the system. It is just a three step process to follow and make it working and play with it :

1) First download latest MongoDB zip file from here ( MongoDB ) and extract its contents at C:\Program Files\MongoDB.

2) Create new directory at C:\data\db , which is default directory for MongoDB to store its database files.

3) Now double click mongod.exe from C:\Program Files\MongoDB\bin location, and MongoDB server will be started to listen as shown in figure :


And that's it, you have successfully setup the MongoDB on your system, you can now perform operations in two ways :

1) Through Command Line tool : for command line tool go to C:\Program Files\MongoDB\bin and double click mongo.exe and start executing your commands there. For commands you can follow MongoDB's official documentation at : http://docs.mongodb.org/manual/reference/command/, to start as basic from command line you can perform CRUD operations by following steps here : http://www.mkyong.com/mongodb/how-to-create-database-or-collection-in-mongodb/


2) Using UI Client for MongoDB : you can use any freeware UI client available for MongoDB, I will prefer Robomongo, its free and extensive, you can download its free copy from : http://robomongo.org/, and here is my post about it : http://usmansidea.blogspot.com/2014/08/robomongo-asesome-mongodb-ui-client-to.html. After installation just run it for the first time and give connection name and don't change any default settings and click save.

That's all about how to setup MongoDB and how to play with it, so lets enjoy :)

What's Next : I am currently working on C# sample project to access MongoDB in both simple way and through repository pattern, will create next post on it, till then stay tuned and happy codding :)

Sunday 10 August 2014

Wamp, change Apache server to run to other port instead of default

Some times port 80 is already occupied by IIS or any other program. In that case you can simple update port no. to run Apache server on, to do this :

Click Wamp server icon
Wamp Server
 in your system tray, go to apache-> httpd.confg , edit this file and place port no. in these lines by finding in file i.e.
#Listen 12.34.56.78:80
Listen 0.0.0.0:80
Listen [::0]:80
e.g. we can change port 80 to 8080 as :
#Listen 12.34.56.78:8080
Listen 0.0.0.0:8080
Listen [::0]:8080


enjoy :)

Wednesday 6 August 2014

Robomongo, asesome mongodb UI client to play with mongodb server

Last week I played with mongo db a bit, its installation/configuration on Windows and how to manipulate mongodb server using cammond line, mean while I have found asesome tool for mongodb to have UI based interation with mongo server.

Latest copy can be download from : http://robomongo.org/, just try it, its fun :)

Saturday 19 July 2014

Sql Server Compact 4.0 database management

You can download Visual studio extension to manage Sql Server Compact 4.0 databases from visual studio from here :
http://visualstudiogallery.msdn.microsoft.com/0e313dfd-be80-4afb-b5e9-6e74d369f7a1/

If you want standalone Sql Server Compact 4.0 database management, you can download from here (SQL Server Compact/SQLite Toolbox):
http://sqlcetoolbox.codeplex.com/

Wednesday 5 March 2014

Tortoise Hg alternative for Mac is SourceTree

Hi all , normally on windows I am always used to play with Tortoise Hg for managing my repositories , but some how it is quite difficult to establish Tortoise Hg environment on Mac , so I have found an easy alternative and that is SourceTree for Mac , and what it says is

"A free Git & Mercurial client for Windows or Mac" .

Saturday 1 March 2014

Get started with IOS development

Hi all, this post will only contain the useful links which I will gather throughout from my R&D and learning :

  • http://www.hongkiat.com/blog/ios-development-guide-part1/

Saturday 16 November 2013

WPF ( Windows Presentation Foundation ) an introduction

.Net framework which is Microsoft's next generation UI framework for creating applications with rich user experience. It is part of .Net from 3.0. WPF is famous because of UI's, 2D graphics , 3D graphics , documents and multimedia usage , makes UI faster , scalable and resolution independent. It loosely couples the implementation ( behavior ) from appearance ( UI ) using XML based graphic designing tool. 

So its key characteristics are :
  • Separation of appearance and behavior 
  • Rich composition ( through xaml based UI )
  • Highly customize-able
  • Resolution independence



WCF ( windows communication foundation) an introduction, characteristics , why should we use this Framework

WCF is .net framework ships with .net  for building service oriented applications , used to send data asynchronously from one service end point to another. Service endpoint may be an independent service available all the time or a part of another application ( hosted in it ). The data which it sends could be a text, xml or complex such as binary stream etc.We can use WCF for real time data exchange, polling , business transactions etc.

Some key characteristics of WCF are :

  • Service Orientation
  • Interoperability
  • Multiple Message Patterns
  • Service Metadata
  • Data Contracts
  • Security
  • Multiple Transports and Encodings
  • Reliable and Queued Messages
  • Durable Messages
  • Transactions
  • Ajax and Rest Support
  • Extensibility

Why to use WCF instead of conventional Web Services:


WCF ServiceWeb Service
-> Communication can happen over HTTP,TCP, IPC or even MSMQ.
-> It can be configured to have simplex,request-response or even full duplex communication.
-> Can be hosted inside web server or event self hosted.
-> Communication can happen over HTTP only.
-> Only simplex and request-response    communication is possible.
-> Work in stateless fashion over HTTP and hosted inside a web server.

That was very simple introduction to WCF , stay tuned :)

Monday 11 November 2013

BDD (behavior driven development) implementation .net

After my first post on "What is behavior driven development" this is an extension to this post as implementation and practical of BDD. We are going to use following libraries/frameworks in this tutorial :

  • SpecFlow : BDD library/framework , works on Given, When and Then keywords where Given relates to preconditions, when represents occurrence of an event and Then is testable outcome. Provides facility to write testing scenarios in human language ( DSL , domain specific language ).
  • Resharper : To run unit tests.
  • NUnit : Unit testing framework
  • Coypu:  Provides fast browsing of web applications to access elements i.e. buttons, links , fields and etc on a web page.This is irrelevant from above exercise( just in-case you are interested in UI testing).

To start practicing you first need to download/install following :
  • Install specflow ide integration from their official website :  http://www.specflow.org/getting-started/
  • Install library package for specflow from nuget ( open package manager console and run  "Install-Package SpecFlow" command  from your visual studio i.e. Tools-->Library Package Manager-->Package Manager Console ) 
  • Same as above run these commands "Install-Package NUnit","Install-Package Coypu" for installation of NUnit and Coypu libraries respectively.
And that it , you are ready to go.

Now when you are going to add new file into your project , you will see three more file extensions in add new file popup window as shown in following figure:




Now start with adding Specflow feature file , this will contain following default data in it :

Feature: SpecFlowFeature1
    In order to avoid silly mistakes
    As a math idiot
    I want to be told the sum of two numbers

@mytag
Scenario: Add two numbers
    Given I have entered 50 into the calculator
    And I have entered 70 into the calculator
    When I press add
    Then the result should be 120 on the screen
Where "@mytag" is used for scope i.e. in step definition file we can specify the scope of definition by declaring [Scope(Tag = "mytag")] on top of the class.

By default the color of Given,when and then statements will be pink and that means there is not binding yet for these steps as shown in figure below :


now right click inside this view and select Generate step definition as shown in figure :

This will generate steps definition file for your scenrio , now you can use tag above your class binding like this :
  [Scope(Tag = "mytag")]
    [Binding]
    public class FirstSecenrio
    {
Now you are ready to run your tests , open re sharper test window and start running your tests.
To work with coypu , you must configure your browser settings in BeforeTestRun method of your binding class and start accessing your webpage controls, see https://github.com/featurist/coypu-jvm page for this.
Your binding class after coypu browser settings will look like this :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Coypu;
using Coypu.Drivers;
using Coypu.Drivers.Selenium;
using NUnit.Framework;
using TechTalk.SpecFlow;

namespace SpecflowCypu.Tests.StepsDefinitions
{
    [Scope(Tag = "mytag")]
    [Binding]
    public class FirstSecenrio
    {
        private static BrowserSession browser;
        [Test]
        [BeforeTestRun]
        public static void BeforeTestRun()
        {
            
            SessionConfiguration sessionConfiguration = new SessionConfiguration();
            sessionConfiguration.AppHost = "localhost";
            sessionConfiguration.Port = 5555;
            sessionConfiguration.SSL = false;
            sessionConfiguration.Browser = Browser.Firefox;
            browser = new BrowserSession();
        }


        [Test]
        [AfterScenario]
        public static void AfterScenario()
        {
         
        }

        [Test]
        [Given(@"I have entered 50 into the calculator")]
        public void GivenIHaveEntered50IntoTheCalculator()
        {
            browser.Visit("https://gmail.com");
            // ScenarioContext.Current.Pending();
        }

        [Test]
        [Given(@"I have entered 70 into the calculator")]
        public void GivenIHaveEntered70IntoTheCalculator()
        {
            //ScenarioContext.Current.Pending();
        }

        [Test]
        [When(@"I press add")]
        public void WhenIPressAdd()
        {
            //ScenarioContext.Current.Pending();
        }

        [Test]
        [Then(@"the result should be 120 on the screen")]
        public void ThenTheResultShouldBe120OnTheScreen()
        {
            //ScenarioContext.Current.Pending();
        }
    }
}

That was very short and to the point tutorial on BDD using specflow , will explain more very soon.




Saturday 9 November 2013

XML Serialization in c#

According to MSDN definition "Serialization is the process of converting an object into a stream of bytes in order to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization".

After serialization data can be stored into a file,database,memory etc. This is simple three step process:

First step is to create a class which's object you want to serialize into xml file i.e.

public class Movie
    {
        // Default ctor
        public Movie()
        { 

        }
        [XmlAttribute(AttributeName="MovieTitle")]  // stores element in xml file with this name
        public string Title
        {
            get;
            set;
        }
        public string Director
        {
            get;
            set;
        }
        [XmlElement(ElementName ="ReleaseDate")]
        public DateTime Year
        {
            get;
            set;
        }
        public double Budget
        {
            get;
            set;
        }
    }
Where  [XmlElement(ElementName ="ReleaseDate")] is used to change the name of the property on run time and save this property in xml file with new name.

Second step is to write a function which will be used to serialize above class's object into xml. i.e.

 private static void SerializeMovieXML(List<Movie> movies)
        {
            // Step 1
            XmlSerializer serializer = new XmlSerializer(typeof (List<Movie>));
            // Step 2
            TextWriter txtWriter = new StreamWriter(@"D:\Movies.xml");
            // Step 3
            serializer.Serialize(txtWriter, movies);
            // step 4
            txtWriter.Close();
        }
This function store Movies.xml file in D drive , you can change this location.

Third step is to create object of movie class and use above method to create xml.

 Movie m = new Movie();

            m.Title = "BOL";
            m.Director = "Shoiab Mansoor";
            m.Year = new DateTime(2011, 09, 05);
            m.Budget = 10000000;


            Movie m1 = new Movie();

            m1.Title = "Forrest Gump";
            m1.Director = "I Dont Know";
            m1.Year = new DateTime(1990, 09, 05);
            m1.Budget = 50000000;

            List<Movie> movie = new List<Movie>();

            movie.Add(m);
            movie.Add(m1);



            SerializeMovieXML(movie);

In result of above code , this xml will be produce in Movies.xml file.

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfMovie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Movie MovieTitle="BOL">
    <Director>Shoiab Mansoor</Director>
    <ReleaseDate>2011-09-05T00:00:00</ReleaseDate>
    <Budget>10000000</Budget>
  </Movie>
  <Movie MovieTitle="Forrest Gump">
    <Director>I Dont Know</Director>
    <ReleaseDate>1990-09-05T00:00:00</ReleaseDate>
    <Budget>50000000</Budget>
  </Movie>
</ArrayOfMovie>

Now if you want to de-serialize above xml into object , following method will be used :
   private static List<Movie> DeserializeMovieXML()
        {
            // step 1
            XmlSerializer serializer = new XmlSerializer(typeof (List<Movie>));
            // step 2
            TextReader txtReader = new StreamReader(@"D:\Movies.xml");
            // step 3

            List<Movie> m = serializer.Deserialize(txtReader) as List<Movie>;

            txtReader.Close();

            return m;
        }
and you can use this method in this way to get your object back :

            List<Movie> movies = DeserializeMovieXML();
That's it, do code and enjoy :)

My Syntax Highlighter V1.0.0 , beautify your source code on html page

I got some free time during holidays , so I decide to write my own syntax highlighter to beautify my code on html pages, its first version is done and pushed on my github account right here :
https://github.com/Usman-uzi/UCodeHighlighter.


To use this you must follow following four steps :

1) First include scripts and style sheet in header of your page :

<head>
<title>jQuery plugin: code highlighting demonstration</title>
<script src="published/jquery-1.6.3.min.js"></script>
<!--<script src="published/UCodeHighlightner.js"></script>
<script src="script/uhighlight.js"></script>
<link href="published/hilightstyle.css" type="text/css" media="screen" rel="stylesheet">-->
<script src="http://www.usmanbackup.somee.com/script/UCodeHighlightner.js"></script>
<link href="http://www.usmanbackup.somee.com/script/hilightstyle.css" type="text/css" media="screen" rel="stylesheet">

</head>

2) Second step is , place you code in a <div > with display none , i.e.

<div id="data" style="display:none;" >

your code here........

</div>

3) Third step must be , use following chunck of code on your page:

<div>
<div id="line_number" class="counting_div_wrap"></div>
<div id="main" class="main"></div>
<div style="clear:both;"></div>
</div>


4) The last step is to use js to process your code i.e.

<script type="text/javascript">
// script for on page code processing
$("#main").highlight($("#data").html(),$("#line_number"));
</script>


That's all , you are done :)

Friday 1 November 2013

DataGridView , show custiom column and row headers , win forms .net

Recently one of my friend requested to show how to use custom header for columns for DataGridVew in WinForms , I worked on that and not only customize column headers but also row headers. Let's start this , first step is we required a model to show data into grid ( what are the fields in our collection or in database).
Our model :


    class CustomModel
    {
        public string Title {  get;set; }
        public string Detail  { get;set;  }
    }

These are two fields we want to show in gridview.

Now second step is to create a collection to bind to our gridview, and here is the all remaning code ,put it into your Form1_Load method like this :

   private void Form1_Load(object sender, EventArgs e)
        {
            List<CustomModel> dataList=new List<CustomModel>();

            dataList.Add(new CustomModel(){Title = "title1", Detail = "detail1"});
            dataList.Add(new CustomModel(){Title = "title2", Detail = "detail2"});

            dataGridView1.Columns.Clear();
            DataGridViewTextBoxColumn title = new DataGridViewTextBoxColumn();
            title.DataPropertyName = "Title";
            title.HeaderText = "Title";      
            dataGridView1.Columns.Add(title);

            DataGridViewTextBoxColumn description = new DataGridViewTextBoxColumn();
            description.DataPropertyName = "Detail";
            description.HeaderText = "Detail";  
            dataGridView1.Columns.Add(description);
         
            dataGridView1.DataSource = dataList;

            /* Create the row headers */
            int rowNumber = 1;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                row.HeaderCell.Value = "R" + rowNumber;
                rowNumber++;
            }

            // set rows headers width according to its text
            dataGridView1.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
            dataGridView1.Show();
        }





And that's simply it , enjoy :)