WebHosting

Wednesday, June 29, 2011

Android Hello World Program

package com.example.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class HelloAndroid extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv
.setText("Hello, Android");
setContentView
(tv);

}
}

C++ Design Pattern

  • Creational Patterns: deal with initializing and configuring classes and objects
  • Structural Patterns: deal with decoupling the interface and implementation of classes and objects
  • Behavioral Patterns: deal with dynamic interactions among societies of classes and objects

SmtpMail and Mail Message

using System.Web.Util 
sendmail()
{
            MailMessage mailMsg = new MailMessage();
            mailMsg .From = "
from@fromServer.com";
            mailMsg .To = "
to@toServer.com";
            mailMsg .Cc = "
cc@ccServer.com"";
            mailMsg .Bcc = "
bcc@bccServer.com";
            mailMsg .Subject = "SubjectOfTheMailString";
            mailMsg .Body = "BodyOfTheMailString";
            SmtpMail.Send(mailMsg ); 

}

How to send e-mail programmatically by using System.Web.Mail in Visual C#


using System;
using System.Web.Mail;

namespace WebMail
{
    class Class1
    {
        static void Main(string[] args)
        {
            try 
            {
                MailMessage oMsg = new MailMessage();
            
                oMsg.From = "sender@somewhere.com";
               
                oMsg.To = "recipient@somewhere.com";
                oMsg.Subject = "Send Using Web Mail";
                
             
                oMsg.BodyFormat = MailFormat.Html;
                
               
                oMsg.Body = "<HTML><BODY><B>Hello World!</B></BODY></HTML>";
                
               
              
                String sFile = @"C:\temp\Hello.txt";  
                MailAttachment oAttch = new MailAttachment(sFile, MailEncoding.Base64);
  
                oMsg.Attachments.Add(oAttch);

              
                SmtpMail.SmtpServer = "MySMTPServer";
                SmtpMail.Send(oMsg);

                oMsg = null;
                oAttch = null;
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
            }
        }
    }
} 
   
Add a reference to the System.Web.dll namespace

Color Codes Hexadecimal..


000300600900C00F00
003303603903C03F03
006306606906C06F06
009309609909C09F09
00C30C60C90CC0CF0C
00F30F60F90FC0FF0F
030330630930C30F30
033333633933C33F33
036336636936C36F36
039339639939C39F39
03C33C63C93CC3CF3C
03F33F63F93FC3FF3F
060360660960C60F60
063363663963C63F63
066366666966C66F66
069369669969C69F69
06C36C66C96CC6CF6C
06F36F66F96FC6FF6F
090390690990C90F90
093393693993C93F93
096396696996C96F96
099399699999C99F99
09C39C69C99CC9CF9C
09F39F69F99FC9FF9F
0C03C06C09C0CC0FC0
0C33C36C39C3CC3FC3
0C63C66C69C6CC6FC6
0C93C96C99C9CC9FC9
0CC3CC6CC9CCCCCFCC
0CF3CF6CF9CFCCFFCF
0F03F06F09F0CF0FF0
0F33F36F39F3CF3FF3
0F63F66F69F6CF6FF6
0F93F96F99F9CF9FF9
0FC3FC6FC9FCCFCFFC
0FF3FF6FF9FFCFFFFF

Design Patterns in .net


  Behavioral Patterns
  Chain of Resp.  A way of passing a request between a chain of objects
  Command  Encapsulate a command request as an object
  Interpreter  A way to include language elements in a program
  Iterator  Sequentially access the elements of a collection
  Mediator  Defines simplified communication between classes
  Memento  Capture and restore an object's internal state
  Observer  A way of notifying change to a number of classes
  State  Alter an object's behavior when its state changes
  Strategy  Encapsulates an algorithm inside a class
  Template Method  Defer the exact steps of an algorithm to a subclass
  Visitor  Defines a new operation to a class without change




  Structural Patterns
  Adapter  Match interfaces of different classes
  Bridge  Separates an object’s interface from its implementation
  Composite  A tree structure of simple and composite objects
  Decorator  Add responsibilities to objects dynamically
  Facade  A single class that represents an entire subsystem
  Flyweight  A fine-grained instance used for efficient sharing
  Proxy  An object representing another object



Creational Patterns
  Abstract Factory  Creates an instance of several families of classes
  Builder  Separates object construction from its representation
  Factory Method  Creates an instance of several derived classes
  Prototype  A fully initialized instance to be copied or cloned
  Singleton  A class of which only a single instance can exist

Official Google Blog: Introducing the Google+ project: Real-life sharing...

Official Google Blog: Introducing the Google+ project: Real-life sharing...: "Update : For our international readers, this post is also available in French , German , Italian , Japanese , Portuguese , Russian and Span..."

Singleton Class in C++

class SingletonClass
{
private:
static bool SingletonIsstanceFlag;
static SingletonClass *single;
SingletonClass()
{
//private constructor

}
public:
static SingletonClass* getInstance();
void method();
~SingletonClass()
{
SingletonIsstanceFlag = false;
}
};

Singleton Pattern & its implementation with C++

#include
#include "Singleton.h"
using namespace std;

void useSingleton(){
Singleton* singletoneg= Singleton::getInstance();
singleton->doSummut();

// this shouldn't be allowed
Singleton* doubleton;
doubleton->doSummutElse();
}

int main(int argc, char** argv) {
useSingleton();
return (EXIT_SUCCESS);
}

Tuesday, June 28, 2011

Delegates (C# Programming)

Delegates have the following properties:
  • Delegates are like C++ function pointers but are type safe.
  • Delegates allow methods to be passed as parameters.
  • Delegates can be used to define callback methods.
  • Delegates can be chained together; for example, multiple methods can be called on a single event.
  • Methods do not have to match the delegate signature exactly. For more information, see Using Variance in Delegates (C# and Visual Basic).
  • C# version 2.0 introduced the concept of Anonymous Methods, which allow code blocks to be passed as parameters in place of a separately defined method. C# 3.0 introduced lambda expressions as a more concise way of writing inline code blocks. Both anonymous methods and lambda expressions (in certain contexts) are compiled to delegate types. Together, these features are now known as anonymous functions. For more information about lambda expressions, see Anonymous Functions (C# Programming Guide).

    public delegate int PerformCalculation(int x, int y);
     
    A delegate is a type that defines a method signature. When you instantiate a delegate, you can associate its instance with any method with a compatible signature. You can invoke (or call) the method through the delegate instance.
    Delegates are used to pass methods as arguments to other methods. Event handlers are nothing more than methods that are invoked through delegates. You create a custom method, and a class such as a windows control can call your method when a certain event occurs
  •  
     
    delegate void Delegate1();
    delegate void Delegate2();
    
    static void method(Delegate1 d, Delegate2 e, System.Delegate f)
    {
        // Compile-time error.
        //Console.WriteLine(d == e);
    
        // OK at compile-time. False if the run-time type of f 
        // is not the same as that of d.
        System.Console.WriteLine(d == f);
    }
    

Interfaces (C# Programming)

Interfaces consist of methods, properties, events, indexers, or any combination of those four member types. An interface cannot contain constants, fields, operators, instance constructors, destructors, or types. It cannot contain static members. Interfaces members are automatically public, and they cannot include any access modifiers.
When a class or struct implements an interface, the class or struct provides an implementation for all of the members defined by the interface. The interface itself provides no functionality that a class or struct can inherit in the way that base class functionality can be inherited. However, if a base class implements an interface, the derived class inherits that implementation. The derived class is said to implement the interface implicitly.
Classes and structs implement interfaces in a manner similar to how classes inherit a base class or struct, with two exceptions:
  • A class or struct can implement more than one interface.
  • When a class or struct implements an interface, it receives only the method names and signatures, because the interface itself contains no implementations

    public class Car : IEquatable<Car>
    {
        public string Make {get; set;}
        public string Model { get; set; }
        public string Year { get; set; }
    
        // Implementation of IEquatable<T> interface
        public bool Equals(Car car)
        {
            if (this.Make == car.Make &&
                this.Model == car.Model &&
                this.Year == car.Year)
            {
                return true;
            }
            else
                return false;
        }
    } 
     
     
     

    An interface has the following properties:
  • An interface is like an abstract base class: any non-abstract type that implements the interface must implement all its members.
  • An interface cannot be instantiated directly.
  • Interfaces can contain events, indexers, methods, and properties.
  • Interfaces contain no implementation of methods.
  • Classes and structs can implement more than one interface.
  • An interface itself can inherit from multiple interfaces.

Featured Posts

How to Enable and Configure Remote Desktop (RDP) on Ubuntu 24.04.4 LTS

Remote Desktop Protocol (RDP) support in Ubuntu has become considerably easier with the GNOME Remote Desktop stack included in modern Ubuntu...