Tuesday, December 6, 2011

MVC2 with Entity Framework–Database first method

Here I want to create a simple MVC website to store and view details of vehicles(Cars). Define the Work Flow as bellow.

1. Create a Database and a data Table to store information.

I have created a simple Cars table. [Usually table names are in plural, because it used singular form for the class name when Entity Framework automatically generates classes from the database ]

image

2. Visual Studio, create empty MVC 2 web application.

imageimage

it generates a MVC template with View, Controller and Model

View – have all the UI views of the application. We normally don’t use visual studio supported server controls (buttons, lists etc..) to build the UI. so we use normal html controls to build up our UI.

[If you don’t like html, don’t worry there are some html Helper classes and with Razor, you can build a nice UI] , there are also some 3rd party UI tools.

image

Controllers – In this MVC model our URL request firstly hit to the Controller class the it starts  communicate with view and model, and it has some URL routing mechanism. When we create a controller class, it names as “SOMENAMEController”, so then the accessing URL is like “http://localhost/SOMENAME”.

image

Controller class has methods. so we can invoke those methods by using “http://localhost/SOMENAME/methodname”. so this is the default URL routing mechanism, we can modify as we want.

image

Model – Where our business rules and db access layer is located. using Entity Framework we can obtain our data model very easily. [Here I use EFramework 4.1]

we can load our required data tables in to the model. We can apply inheritance rules can abstract rules for the classes. you can see our “Cars” Table –> Car Object.

image

select DbContextGenerator, if there is not available you can check @ online template section, download it, and use it.

image

then it automatically generates us some classes.

image

image

this is our Car Class, it has only properties and get,sets. I additionally use some validation rules.

Special thing is that you can see all the Generates  classes and methods are “Partial”. so I think I don’t want to save what are the possibilities that “Partial” gives us.

3. Create Controller methods and Views

image

MVC template supports us to generate some Views for simple CRUD operations. the above image shows you, when you add a View to a particular action, it gives us a option window to chose the  type of the View to be generated.

image

sample Action methods in the Controller Class.

Monday, August 1, 2011

What is the difference between g++ and gcc compilers

  • Why use g++ instead of gcc?
  • Why some codes compile with g++ but not in gcc?
  • How do we know what compiler works fine with our code?

  1. Background of gcc and g++ compilers

gcc / g++ is just a front-end driver programs which invokes the actual compiler and / or linker based on the options given to it.

If you invoke the compiler as gcc:

  • it will compile as C or C++ based on the file extension (.c, or .cc / .cpp);
  • it will link as C, i.e. it will not pull in C++ libraries unless you specifically add additional arguments to do so.

If you invoke the compiler as g++:

  • it will compile as C++ regardless of whether or not the file extension is .c or .cc / .cpp;
  • it will link as C++, i.e. automatically pull in the standard C++ libraries.

 

2. Examples you may face the difference between g++ and gcc

image

$ gcc -o test test.c

$ g++ -o test test.c

This will compile with gcc, but not with g++ and give some errors. C++ requires an explicit cast from void* here, whereas C does not.

image

This will give errors when compile using gcc. (because of ‘int array’ – it is not recognized in c linking stage)

we can prove it by compiling using gcc and then linking with g++

$ gcc –c test.c

$ g++ –o test test.o

$ ./test

  • Where as g++ not compile .c ass plain C, it always compiles as c++.
  • g++ automatically links the C++ runtime library where gcc doesn't.

Wednesday, July 20, 2011

Unstructured, Procedural, Modular Programming

1. Unstructured Programming

They are simple programs consists only one main program. “Main Program” stands for a sequence of commands or statements which modify data which is global throughout the whole program.

image

2. Procedural Programming

With procedural programming you are able to combine returning sequences of statements into one single place.Procedure call is used to invoke the procedure. After the sequence is processed, flow of control proceeds right after the position where the call was made.

image

Now a program can be viewed as a sequence of procedure calls. The main program is responsible to pass data to the individual calls, the data is processed by the procedures and, once the program has finished, the resulting data is presented. Thus, the flow of data can be illustrated as a hierarchical graph, a tree, as shown bellow.

image

Now we have a single program which is divided into small pieces called procedures.

3. Modular Programming

With modular programming procedures of a common functionality are grouped together into separate modules.

image

Sunday, July 17, 2011

Quick Guide to Regular Expressions

Introducing Regular Expressions – Fastest learning Method

Regular Expressions (or regex) are string patterns which used for text processing. ASP, .NET, C#, Java and many other languages support RegEx. Simply it contains string text and special instructions-statements.
RegEx is a minilanguage that has a special syntax and instructions that you must learn and I like to discuss them step by step.
It is important to note that syntax is the easiest part of mastering regular expressions. The real challenge, however, is learning how to apply that syntax, how to dissect problems into solvable regex solutions. That is something that cannot be taught by simply following exercises, but like any language, mastery comes with practice.


RegEx Lesson 1 – Matching Characters
RegEx Lesson 2 – Matching Several Characters
RegEx Lesson 3 – Repeating Matches

Friday, July 15, 2011

RegEx Lesson 3 – Repeating Matches – Quick Guide to Regular Expressions

3.1 Matching one or more characters
To match one or more instances of a character, simply append a + character.
Eg: matching an email
T: askamith@fmail.com
RegEx: \w+@\w+\.\w+
R: askamith@fmail.com


3.2 Matching Zero or More Characters
use * metacharacter, it is placed right after a character or a set and it will match zero or more instances of the character or set.
T: Amith Ah Amh A3465654747ucrfjerghggh
RegEx: A.*h
R: Amith Ah Amh A3465654747ucrfjerghggh43566dcs

last regex match result reminds us that we have to limit the exact match. its done using (?).


3.2 Matching Zero or One Character - ?
use ? metacharacter for matching zero or one char right after a character.
T: The URL is http://www.askamith.wordpress.com/, to connect
securely use https://www.askamith.wordpress.com/ instead.
RegEx: https?://
R: The URL is http://www.askamith.wordpress.com/, to connect
Securely use https://www.askamith.wordpress.com/ instead.


3.3 Range Interval matching - {n1,n2}
T: 10-6-2004
RegEx: \d{1,2}[-\/]\d{1,2}[-\/]\d{2,4}
R: 10-6-2004


3.4 Preventing Over Matching using Lazy Quantifiers - *?
T: living in <b>SL</b> and <b>LK</b>.
RegEx: <b>.*</b>
R: living in SL and LK.
The reason for this is that metacharacters such as * and + are greedy; they look greatest possible match as opposed to the smallest. You can prevent this by using lazy versions of these quantifiers (they matches the fewest characters instead of the most).
T: living in <b>SL</b> and <b>LK</b>.
RegEx: <b>.*?</b>
R: living in SL and LK.


3.5 Match Word Boundaries
\b is used to match the start or end of a word.
T: The cat scattered his food all over the room.
RegEx: \bcat\b
R: The cat scattered his food all over the room.

RegEx Lesson 2 – Matching Several Characters – Quick Guide to Regular Expressions

2.1 Matching one of Several Characters
T: amith smith gmith
RegEx: [ag]mith
R: amith smith gmith


[Rr]eg[Ee]x ,Match both RegEx or regex.
2.2 Using Character set ranges

    [ns]a[0123456789] == [ns]a[0-9]
    • A-Z matches all uppercase characters from A to Z.
    • a-z matches all lowercase characters from a to z.

    note:
    When you use ranges, be careful not to provide an end range that is less than the start range (such as [Z-A]).

    Multiple ranges may be combined in a single set.
    [A-Za-z0-9] ,This pattern is shorthand for:
    [ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890]

    Eg: validation RegEx for css color codes;
    T: BGCOLOR="#336633" TEXT="#FFFFFF"
    RegEx: #[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]
    R: It will check the color code are in hexadecimal range.
    BGCOLOR="#336633" TEXT="#FFFFFF"


2.3 Anything but not this; (using the ^ metacharacter)
The pattern used in this example is the exact opposite of the one used previously. [0-9] matches all digits (and only digits). [^0-9] matches anything by the specified range of digits. As such,

[ns]a[^0-9]\.xls matches sam.xls but not na1.xls, na2.xls, or sa1.xls.


2.4 Dealing with meta characters with escaping(\):
There may be some special cases where metacharacters wont behave their normal way. For example it cant be used . to match. or [ to match [. So we have to specially pointed out what is the exact role of those meta characters in a Regular Expression.


    T: myArray[0]
    RegEx: myArray\[0\]
    R: myArray[0]


So any metacharacter can be escaped by preceding it with a blackslash (\).


2.5 Matching Whitespace Characters:
When you are performing regular expression searches, you’ll often need to match nonprinting whitespace characters within your text.
Metacharacter Description
[\b] Backspace
\f Form feed
\n Line feed
\r Carriage return
\t Tab
\v Vertical tab
Matching Specific Character types
\d Any digit (same as [0-9])
\D Any nondigit (same as [^0-9])
\w Any alphanumeric character in upper or lower case and underscore (same as [a-zA-Z0-9_])
\W Any nonalphanumeric or underscore character (same as [^a-zA-Z0-9_])
\s Any whitespace character (same as [\f\n\r\t\v])
\S Any nonwhitespace character (same as [^\f\n\r\t\v])

RegEx Lesson 1 – Matching Characters - Quick Guide to Regular Expressions

I want to remind you that RegEx contains plain text and expressions (can contain only plain text). RegEx are highly case sensitive.

1.1 Matching literal text:
Text: Hello, my name is Amith. Welcome
RegEx: Amith
Result: Hello, my name is Amith. Welcome


1.2 For Matching Any Character - .

    T : cat cnt sat
    RegEx: c.t
    R: cat cnt sat

1.3 Matching special characters
A . has a special meaning in regex. If you need a . in your pattern, you need a way to tell regex that you want the actual . character and not the regex special meaning of the . character. To do this, you escape the . by preceding it with a \(backslash) . \is a metacharacter (a fancy way of saying a character with a special meaning, in contrast to the character itself). Therefore, . means match any character, and \. means match the . character itself.

    T : cat cnt.a sat.txt
    RegEx: sat\.txt
    R: cat cnt.a sat.txt

Tuesday, July 12, 2011

C# Client Application to add new posts to blogspot.com (automated stuffs)

lang: c#

download: Google Data API 21.7mb

install the msi. normaly it contents several libraries. but for this app we need only using Google.GData.Client;
add reference to ur solution.


using System.Net;
using Google.GData.Client;


public static void Main()
{
string posttitle="How to make a cup of tea";
// body contains html
string body = "<p>sample paragraph<img src="http://www...."/><a href></a></p>";
//string[] label
string[] label={"tea","cup of tea","askamith"};

bool abc = AddPost(posttitle, body, label);

}



public static bool AddPost(string title, string bodyHTML, string[] labels)
{
Service service = new Service("blogger", "askamith-global");
service.Credentials = new GDataCredentials("your blogspot gmail-address", "password");
AtomEntry newPost = new AtomEntry();
newPost.Title.Text = title;
newPost.Content = new AtomContent();
newPost.Content.Content = bodyHTML;
newPost.Content.Type = "html";
foreach (string label in labels)
{
AtomCategory cat = new AtomCategory();
cat.Scheme = new Uri("http://www.blogger.com/atom/ns#");
cat.Term = label;
newPost.Categories.Add(cat);
}
AtomEntry response = null;
try
{
response = service.Insert(new Uri("http://www.blogger.com/feeds/xxxxxxxxxxxxx/posts/default"), newPost);
}
catch (GDataRequestException exception)
{
if (exception.ResponseString == "Blog has exceeded rate limit or otherwise requires word verification for new posts")
{
return false;
}
else
{
throw exception;
}
}
if (response == null)
{
throw new Exception("Something went wrong");
}
return true;
}



for new Uri("http://www.blogger.com/feeds/xxxxxxxxxxxxx/posts/default")

xxxxxxxxxxxxxxx= your blogger id (it will be shown in the url in adding a new post page in ur blogger dashboard)

http://www.blogger.com/post-create.g...xxxxxxxxxxxxxx

any questions regarding this. comment those bellow. its 100% working. try it. thanks

MySQL command Help – How to Remove Duplicate Data or Rows

How to remove duplicate data or rows from a MySQL data table by using a single command or a query?

If the output of a MySQL query contains duplicate data or rows, you can eliminate or remove those by using the DISTINCT keyword before the selected column name.

Mysql>
SELECT firstname FROM address;


Then you need unique firstname (remove duplicate firstnames):

Mysql>
SELECT DISTINCT firstname FROM address;


DISTINCT can be used with multiple columns also:

Mysql>
SELECT DISTINCT firstname,city FROM address;


>>Next thing is, if you want to permanent delete the duplicate data, you can use:

Mysql>>
DELETE FROM table1
USING table1,table1 AS vtable
WHERE (NOT table1.id=vtable.id)
AND (table1.field_name=vtable.filed_name);


This code tells mysql that there is a table called ‘table1’, then it tells that we use ‘table1’ and a new virtual table ‘vtable’ with the values of table1. Then 3rd row tells mysql to not to compare records itself. Then finaly we command there should not be records with the same field_name.

Thursday, June 30, 2011

How to prepare Software Requirement Specification Document (SRS)

This is one of a very important document which act as a baseline for a contract between the user and the developer. Its is expected to contain the complete requirements to adequate what the user will get from the implementation.

Based on IEEE recommendation.

1. INTRODUCTION

  • 1.1 PURPOSE: Clearly state purpose of this document
  • 1.2 SCOPE: by whom and how it will be used
  • 1.3 Definitions: Acronyms, Abbreviations as applicable
  • 1.4 References: to other documents
      • 1.5 Overview of Developer’s Responsibilities: In terms of development, installation, training, maintenance, etc..

2. GENERAL DESCRIPTION

Is a general description giving the overview of the product features.

    • 2.1 PRODUCT PERSPECTIVE: relationship with other products and principle interfaces
    • 2.2 PRODUCT FUNCTION OVERVIEW: general overview of tasks; including data flow diagrams
    • 2.3 USER CHARACTERISTICS: who they are and what training they may need
    • 2.4 GENERAL CONSTRAINTS: about schedule, resources, cost, etc..

3.1 FUNCTIONAL REQUIRMENTS

In this part we give functional details of every function of the software by giving brief introduction to this functions, then we describe  inputs to the function, processing and the output. This is really the body of SRS document where functions are describe in full detail.

  • 3.1.1 INTRODUCTION
  • 3.1.2 INPUTS
  • 3.1.3 PROCESSING
  • 3.1.4 OUTPUTS
  • 3.2…. (repeat similarly for each function

4. External Interface Requirements

  • 4.1 User Interfaces: a preliminary user manual giving commands, screen formats, outputs, error messages, etc.. e.g: not need to show exact interfaces, but user must get an logical overview for those interfaces.
  • 4.2 Hardware Interfaces: with existing as well as new or special purpose hardware.
  • 4.3 Software Interfaces: with other software packages, operating systems, etc.. e.g: A hotel reservation system may have to interface with their existing Accounting system.

5. Performance Requirements

  • What kind of an environment in which this system performs well.
  • Capacity requirements (no of users, no of files), response time, through-put (in measurable terms). e.g: In a Banking system: how long will it take for a transaction process, is system able to face peak time work load, etc..

6. Design Constraints

ex: In financial world, lots of standards are there. so our software must be compatible with those.

  • 6.1 Standards Compliance: software development standards as well as organizational standards (e.g., for reports, auditing)
  • 6.2 Hardware Limitations: available machines, operating systems, storage capacities, etc..

7. Other Requirements

Possible future extensions

Note:

  1. All sections are not required for all projects.
  2. After SRS finishes, it will be handover to the design team, and then they will convert the word specification into a design.
  3. We must ensure that we have collected all the data and put them in to that document.
  4. SRS can be extensive task for a large scale systems, and it is used to be reviewed with the customer and there should be a sign off by telling ‘YES’ to the SRS from the customers view.
  5. We would proceed for the next phase (Design Phase) if only the SRS is accepted by the user.

Saturday, April 30, 2011

When the Abstraction and interface uses (Abstract vs Interface)

Both abstract classes and interfaces are used when there is a difference in behavior among the sub-types extending the abstract class or implementing the interface.

When the sub-types behaviour is totally different then you use an interface, when the sub-types behaviour is partially common and different with respect to the supertype an abstract class is used. In an abstract class the partially common behaviour is given a concrete implementation. Since there is no common behaviour between an interface and a sub-type an interface does not have an implementation for any of its behaviour.

Lets assume you are developing a framework for a 'killer' competition where the people who participate have to demonstrate their killing skills. Members participating in the competetion have their own ways of killing.

It could be as different as 'using a gun to kill', 'throwing the victim up in the air and kicking his balls when he victim comes down,  'slitting his throat or behaeding the victim'

The expected behaviour here is to 'KILL', though all the members do have that behaviour 'KILL" each member manifests the behaviour in a different way. Since the behaviour manifestation varies from member to member this scenario calls for an interface.

Interface KilingCompetition{
  Corpse kill();
}

Each member will implement this interface and give an implementation in his/her own way.

Now, lets consider a karate competition(is it called sparring?). Here each member has to follow certain things as laid out by the organizers or the karate protocol. It may include things like bowing to the opponent before and after the fight starts, taking a stand etc. Now these behaviours are common and has to manifested in the same way by every paticipating member. But the behaviour 'fight' will differ from member to member. So now we have a set of common behaviour and also a behaviour which manifests differently from member to member. this calls for an abstract class where you give implementation to the common behaviour and make the differeing behaviour abstract and hence the class abstract.

public abstract class KarateFight{
      public void bowOpponent(){
         //implementation for bowing which is common
         // for every participant
      }

      public void takeStand(){
         //implementation which is common
         // for every participant
      }

      public abstract boolean fight(Opponent op);
      //this is abstract because it differs from
      // person to person
}

What is the difference between interface and abstract class?

* interface contains methods that must be abstract; abstract class may contain concrete methods.
* interface contains variables that must be static and final; abstract class may contain non-final and final variables.
* members in an interface are public by default, abstract class may contain non-public members.
* interface is used to "implements"; whereas abstract class is used to "extends".
* interface can be used to achieve multiple inheritance; abstract class can be used as a single inheritance.
* interface can "extends" another interface, abstract class can "extends" another class and "implements" multiple interfaces.
* interface is absolutely abstract; abstract class can be invoked if a main() exists.
* interface is more flexible than abstract class because one class can only "extends" one super class, but "implements" multiple interfaces.
* If given a choice, use interface instead of abstract class.

Saturday, March 5, 2011

How to downgrade WordPress version step by step

People (Blog owners) want to downgrade their wordpress version because of

1. Incompatibilities with their themes

2. Incompatibilities with installed plugins

etc..

I had one of above problem and i googled but not found any automated way for it. then i decided to go manually.

step by step ~ how to downgrade wordpress

- you should have the zip file of the older version of the wordpress

1. you must have your current blog, DB name, DB admin, DB admin pwd

2.Goto web site cpanel

there in wp-content folder compress(.zip) your theme folder and plugin folder and download them in to your local machine.

3. then delete all wordpress related files, folders from the root direstory. (if you want you may keep .htaccess, sitemap.xml, robot.txt)

4.Then upload the older version of wordpress and extract the .zip in to the root directory.

5. then access to your domain and install your blog, using the old DB file.

6. Replace theme and plugin folder by uploading your old theme and plugin folders.

then thats it.. it's easy.. you can get your old wordpress version just in a minitue without harming to your blog post or your account details.

(actually this is a file replacement :)..)

thanks.

Friday, February 25, 2011

Web Crawlers | Search Engine Robots | Search Engine Spiders

A web crawler (also known as a web spider or web robot) is a program or automated script which browses the internet seeking for web pages to process. Many applications mostly search engines, crawl websites everyday in order to find up-to-date data. Most of the web crawlers save a copy of the visited page so they could easily index it later.

.:: Flash Contents and Web Spiders ::.

Flash is cool, in fact it's much cooler than HTML. It's dynamic and cutting edge. Unfortunately, search engine spiders use trailing-edge technology.

Remember: a search engine spider is roughly equivalent to a version 2.0 web browser. Spiders simply can't interpret newer technologies, such as Flash. So even though that Flash animation may amaze your visitors, it's invisible to the search engines. If you're using Flash to add a bit of spice to your site, but most of your pages are written in standard HTML, this shouldn't be a problem.

 

But if you've created your entire site using Flash, you've got a serious problem getting your site into the engines. And you will have to optimize flash using different steps....

some clients wants to develop flash site so it seems to be tough job handling a flash site and a real challenge for seo!

So that is why having a full PHP page is not really a problem in SEO... because once you browse a particular PHP it was already converted to HTML.

I have never build flash content websites, i do attractiveness to my websites from the help of CSS. But it's wanted to SE spiders be updated to face the new technologies.

 

source : http://www.googlecommunity.com/forum/