How to Publish blog remotely using Microsoft Word

Having a website is very common these days. Either through free website service providers like blogger, tumblr, WordPress or having own registered TLD (Top Level Domain) and self hosted site developed using WordPress or Drupal or many other famous open source CMS.

All bloggers are not from technical background and posting an article is somehow tougher for them at the initial stage. They face problem in setting categories, text formatting, url inclusion, image insertion etc. Moreover, we usually write the whole article first using Microsoft Word or similar editors based on various Operating Systems.

How about posting a blog remotely and directly from MS word to your website? Isn’t it cool and easy for majority of bloggers? Question is how we can post a blog directly from MS Word, right?

Read more

Convert Rows into Columns or Transpose Rows to Columns In Oracle SQL

SQL Database LanguageHello Friends, 
Have you ever been in a situation where you as a developer knows that your data is stored in your table rows, but you would like to present the data as a column ??

There are many way to handle this situation. Here I am sharing few of them which I know.​

Below is the sample table and data :
————————————————————
[sql]CREATE TABLE yr_table (
        Roll_No            NUMBER,
        Subject            VARCHAR2(20),
        Marks              NUMBER
);
[/sql]
[sql]insert into yr_table VALUES (1212324,’MTH’,90);
insert into yr_table VALUES (1212324,’PHY’,72);
insert into yr_table VALUES (1212324,’CHE’,85);
insert into yr_table VALUES (1212324,’BIO’,78);
insert into yr_table VALUES (1212334,’MTH’,85);
insert into yr_table VALUES (1212334,’PHY’,65);
insert into yr_table VALUES (1212334,’CHE’,74);
insert into yr_table VALUES (1212672,’MTH’,88);
insert into yr_table VALUES (1212672,’PHY’,42);
insert into yr_table VALUES (1212672,’BIO’,12);
COMMIT;
[/sql]
——————————————————————-

Now I would like to represent above data into below format :

We can achieve above output  in different way.

# Method 1 ->  Using DECODE  function

[sql]SELECT  ROLL_NO,
                 MAX( DECODE( SUBJECT , ‘MTH’ , MARKS ) ) AS MTH  ,
                 MAX( DECODE( SUBJECT , ‘PHY’ , MARKS ) ) AS PHY ,
                 MAX( DECODE( SUBJECT , ‘CHE’ , MARKS ) ) AS CHE ,
                 MAX( DECODE( SUBJECT , ‘BIO’ ,  MARKS ) ) AS BIO
FROM yr_table
GROUP BY ROLL_NO ORDER BY 1  ;​
[/sql]
To understand the above query, first see  the below output of above query without using MAX function then you can understand how above query works.

Method 2 -> Using CASE​ statement 
[sql]SELECT    ROLL_NO,
                MAX( CASE WHEN SUBJECT = ‘MTH’ THEN MARKS END) MTH ,
                MAX( CASE WHEN SUBJECT = ‘PHY’ THEN MARKS END) PHY ,
                MAX( CASE WHEN SUBJECT = ‘CHE’ THEN MARKS END) CHE ,
                MAX( CASE WHEN SUBJECT = ‘BIO’ THEN MARKS END) BIO
FROM yr_table
GROUP BY ROLL_NO ORDER BY 1 ;​
[/sql]
Here CASE statement works same as DECODE function.

Method 3 -> Using PIVOT Operator​

The PIVOT and the UNPIVOT operators were introduced in Oracle version 11g. The PIVOT operator takes data in separate rows, aggregates it and converts it into columns. The following query will give the same result as the query above, just by using the PIVOT operator.
[sql]SELECT * FROM yr_table
PIVOT (
MAX ( MARKS )  FOR (SUBJECT) IN (‘MTH’ AS MTH, ‘PHY’ AS PHY, ‘CHE’ AS CHE, ‘BIO’ AS BIO)

ORDER BY 1​​
[/sql]
 You can check below link for more clarification on PIVOT Operator.  http://www.oracle.com/technetwork/articles/sql/11g-pivot-097235.html 

Method 4 -> Using WITH clause and PIVOT Operator​   
[sql]WITH TMP AS (
    SELECT ROLL_NO,SUBJECT , MARKS FROM yr_table
)
SELECT * FROM TMP 
PIVOT (
MAX(MARKS)  FOR (SUBJECT) IN (‘MTH’ AS MTH, ‘PHY’ AS PHY, ‘CHE’ AS CHE, ‘BIO’ AS BIO)
)
ORDER BY 1
[/sql]

The WITH clause, was added into the Oracle SQL syntax in Oracle 9.2 . The WITH clause can be used to reduce repetition and simplify complex SQL statements. Here don’t get confuse with WITH Clause; just think that it create a temporary table which we can use it in select statement.

Method 5 -> Using WITH clause and Sub-query
[sql]WITH TMP AS (
        SELECT ROLL_NO,SUBJECT , MARKS FROM yr_table
)
SELECT Y.ROLL_NO ,
             (  SELECT TMP.MARKS FROM  TMP WHERE TMP.ROLL_NO = Y.ROLL_NO AND TMP.SUBJECT = ‘MTH’)  AS MTH ,
             (  SELECT TMP.MARKS FROM  TMP WHERE TMP.ROLL_NO = Y.ROLL_NO AND TMP.SUBJECT = ‘PHY’)  AS PHY ,
             (  SELECT TMP.MARKS FROM  TMP WHERE TMP.ROLL_NO = Y.ROLL_NO AND TMP.SUBJECT = ‘CHE’)  AS CHE ,
             (  SELECT TMP.MARKS FROM TMP WHERE  TMP.ROLL_NO = Y.ROLL_NO AND TMP.SUBJECT = ‘BIO’)   AS BIO
FROM (SELECT DISTINCT ROLL_NO FROM yr_table ) Y
ORDER BY 1  ;
[/sql]
Method 6 -> Using Multiple Joins

[sql]SELECT  DISTINCT
              A.ROLL_NO ,    
              B.MARKS AS MTH ,
              C.MARKS AS PHY ,
              D.MARKS AS CHE ,
              E.MARKS AS BIO
FROM yr_table A 
LEFT JOIN yr_table B
    ON  A.ROLL_NO = B.ROLL_NO AND B.SUBJECT = ‘MTH’
LEFT JOIN yr_table C 
    ON A.ROLL_NO = C.ROLL_NO AND C.SUBJECT = ‘PHY’
LEFT JOIN yr_table D
    ON A.ROLL_NO = D.ROLL_NO AND D.SUBJECT = ‘CHE’
LEFT JOIN yr_table E
    ON A.ROLL_NO = E.ROLL_NO AND E.SUBJECT = ‘BIO’
ORDER BY 1;
[/sql]

Friends, please share your knowledge as well, if you know any other method.

Follow me at :
Facebook
Read more

Various ways to print the content of hash in Perl

What is the various ways to print the contents of a hash?

Hash in Perl is nothing but an associative array i.e. Each key is associate with its value and can be displayed using either key or value. It is preferred over simpler array because instead of printing value based on index number, you can print by using key.
Ex:
[perl]$hash{'key'} = 'value';
[/perl]
We will discuss Hash fundamentals in another tutorial where I will explain everything which is required to understand hash clearly with some examples. Let’s see here, how we can display the contents of hash. We assume we have a hash defined as %hash = (some key value pairs);

Read more

[Solved]Cannot accept more than 1 connection error in Filezilla

There is a case when your hosting provider (110mb.com being one of the examples) doesn’t allow more than 1 simultaneous connection per user for file transfers using FTP as it will be restricted from their FTP server due to some security reasons.
 
And if you are using Filezilla, then by default it will try to connect multiple FTP connections. It can connect maximum 11 connections i.e.  10 connections (simultaneous file transfer) +1 (browse the server files) per tab. If it is more than 11 simultaneous connections then either router, firewall or ftp server is compromised. You should report to your hosting provider or site admin.

Read more

How chomp and chop function works in Perl

How chomp and chop function works in PerlWhat is chomp and chop?
chomp()
The chomp() function will remove (usually) any new line character from the end of a string. The reason we say usually is that it actually removes any character that matches the current value of $/ (the input record separator), and $/ defaults to a new line. It returns the total number of characters removed from all its arguments and If VARIABLE is omitted, it chomps $_

So, if $/ =”\t” then chomp would remove every tab instead of new line.
 
For more information on the $/ variable, try perldoc perlvar and see the entry for $/ and perldoc -f chomp
Note: if chomp doesn’t behave as it should by default, hint is to check record separator ($/)

chop()
Sometimes you will find you want to unconditionally remove the last character from a string. While you can easily do this with regular expressions, chop is more efficient. Check perldoc -f chop
 
The chop() function will remove the last character of a string (or group of strings) regardless of what that character is and return the last character chopped. In case of array it return the last character chopped of the last element of the array. Note, if you want to easily remove newlines or line separators see the chomp().

As chop return the last character chopped of the string , if you want it's reverse i.e. return all characters except the last from the string you could use substr($string, 0, -1)
 
Chomp and chop, both functions can be applied on strings,array,hash. We would see it by three examples for each functions.
 
Example 1. Chomping a string
Most often you will use chomp() when reading data from a file or from a user. When reading user input from the standard input stream (STDIN) for instance, you get a newline character with each line of data. chomp() is really useful in this case because you do not need to write a regular expression and you do not need to worry about it removing needed characters.
When running the example below, using the enter key on a line by itself will exit the program.
 
[perl]#!/usr/bin/perl
  use strict;
  use warnings;
  my $username = <STDIN>;
  print "before chomp: $username";
  chomp $username; #or chomp($username); or chomp (my $username =<STDIN>); in one line
  print "After chomp: $username";[/perl] 
Output:
[vim][Sanjeev@Alien Coders]$ perl chomp_examples.pl
Alien Coders
before chomp: Alien Coders
After chomp: Alien Coders[Sanjeev@Alien Coders]$[/vim] 

First print got printed with new line which you entered while typing. Yes, it took new line (pressed enter) also as user input. Second line removed that new line, so second print is displayed along with shell on the same line.
 
Example 2. Chomping an array
If you chomp an array, it will remove  newline from the end of every element in the array:
 [perl] #!/usr/bin/perl
  use strict;
  use warnings;
  my @array = ("sanjeev\n", "Jassi", "AlienCoders\n");
  print "Before chomp:\n";
  print "@array\n";
  chomp(@array);
  print "After chomp:\n";
  print "@array\n";[/perl]
Output:
[vim]Before chomp:
sanjeev
 Jassi AlienCoders
 
After chomp:
sanjeev Jassi AlienCoders[/vim]
As you can see, the newlines have been removed from "sanjeev" and "AlienCoders", but no characters have been removed from "jassi".
 
Example 3. Chomping a hash
If you pass a hash into chomp() function, it will remove newlines from every value (not key) of the hash. Remember key is always unique and string (internally). So, if you add new line in key then use that new line char also while using that key. Better to avoid such nasty thing:
 
 [perl] #!/usr/bin/perl
  use strict;
  use warnings;
  use Data::Dumper;
 
my %hash = (
    'first' => "one\n",
    'second' => "two\n",
    'third' => "three\n",
  );
  print "before chomp:\n";
  print Dumper(\%hash);
  chomp(%hash);
  print "after chomp:\n";
  print Dumper(\%hash);[/perl]
Output:
[vim]before chomp:
$VAR1 = {
          'first' => 'one
',
          'second' => 'two
',
          'third' => 'three
'
        };
after chomp:
$VAR1 = {
          'first' => 'one',
          'second' => 'two',
          'third' => 'three'
        };[/vim]
It clearly shows that how new line is effective before chomp and it looks nice after chomp.
 
Example 4. Chopping a string
The chop() function removes and returns the last character from the given string whatever it is. So don’t do any mistake by assuming that it removed new line from the user input with its first use. When you will use it second time it will again remove one more character from user input but chomp only and only removes new line (or whatever is stored in $/).
 
  [perl]#!/usr/bin/perl
  use strict;
  use warnings;
 
  my $string = 'Perl';
  my $char = chop($string); #to return the chopped character in a variable
 
  print "String: $string\n";
  print "Char: $char\n";[/perl]
 
Output:
 [vim]String: Per
Char: l[/vim] 
 
Example 5. Chopping an array
If you pass the chop() function to an array, it will remove the last character from every element in the array.
 
  [perl]#!/usr/bin/perl
  use strict;
  use warnings;
 
  my @arr = ('Jassi', 'Sanjeev', 'Alien Coders');
  my $last_char = chop(@arr);
 
  print "@arr\n";
  print "Last Char: $last_char\n"; #it will store last character of last element in the array[/perl]
Output:
[vim]Jass Sanjee Alien Coder
Last Char: s[/vim] 

Example 6. Chopping  a hash
If you pass a hash into chop() function , it will remove the last character from the values (not the keys) in the hash. For example:
 
 [perl] #!/usr/bin/perl
  use strict;
  use warnings;
  use Data::Dumper;
 
  my %hash = (
    first => 'one',
    second => 'two',
    third => 'three',
  );
 
  print “Before chop:\n”;
  print Dumper \%hash;
 
  my $chr = chop(%hash);
  print “After chop: \n”;
  print Dumper(\%hash); 
 
  print "Char: $chr\n"; #it always have last character of last value in hash[/perl]
Output:
[vim]Before chop:
$VAR1 = {
          'first' => 'one',
          'second' => 'two',
          'third' => 'three'
        };
After chop:
$VAR1 = {
          'first' => 'on',
          'second' => 'tw',
          'third' => 'thre'
        };
Char: e[/vim]

Note:

  • chop and chomp functions would not work on array/hash reference or array of array/hash reference. So, avoid using this on referential things.
  • Always use parenthesis, if you are using assignment operator while chomping or chopping.
    chomp $value = <STDIN>;  doesn't work  but chomp($value=<STDIN>); works

Credit: http://perlmeme.org

Read more

Delete Function in Perl with examples

“delete” function in Perl is mainly used to delete the given element/key, which in return deletes its associated value(s) too. So, exists() on such key would return false.
Note: Assigning undefined value to a key in has doesn’t remove its key but delete() function would do that. So, use delete() or assigning undefined value wisely.
The general syntax for delete function is:
[perl]delete EXPR
[/perl]

Read more