Monday 28 October 2013

Scroll whole page , Ext js

Hi , during practicing I got very short code to make your page ( body ) scroll to some location , we have following options for this :

var body=Ext.getBody().el;

var el=Ext.getBody().el;
el.scrollBy(10, 10, true);
el.scrollBy([10, 10], true);
el.scrollBy({ x: 10, y: 10 }, true);
or you can use:
el.side, value, [animate] ) ; where side may be left or top , value is integer and true or false for animate or not.
And that's simply it :)

Sunday 27 October 2013

Article CMS started in php

Hi guys, I have started Articles CMS system and decided to  make my hands dirty with php codding too , and created public repository on github at : https://github.com/Usman-uzi/ArticlesCMS 
 I have stared with some initial work on database read and login authentication (basic one ) , you can also participate in it :)

Bitknex , All in one FTP/SFTP/HTTP/WebDAV client

During searching for moving files and directories from workspace to the wamp server www directory , I found very niece tool BitKnex (http://www.bitkinex.com/) , which is "All-in-one FTP/SFTP/HTTP/WebDAV Client" , so from now move your code to any online url or on the network or only between your system folders.



Eclipse and php tools setup for php development

Hi all , in this post I will show you how to use eclipse for php development. First you need to download eclipse for php i.e go to : http://www.eclipse.org/downloads/packages/eclipse-php-developers/heliosr , select you favorite package ( may skip ) and download IDE according to your OS requirement, as shown in screen shot below :


That's it :)

Wamp doesn't start all services , php

Hi all , recently I have encountered a problem that I tries to start wamp server for php development but it doesn't started all of its services , when I inquired problem I got to know that there is a "Web deployment agent service " , started at windows start , which works for asp.net applications to deploy them on local server when we start our asp.net application form visual studio , actually it uses port 80 by default , and wamp also uses port 80 to start working , so every time when wamp was started , it founds port 80 busy, so simple solution is we have to configure one of them to another port so that port clashes doesn't happens.
What I do for simple solution is that , when I do need to work with wamp , I just simply stop "web deployment agent  service service" and when I finished I started that again.
It is very simple one step process.Go to start , search for services :


Then select web deployment agent  service and stop it :


And that's it, enjoy php :)

Saturday 26 October 2013

Populate DropDownList control with enum , asp.net

DropDownList can also be populated with enum i.e

  protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //Assigning values to dropdown form enum as news types
                var hash = Helper.GetEnumForBind(typeof(NewsType));
                hash.Add("0", "--Select Type--");
                NewsType.DataSource = hash;
                NewsType.DataTextField = "value";
                NewsType.DataValueField = "key";
                NewsType.DataBind();
            }
        }

Where NewsType is enum , lets say like this :
 
 public enum NewsType
    {
        Sports=1,
        Business,
        Political,
    };

And GetEnumForBind function converts enum to hashtable which can be bound to DropDownList,

 public static Hashtable GetEnumForBind(Type enumeration)
        {
            string[] names = Enum.GetNames(enumeration);
            Array values = Enum.GetValues(enumeration);
            Hashtable ht = new Hashtable();
            for (int i = 0; i < names.Length; i++)
            {
                ht.Add(Convert.ToInt32(values.GetValue(i)).ToString(), names[i]);
            }
            return ht;
        }

and finally our dropdownlist is :

    <asp:DropDownList runat="server" ID="NewsType"  AutoPostBack="True" onselectedindexchanged="NewsType_SelectedIndexChanged"> </asp:DropDownList>

and that's all what we need :)


Asp.net dropdown list populated with data from .xml file

In asp.net we have <asp:DropDownList> control , to populate this control with data from .xml file , you need to do straight and simple three steps.

Step#1 : Create xml file in your project , lets say we have data of countries i.e

<?xml version="1.0" encoding="utf-8" ?>
<Countries>
  <Country>
    <Id>1</Id>
    <Name>India</Name>
  </Country>
  <Country>
    <Id>2</Id>
    <Name>USA</Name>
  </Country>
    <Country>
      <Id>3</Id>
      <Name>Japan</Name>
    </Country>
    <Country>
      <Id>4</Id>
      <Name>Australia</Name>
    </Country>
    <Country>
      <Id>5</Id>
      <Name>England</Name>
    </Country>
    <Country>
      <Id>6</Id>
      <Name>UAE</Name>
    </Country>
    <Country>
      <Id>7</Id>
      <Name>China</Name>
    </Country>
  </Countries>

Copy paste this data as it is in your Countries.xml file.

Step#2 : Now you must have DropDownList control on your page .Put following code inside your .aspx page. 


        <asp:DropDownList ID="ddlCountries" runat="server" AutoPostBack="True" Width="183px">  
        </asp:DropDownList>

Step#3 : Now go to your code behind file and define following function there :

  public void BindDropDownListFromXml()
        {
            DataSet ds = new DataSet();
            try
            {
                //Reading the data from the XML file
                ds.ReadXml(MapPath("~/Countries.xml"));
                DataView dv = ds.Tables[0].DefaultView;
                //Sort the DataView by "Name"
                dv.Sort = "Name";
                //Setting DataText field and DataValue field of DropDownList
                ddlCountries.DataTextField = "Name";
                ddlCountries.DataValueField = "ID";
                //Binding the DropDownList with the  DataView
                ddlCountries.DataSource = dv;
                ddlCountries.DataBind();
                ddlCountries.Items.Insert(0, new ListItem("-- Select --", "0"));
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message.ToString());
            }
        }

And after this , call this function inside your Page_Load function like this :

  protected void Page_Load(object sender, EventArgs e)
        {
            //this will run on page load
            if (!Page.IsPostBack)
            {
                BindDropDownListFromXml();
            }  
        }

And that's it :)

Saturday 19 October 2013

Replace a single character or string or multiple occurrence of a character or string in a string , JQuery

Recently I was working on my own Syntax Highlighter plugin for JQuery ( UCodeHighlighter github ) , I go through from good experience to play with strings , its characters and sub-strings.To demonstrate the string manipulations lets say we have a string :

var text='I am a programmer , I love my field and I love codding'; 

I have face following cases while working :

  • Replace a single occurrence of a string in a string :                                                                                 text= text.replace("love","very love"); // this will replace only first 'love' in above string with 'very love'
  • Replace multiple occurrence of a string in a string                                                      text= text.replace("/love/g","very love"); // this will replace both' love' in above string with 'very love'
  • Replace multiple occurrence of a dynamic string in a string                                                              var keyword='love';                                                                                                                            text= text.replace(new RegExp(keyword, 'g'),"very love"); // this will replace both' love' in above string with 'very love'
  • Replace multiple occurrence of a character in a string :                                                                                 text= text.replace(/a/g,"e"); // this will replace all 'a' characters in above string with 'e'
  • And same are the other cases for characters manipulation as strings described above.
And that's it , I hope this will help while doing your scripting :)

Thursday 17 October 2013

Getting stated Android , development environment setup

Welcome to android development series , this time I am going to describe that how to setup your development environment for android apps development.This is simple two step process.

  1. First step is installing java JDK from their official website i.e (http://www.oracle.com/technetwork/java/javase/downloads/index.html).
  2. Second step is to download Android ADT bundle ( sdk for android ) from this link : http://developer.android.com/sdk/index.html , and it has every thing you need to develop an android application , it has three folders, one is for eclipse containing IDE , second one is SDK and third one is SDK manager app, to start doing android , you just need to start eclipse and that's it.

Android handle onClick event ( two ways )

I recently have started to practice pure android apps , and now I am going to show how to register onclick events of controls in two ways. First way is our old java way , to associate separate onclick listener to each control like this :

  btn_1.setOnClickListener(new OnClickListener()
        {
            public void onClick(View v)
            {
            input_screen.append("0");
            }
        });

which is good but not best way.

Second way is to define your onClick method in the current context ( class ) and while handling the onClick events just give "this" ( context ) to the setOnClickListener method of controls and apply cases inside your onClick method, like given below :

btn_num_0.setOnClickListener(this);
btn_num_1.setOnClickListener(this);

public void onClick(View v) {
      // TODO Auto-generated method stub
      final int id = v.getId();
       switch (id) {
       case R.id.btn_num_0:
            // your logic here
           break;
       case R.id.btn_num_1:
           // your logic here
           break;
       // even more buttons here
       }
    }

So these are the two ways for registering events for controls.

Sunday 13 October 2013

Resharper, an awesome tool for visual studio

Recently I get experienced to use "Resharper" , which I found amazing , it actually provides codding assistance for developer to code in much efficient and fast way, it is known for :


You can get complete feature details of it from site link given above :)

Convert visual studio 2012 project to visual studio 2010

To convert visual studio 2012 project to visual studio 2010 you have to do only two changes in two files.Fist change you have to do in your .solution file , for this you have to open your project solution file into text editor and do following changes :


  • Change "Microsoft Visual Studio Solution File, Format Version 12.00" to "Microsoft Visual Studio Solution File, Format Version 11.00"
  • and "# Visual Studio 2012" to " # Visual Studio 2010"

and now right click your project file and open it in text editor and change :
  • <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> to "<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>"
And you are done , now open your project in visual studio 2010 and start codding :)

Saturday 5 October 2013

What is "Code Re-factoring" ?

Recently I go through the process of code re-factoring, before going into detail lets have definition of re-factoring, i.e. "It is process of code restructuring without changing its behavior", first question that may arises is that why we need to restructure our code and this will not going to effect the behavior of our system and the answer will be the detail of re-factoring, now lets assume one developer work one module of the system and other work on another and both developers merge their code, so during these steps developers wrote their code consists of classes containing methods and in methods there may be instantiation of objects, so as the other developers do.
1- After merging first scenario (very common one ) can occur i.e. same general chucks of code for doing       identical work but consists of different method names.
2-Un-necessary creation of methods ( call only from one place)
3-Un-necessary creation of variables ( usually we do for debugging purposes)
4-Extra long methods ( un-necessary logic)

You can find different possible combinations from above points after reviewing your code and when you will remove things like these then this process will be called "Code Re-factoring".