Thursday, March 15, 2012

C# code for sending mail automatically through application code.

You can generally find this kind of programming requirements in automated mail response system like websites for online booking for booking confirmation mail. This is very basic piece of code. For enterprise level requirement you can use MS SQL server 2008 which has functionality for the same available.


These namespaces are to added to the code.
using System.Net.Mail;
using System.Net;
The following lines of code shows how the mail message is generated and finally send using SMTP.
MailMessage mM = new MailMessage();
//Mail Address
mM.From = new MailAddress("sender@hotmail.com ");
//receiver email id
mM.To.Add("receiver@hotmail.com ");
//subject of the email
mM.Subject = “subject string”;
//attachment
mM.Attachments.Add(new Attachment(@"local path"));
//body of the email
mM.Body = “email body”;
mM.IsBodyHtml = true;
//SMTP client
SmtpClient sC = new SmtpClient("smtp.live.com");
//port number for Hot mail
sC.Port = 25;
//credentials to login in to hotmail account
sC.Credentials = new NetworkCredential("sender@hotmail.com", "password");
//enabled SSL
sC.EnableSsl = true;
//Send an email
sC.Send(mM);

How to list open ports in ubuntu lunux.


Open and listening ports :

netstat -anltp | grep "LISTEN"

Established ports :

netstat -anltp | grep "ESTABLISHED"

Monday, March 12, 2012

Unlock Windows Phone 7 Emulator through coding, Start all application in windows phone emulator 7 which is not displayed by default


1. start visual studio 2010
2. create a new console application.
3. add reference to “Microsoft.Smartdevice.Connectivity” which is found in the path
“c:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SmartDevice.Connectivity\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.Smartdevice.Connectivity.dll”
// -----  Select this path according to your system.
Note : Please keep in mind for this sample to work you should have windows phone sdk installed on your pc.

Paste this code in  Program.cs which is created by default in your project.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SmartDevice.Connectivity;
using System.Globalization;


Friday, March 9, 2012

Search Engine Based on Hbase Sorl

Here is a solution for hbase solr integration for create full fledged search engine based on hbase the cloud database.
the solution is called SolBase according to publisher site

"
Solbase is highly scalable search engine built on top of Lucene, Solr, and HBase.
In a nut shell, Solbase replaced Lucene's index file layer that was stored in local file system
under NFS to big database implementation in HBase.

Leveraging HBase's high performance scan, inverted index is efficiently stored in HBase for
fast data retrieval.

http://www.slideshare.net/KyungseogOh/solbase"
 
For more detail visig 
https://github.com/Photobucket/Solbase
http://www.slideshare.net/KyungseogOh/solbase

Thursday, March 1, 2012

Copy file from local disk to hdfs using java

 
Local File ====== File Copy =======> hdfs file systemHadoop
 
 
Create a project in eclipse or netbeans or any editor you like and add hadoop-core.jar and create a class named PutToHdfs and put this code
 
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DistributedFileSystem;

/**
*
*
* @author shashwat
*/
public class PutToHdfs {


Tuesday, February 28, 2012

Gentrate Equivalent Regular Expression From String

public static String CreateRegexFromString(String inString) { 
        StringBuilder newString = new StringBuilder(); 
        for(int i=0; i<inString.length(); ++i) { 
            char eachCharacher = inString.charAt(i); 
            if ("\\.^$|?*+[]{}()".indexOf(eachCharacher) != -1) 
                newString.append('\\').append(eachCharacher); 
            else if (Character.isLetter(eachCharacher))
               
                newString.append("["+Character.toLowerCase(eachCharacher)+Character.toUpperCase(eachCharacher)+"]"); 
            else if (Character.isDigit(eachCharacher)) 
                newString.append("\\d"); 
            else 
                newString.append(eachCharacher); 
        } 
        return newString.toString(); 
    }

Sunday, February 5, 2012

What are the access Modifiers in C# ?

Access modifier specify the accessibility of a variable or and object. That means who can access the object and how can it be accessed.which controls whether they can be used from other code in your assembly or other assemblies. You can use the following access modifiers to specify the accessibility of a type or member when you declare it:

public : 
The type or member can be accessed by any other code in the same assembly or another assembly that references it.

private:
The type or member can be accessed only by code in the same class or struct.

Saturday, February 4, 2012

How a thread is created ?


First, create a new Thread Start delegate. The delegate points to a method that will be executed by the new thread. Pass this delegate as a parameter when creating a new Thread instance. Finally, call the Thread.Start method to run your method.


In Detail :


1. Create a System.Threading.Thread object.
2. Create the call back function
3. Starting the Thread




Thread newThread= new Thread(new ThreadStart (MyCallbackFunction));


                 /  \                                                      /  \
                   |         (1)                                            |          (2)




newThread.Start()


        /  \
          |        (3)







C# get file name from file path

  String filePath = @"c:\file\neme\file.txt";

=> filePath.Split('\\')[filePath.Split('\\').Length-1]     ---->   Will give file name with extension

=> (filePath.Split('\\')[filePath.Split('\\').Length-1]).Split('.')[0] --> Will give file name without extension 


=> filePath.Split('\\')[0]  --> Will give drive letter 


Lets Discuss Deligates


A delegate is a form of type-safe function pointer used by the .NET Framework. Delegates specify a method to call and optionally an object to call the method on. They are used, among other things, to implement callbacks and event listeners. It encapsulates a reference of a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked.

Basically it is similar like the old "C" age function pointer, where functions can be assigned like a variable and called in the run time based on dynamic conditions. C# delegate is the smarter version of function pointer which helps software architects a lot, specially while utilizing design patterns.

At first, a delegate is defined with a specific signature (return type, parameter type and order etc). To invoke a delegate object, one or more methods are required with the EXACT same signature. A delegate object is first created similar like a class object created. The delegate object will basically hold a reference of a function. The function will then can be called via the delegate object.



Syntax :

Friday, February 3, 2012

Setup passwordless ssh in Ubuntu, ssh localhost


1. ssh-keygen -t rsa -P "" 
 
-> this will generate key pair file in the current user .ssh folder
-> which is in home folder of user just press ctrl + h to show hidden files 
-> after giving this command just keep pressing enter dont enter file name or so
 
it will show    ->   Generating public/private rsa key pair.
 
Enter file in which to save the key    -> just press enter on this.
 
after this you will get the shell prompt back there you type
 
2. cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys 
 
-> this will create authorized_keys in .ssh folder and put your public key in that so that
-> you just type ssh localhost it will login to localhost without asking the password.
 
 

Featured Posts

Run Commands for Windows

  🖥️ CPL Files (Control Panel Applets) Run via Win + R → filename.cpl Command Opens appwiz.cpl P...