Nano's Blog

03/08/2010

Typeof() and GetType() in C#

Filed under: programming — Tags: — nano @ 02:05
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace testNameSpace
{

    class testClass
    {
        public static void Main()
        {
            System.Type type0 = typeof(int);
            Console.WriteLine("{0}", type0);

            int i = 0;
            System.Type type1 = i.GetType();
            Console.WriteLine("{0}", type1);

        }
    }
}

output

System.Int32
System.Int32

More:
MSDN : http://msdn.microsoft.com/en-us/library/58918ffs(VS.80).aspx

01/31/2010

pear install HTML_QuickForm

Filed under: programming — Tags: — nano @ 15:04

pear.php.net

root@mysite:~# pear install –onlyreqdeps HTML_QuickForm
PHP Warning: Module ‘imap’ already loaded in Unknown on line 0
PHP Warning: Module ‘mcrypt’ already loaded in Unknown on line 0
WARNING: “pear/HTML_QuickForm” is deprecated in favor of “pear/HTML_QuickForm2″
WARNING: “pear/HTML_Common” is deprecated in favor of “pear/HTML_Common2″
downloading HTML_QuickForm-3.2.11.tgz …
Starting to download HTML_QuickForm-3.2.11.tgz (102,201 bytes)
…………………..done: 102,201 bytes
downloading HTML_Common-1.2.5.tgz …
Starting to download HTML_Common-1.2.5.tgz (4,585 bytes)
…done: 4,585 bytes
install ok: channel://pear.php.net/HTML_Common-1.2.5
install ok: channel://pear.php.net/HTML_QuickForm-3.2.11
root@mysite:~#

01/23/2010

Kohana Installation Tutorial

Filed under: programming — Tags: , , — nano @ 15:11

Step1.
Download kohana from : http://v3.kohanaphp.com (Version:3.0.3.zip);
Step2.
Uncompress kohana_3.0.3 and copy kohana folder to C:\xampp\htdocs and rename kohana to ‘home’
Step3.
start XAMPP apache service from XAMPP control panel
Step4.
Input: http://localhost/home/index.php
Show error below
cURL Enabled Kohana requires cURL for the Remote class.
Step5.
Open C:\xampp\php\php.ini file and remove ‘;’ from

extension=php_curl.dll in php.ini

Step6.
Restart Apache service.
Step7.
Input: http://localhost/home/index.php again.
Show Your environment passed all requirements.
Remove or rename the install.php file now.

Step8. Rename install.php to other_Name.php
input: http://localhost/home/index.php again.
Show Kohana_Request_Exception [ 0 ]: Unable to find a route to match the URI: home/index.php
Step9.
Open C:\xampp\htdocs\home\application\bootstrap.php
find

Kohana::init(array('base_url' => '/kohana/'));

Modify the /kohana/ to /home/
Step10.
input: http://localhost/home/index.php again.
Show hello, world!
congratulations!

01/19/2010

How to delete Offline Folder (.OST) file

Filed under: collections — Tags: — nano @ 11:48

The below procedure tested on winxp and outlook2003.

Sometimes an OST file becomes corrupted beyond repair or repair is not desirable. In this case, it can be deleted. After it had been deleted, you may need to recreate it as a new file as described above before Outlook will work properly.
• Quit Outlook if it is running.
• From the Start menu, go to Run.
• In the Run window, enter this command in the “Open:” field and click OK:
o “%USERPROFILE%\Local Settings\Application Data\Microsoft\Outlook\
To find the exact path, please follow the steps 1-4 for Outlook 2002/2003/2007 or steps 1-3 for Outlook 2000 outlined above to get to Offline Folder File Settings. You can find the .ost file location in the File box. You may want to cut-and-paste that information for accuracy and ease.
• In the Explorer window, locate the OST file to deleted. Select it and press delete on your keyboard or use the Delete icon on the toolbar

How to change the default startup directory for Command Prompt?

Filed under: collections — Tags: — nano @ 06:13

When you open a Command Prompt window (CMD.EXE), it defaults to your user profile home directory. If you wish to change the default startup directory for Command Prompt, use the steps listed in this article.

Set the default startup directory

Click Start, Run and type Regedit.exe
Navigate to the following branch:

HKEY_CURRENT_USER \ Software \ Microsoft \ Command Processor

In the right-pane, double-click Autorun and set the startup folder path as its data, preceded by “CD /d “. If Autorun value is missing, you need to create one, of type REG_EXPAND_SZ or REG_SZ in the above location.

Example: To set the startup directory to D:\learning\perl, set the Autorun value data to CD /d D:\learning\perl

You may also use a batch file so that it executes the contents automatically upon launching the Command Prompt. To view the entire list of arguments supported by CMD.EXE and their description, type CMD /? at the Command Prompt.

01/16/2010

The shift and unshift Operators

Filed under: programming — Tags: — nano @ 02:39

The shift and unshift operators perform the corresponding actions on the “start” of the array (or the “left” side of an array, or the portion with the lowest subscripts).
push and pop operators do things to the “end” of an array(or the “right” sidce of an array).

The foreach control involved to the sample code below.

#!C:\Perl\bin\perl.exe
use strict;
use warnings;

my @array = qw# dino fred barney #;
# print @array;
foreach my $array (@array) {
$array = "\t$array"; # put a tab in front of each element of @rocks
$array.= "\n"; # put a newline on the end of each
print $array;
}

my $m = shift(@array); # $m gets "dino", @array now has ("fred", "barney")
my $n = shift @array; # $n gets "fred", @array now has ("barney")
shift @array; # @array is now empty
# print a empty array
foreach my $array (@array) {
$array = "\t$array"; # put a tab in front of each element of @rocks
$array.= "\n"; # put a newline on the end of each
print $array; # nothing printed
}

my $o = shift @array; # $o gets undef, @array is still empty
unshift(@array, 5); # @array now has the one-element list (5)
unshift @array, 4; # @array now has (4, 5)
my @others = 1..3;
unshift @array, @others; # @array now has (1, 2, 3, 4, 5)
foreach my $array (@array) {
$array = "\t$array"; # put a tab in front of each element of @rocks
$array.= "\n"; # put a newline on the end of each
print $array;
}

Output:


D:\learning\perl>hi.pl
        dino
        fred
        barney
        1
        2
        3
        4
        5

D:\learning\perl>

- from Learning Perl 5E

01/14/2010

XAMPP for windows

Filed under: programming — Tags: , , — nano @ 16:32

new version of XAMPP 1.7.3, including:
Apache 2.2.14 (IPv6 enabled) + OpenSSL 0.9.8l
MySQL 5.1.41 + PBXT engine
PHP 5.3.1
phpMyAdmin 3.2.4
Perl 5.10.1
FileZilla FTP Server 0.9.33
Mercury Mail Transport System 4.72

Download and Install XAMPP 1.7.3
Destination folder: c:\

The perl cgi script could located in
C:\xampp\htdocs\hello.cgi (or hello.pl) recommend.
C:\xampp\cgi-bin\hello.cgi (or hello.pl)

Link: http://www.apachefriends.org/en/xampp-windows.html

Beginning Perl and MySQL Tutorial

Filed under: programming — Tags: , — nano @ 07:41

Step1.
Download & install MySQL.
mysql-essential-5.1.36-win32.zip
Download Link: http://download.cnet.com

Step2.
Setting a root password for MySQL
1. Start your command line by going to the Start Menu > Run and typing cmd (or type command if you are using an older version of windows)
2. Change directory to where you installed mysql to:

C:\> cd C:\mysql\bin

3. Switch to mysql command line:

C:\mysql\bin> mysql -u root mysql

4. Then set a default password:

mysql> SET PASSWORD FOR root@localhost=PASSWORD(‘newpass’);

where “newpass” is the password you want to use

Adding more users
Start your command line by going to the Start Menu > Run and typing cmd (or type command if you are using an older version of windows)
Change directory to where you installed mysql to:

C:\> cd C:\mysql\bin

Switch to mysql command line (if you have not set a root password remove the -p switch when you type it in):

C:\mysql\bin> mysql -u root -p mysql

Then then add your new user:

mysql> GRANT ALL PRIVILEGES ON *.* TO rachel@localhost IDENTIFIED BY ’summer’;

where “rachel” is the username and “summer” is the password you want to use. You can also limit users to specific database, allow only certain remote hosts to connect all using the GRANT statement. However, that is outside the scope of this tutorial so search for more info on using GRANT if you are interested in those features.

- from www.ricocheting.com

Step3.
let’s create a database called perltest and in that database, we will create a simple table called samples and populate it with some data. Here is the SQL you’ll need to create the table and fill in a few records, just connect to your MySQL database and run them.

CREATE DATABASE perltest;
USE perltest;
CREATE TABLE samples (
id int(10) unsigned NOT NULL auto_increment,
name varchar(128) NOT NULL default '',
phone varchar(128) NOT NULL default '',
PRIMARY KEY (id)
);
INSERT INTO samples VALUES (1, 'Some Person', '555-5555');
INSERT INTO samples VALUES (2, 'Another Person', '222-2222');

Step4.
Sample Script

#!/usr/bin/perl -w

use strict;
use warnings;
use DBI;

my $dbh = DBI->connect('dbi:mysql:perltest','root','myroot')
or die "Connection Error: $DBI::errstr\n";
my $sql = "select * from samples";
my $sth = $dbh->prepare($sql);
$sth->execute
or die "SQL Error: $DBI::errstr\n";
while (my @row = $sth->fetchrow_array) {
print "@row\n";
}

Dissection.

$dbh = DBI->connect('dbi:mysql:DATABASE_NAME', USERNAME, PASSWORD)</blockquote>

The die option provides an alternative to the program simply not working if a connection is not established. Basically, the connect it tried, and if it fails, your script will die and display an error message that should help you debug. Once we’ve established a connection to the MySQL database, we will need to create a string of SQL and then prepare it to query the database.

$sql = "select * from samples";
$sth = $dbh->prepare($sql);

Next we query the database with our prepared SQL query, or exit the program and display some debugging information if the MySQL query fails to execute.

$sth->execute
or die "SQL Error: $DBI::errstr\n";

Finally we use the fetchrow_array function to fetch each row of the results from the MySQL database and print them one to a line.

while (@row = $sth->fetchrow_array) {
print "@row\n";
}

If the program is successful, you should see the following output:

1 Some Person 555-5555
2 Another Person 222-2222

- from perl.about.com

[Tips]
DBD-mysql
I run the script using ActivePerl 5.10.1 on Winxp.
The DBD-mysql package didn’t installed by default. You need install it via Perl Package Manager.
More about DBD-mysql
A MySQL driver for the Perl5 Database Interface (DBI)
Version: 4.011
Released: 2009-04-14
Author: Patrick Galbraith CPAN: http://search.cpan.org/dist/DBD-mysql-4.011/

01/06/2010

The each Function

Filed under: programming — Tags: — nano @ 09:09

If you wish to iterate over (that is, examine every element of) an entire hash, one of the usual ways is to use the each function, which returns a key-value pair as two-element list.

#!C:\Perl\bin\perl.exe
use strict;
use warnings;

# declare a new hash
my %some_hash;

%some_hash = ("foo", 35, "bar", 12.4, 2.5, "hello",
      "wilma", 1.72e30, "betty", "bye");

my $key;
my $value;

while ( ($key, $value) = each %some_hash)
{
  print "$key => $value\n";
}

print "\n";
foreach $key (sort keys %some_hash) {
  $value = $some_hash{$key};
  print "$key => $value\n";
  # Or, we could have avoided the extra $value variable:
  #  print "$key => $hash{$key}\n";
}

Output

betty => bye
bar => 12.4
wilma => 1.72e+030
foo => 35
2.5 => hello

2.5 => hello
bar => 12.4
betty => bye
foo => 35
wilma => 1.72e+030

-from Learning Perl 5E

The Hash As a Whole

Filed under: programming — Tags: — nano @ 09:01

The order is jumbled because Perl keeps the key-value pairs in an order that’s conven-
ient for Perl so that it can look up any item quickly.

Elements of a hash are printed out in their internal order, which can not be relied upon and will change as elements are added and removed. If you need all of the elements of a hash in some sort of order, sort the keys, and use that list to index the hash.

If you are looking for a structure that holds its elements in order, either use an array, or use one of the ordered hash’s on CPAN.

the only ordering you can rely upon from a list context hash expansion is that key => value pairs will be together.

use the keys function to get a list of the keys. They will most likely be in the same order as they’re stored in the hash itself, although there’s no guarantee. If the order matters, then you either shouldn’t be using a hash in the first place, or you should use the keys function to get a list, put the items in the desired order, and then loop through that list, accessing each corresponding hash item.

#!C:\Perl\bin\perl.exe
use strict;
use warnings;

# declare a new hash
my %some_hash;

%some_hash = ("foo", 35, "bar", 12.4, 2.5, "hello",
      "wilma", 1.72e30, "betty", "bye");

my @any_array;
@any_array = %some_hash;

print %some_hash;
print "\n";
print "\n";
print @any_array;
print "\n";
print "\n";

my @keys;
@keys = keys %some_hash;
for my $k (sort @keys)
{
    print $k, $some_hash{$k};
}
print "\n";
print "\n";
print map {$_, $some_hash{$_}} sort keys %some_hash;

Output


D:\learning\perl>test.pl
bettybyebar12.4wilma1.72e+030foo352.5hello

bettybyebar12.4wilma1.72e+030foo352.5hello

2.5hellobar12.4bettybyefoo35wilma1.72e+030

2.5hellobar12.4bettybyefoo35wilma1.72e+030
D:\learning\perl>

-from StackOverflow.com

Older Posts »

Powered by WordPress