Pages

Tuesday, August 28, 2012

Was the victory of Apple correct?

Was the victory of Apple correct?

I strongly believe that the decision of court in favour of Apple is injustice to innovation. Patent can be moulded in any shape which is done by Apple.

The only motive of Apple is to have monopoly market.
Patent should be means of safety to the developer not the weapon for killing innovations.
What are the negative impacts it have in markets:-
 Apple will have monopoly market if it is able to restrict the Samsung product. Price will be hype, no competitions means no innovations.

Today the rate at which smartphone business is flourishing soon be diminished by dull products. In every sector the only way to gain rapid growth is competition which is what Apple is afraid.

Let's think of a environment where C developer sue Java for using programming style similar to it, Microsoft suing Linux for making operating system and features similar to it.
 War of Patent should me clean not hurting innovations/competitions in the market

Wednesday, July 11, 2012

IP/Host Resolver

Program that converts IP to host and host to IP
A simple use of Windows API for playing with networks. Today I thought of  making a simple program with the help of Windows API that can return your hostname if you enter IP address and return your IP address if you enter your hostname.
 This program can be very useful for some project where they need user IP address or hostname for processing.



We have used the WinSock API to achieve this.

Here's the code written in Delphi

// Function to get the Host from IP address
function TFrmMain.IPAddrToName(IPAddr: string): string;
var
  SockAddrIn: TSockAddrIn;
  HostEnt: PHostEnt;
  WSAData: TWSAData;
begin
  WSAStartup($101, WSAData);
  SockAddrIn.sin_addr.s_addr := inet_addr(PAnsiChar(AnsiString(IPAddr)));
  HostEnt := gethostbyaddr(@SockAddrIn.sin_addr.S_addr, 4, AF_INET);
  if HostEnt <> nil then
    Result := StrPas(Hostent^.h_name)
  else
    Result := '';
end;


// Function to get the IP Address from a Host

function TFrmMain.GetIPFromHost(HostName: string): string;
type
  TaPInAddr = array[0..10] of PInAddr;
  PaPInAddr = ^TaPInAddr;
var
  phe: PHostEnt;
  pptr: PaPInAddr;
  i: Integer;
  GInitData: TWSAData;
begin
  WSAStartup($101, GInitData);
  Result := '';
  phe := GetHostByName(PAnsiChar(AnsiString((HostName))));
  if phe = nil then Exit;
  pPtr := PaPInAddr(phe^.h_addr_list);
  i := 0;
  while pPtr^[i] <> nil do
  begin
    Result := inet_ntoa(pptr^[i]^);
    Inc(i);
  end;
  WSACleanup;
end;



For complete project source code and exceutable
Refer this site Ip-Host Resolver or Softpedia.com
https://sourceforge.net/projects/iphostresolver

Wednesday, June 13, 2012

Get YOUR SLC RESULT

You can view your slc result/ slc supplementary
at

Refer the following sites for your 2068-2069 slc result
http://slcresult.soce.gov.np/

http://slc.ntc.net.np/

You can also get result using Phone/Mobile
IVR System (From PSTN and CDMA phones)
Dial 1600 and follow the instructions

SMS
Type slc and send sms to 1400
Example :- Type SLC  0201382D and send it to 1400

Monday, May 28, 2012

Chrome overtakes Internet Explorer To Become The World's Most Popular Web Browser


According to new data from StatCounter, Web browser Google Chrome has surpassed the Microsoft Internet Explorer to become World's most Used Web Browser.
Chrome's share of the market rose to 32.8% in the week ending May 20, while Internet Explorer's share of the market dropped to 31.9%.
Google Chrome was released on September 2, 2008. Within 3 and half years of its release it is neck to neck to the software giant Microsoft Internet Explorer.Chrome stability,simplicity and performance attract all the user.
In my personal opinion Healthy Competitions are always good for all of us as it increases efficiency lead to better product and we all enjoy better product. Isn't it????
Now need to see the next step of Microsoft giant to tackle this problem.

Chrome overtakes Internet Explorer To Become The World's Most Popular Web Browser
Chrome overtakes Internet Explorer To Become The World's Most Popular Web Browser

Monday, May 21, 2012

Facebook Vs Google Display Advertising

Facebook Vs Google Display Advertising
In the world of advertising Google is still the lead actor. Google has reach to twice the internet user than Facebook.Advertisement Revenues  for Facebook are decreasing at the rate 6.5% whereas for Google it is increasing 1% / year. Google revenue is two times the Facebook.

Here's a summary:
Total Reach

Facebook: 51% of all internet users
Google: 90% of all internet users

Q1 Revenues

Facebook: $1.06 billion, down 6.5 percent year on year and down 32 percent sequentially.
Google: $2.9 billion, up 1 percent year on year and up 0.7 percent sequentially.

Click through rates

Facebook: 0.051%
Google: 0.4%
Average: 0.1%


Targeting

Facebook:
  • Education
  • Workplace
  • Likes
  • Location
  • Demographics
Google:
  • Interest
  • Keywords
  • Remarketing
  • Location
  • Demographics

Formats

Facebook: standard display ad, Sponsored Stories
Google: Text ads, image ads, video text overlay ads, mobile web game ads

Facebook vs. Google Display Advertising - Comparing the value of the world's largest advertising venues. [INFOGRAPHIC]
© 2012 WordStream, a Provider of AdWords and PPC Management Software.

Friday, May 18, 2012

How to use regular expression for form validation

Suppose, you want user to enter data, combination of small letter,capital letter and digit then how would you do that.You can use regular expressions to check whether user input contains required data or not i.e. digit,small letters.

We have to learn first Perl Compatible Regular Expression (PCRE) in-order to understand this if you are unaware of the PCRE try this out.
PCRE helps us to check the user input with all the combinations of the strings that matches the defined rule.

The given below code will check whether user input  is the combinations of small letter,capital letter and digit. If any one is missing it will echo the message saying that the required data is missing.
Here's the code to do that
<..php

$satisfied=true;
if(isset($_POST['password']))
{
$user_input=$_POST['password'];
/*
Here we check whether user input contains digit or not
*/
$digit="/\d/";
if(!preg_match($digit,$user_input))
{
echo "User input doesnot contains digit
";
$satisfied=false;
}

/*
Here we check whether user input contains capital letter
*/
$capital_alphabet="/[A-Z]/";
if(!preg_match($capital_alphabet,$user_input))
{
echo "User input  doesnot contains Capital letter
";
$satisfied=false;
}

$small_alphabet="/[a-z]/";
if(!preg_match($small_alphabet,$user_input))
{
echo "User input doesnot contains small letter
";
$satisfied=false;
}

$space="/\s/";
if(preg_match($space,$user_input))
{
echo "User input contains Space
";
$satisfied=false;
}

if($satisfied)
{
echo " Satisfied All condtitons";
}
}

?>

Perl Compatible Regular Expression(PCRE)

Perl Compatible Regular Expression(PCRE)
Perl Compatible Regular Expressions (normally abbreviated as “PCRE”) offer a very powerful string-matching and replacement mechanism that far surpasses anything we have examined so far.

Delimiters
A regular expression is always delimited by a starting and ending character.
e.g.   /ab[cd]e/
Here "/" is the delimiter. The expression above will match both abce and abde.

Metacharacters
.       Match any character
ˆ       Match the start of the string
$      Match the end of the string
\s     Match any whitespace character
\d     Match any digit
\w    Match any “word” character


Quantifiers
A quantifier allows you to specify the number of times a particular character or metacharacter can appear in a matched string. There are four types of quantifiers:

*             The character can appear zero ormore times
+             The character can appear one or more times
?              The character can appear zero or one times
{n,m}      The character can appear at least n times, and no more than m.
                 Either parameter can be omitted to indicated a minimum limit
                with nomaximum, or a maximum limit without aminimum, but
                not both.

Using PCRE
First we need to create a regular expression using above rules. All  the combinations of string that can be generated from regular expression is valid.

for e.g.    /ab[c-e\d]/
This will match abc, abd, abe and any combination of ab followed by a digit.

Similarly, /a(bc.)e/
This expression will match the letter a, followed by the letters b and c, followed by
any character and, finally the letter e.

/a(bc.)+e/
This expression will match the letter a, followed by the expression bc. repeated one
or more times, followed by the letter e.

For given regular expression certain combinations are generated now how do we check than users input matches with the combinations or not, For that we will use the function preg_match.

$name = "Pratik Shrestha";
// Simple match
$regex = "/[a-zA-Z\s]/";
if (preg_match($regex, $name)) 
// Valid Name
echo "Valid";
}

In above code if the user input suppose user input is "Pratik Shrestha" and we need to check whether the input matches the pattern or not we pass it to the function preg_match.If it matches it will return true else false.Thus if pattern matches if condition will execute.

Hope you got some idea of regular expression.If you want to see one  practical use PCRE. Look at this.

Source
PHP ZEND BOOK


Tuesday, May 8, 2012

How to Import/Export data from/to Excel Sheet

Do you want to learn the process to export your database to excel sheet or import data from excel sheet. It will be a piece of cake after you learn what I am going to teach you.
Read carefully the steps.  Don't give any hassle to your brain you will say such a easy method at the end of this post.

In-order to export and import data from and to database you need first to learn connecting and performing queries using PHP. As I am going to write code using PHP.If you don't have database connection knowledge. Please learn that first and re-read this article.
OK Lets proceed

First you need to know about CSV file
A file which contains the data which is separated from one another with comma is known as comma-separated values (CSV) file. Normally this file can be open in Microsoft Excel Sheet and can treated as XLS file. We will use CSV file to import and export data.

Here's the Code needed to Read the CSV File and Import Data using PHP
//Integrate this code in your PHP file for reading csv file and inserting data to table
$dbc=mysqli_connect('hostname','username','password','database_name');
$f = fopen('file_name.csv','r');
while($row=fgetcsv($f))
{
$query="Insert into table_name values('$row[0]','$row[1]')";
mysqli_query($dbc,$query); 
}

Here enter your hostname,username,password and database_name that is required for your database connection. After successfull connection you can proceed reading csv file.
First you need to make connection between your csv file and server using the default function fopen. Enter the location and filename you want to read This function is used to read files.
Since we just need to read file we have passed "r" for reading only.
fopen('file_name.csv','r');
Let's assume that the CSV file contains two field and table also contains two field.If you have more that two field  then you need to make changes according to it.
for e.g. if you got n column in CSV file and have n columns in table
$query="Insert into table_name values('$row[0]','$row[1]',.......,'$row[n-1]','$row[n]')";
The first the foremost thing you need to check is no of fields you have in your table ,As only for that fields you can insert data. If  CSV file contains less or more field  that required it may cause error.

Here's the Code needed to Read the Database and Export it to CSV File using PHP

//Integrate this code in your PHP file for exporting data to csv file

$dbc=mysqli_connect('hostname','username','password','database_name'); 
$f = fopen('file_name.csv','a');
$query="Select * from table_name";
$r=mysql_query($dbc,$query);
while($row=mysqli_fetch_array($r,MYSQL_NUM))
{
fputcsv($f,$row);
}
 Here we read the data from database and write it to the csv file. Query returns the data in the form of array which we write in the CSV file using the function fputcsv.
fputcsv($f,$row);
 Since we are going to write in the file the second parameter of the fopen function should be "a" as it indicates we are writing to the file and appending data to previous data of the file.

Wednesday, March 14, 2012

Encrpy & Decrypt your Message using PHP



Today thought of writing simple program in PHP implementing Julius Caesar Encryption / Decryption technique. In this encryption character are shift by certain numbers i.e for e.g. if shifted by 3 bits.In encrytion A will be replaced by D ,similarry B-E,C-F,.................. and vice versa for decrpytion. This is a simple algortihm. If you have an object oriented principle it will be piece of cake for you to understand.

Here's the code for it


 class CaesarCipher
 {

  const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';

  protected $encrypt_sequence = array();
  protected $decrypt_sequence = array();

  public function __construct($seed = 1)
  {
   $total_chars = strlen(self::CHARS);

   // Normalize seed
   $seed = $seed % $total_chars;

   // Generate encryption and decryption sequences on the basis of seed passed 
   for ($i = 0; $i < $total_chars; $i++)
   {
    $src = substr(self::CHARS, $i, 1);
    $dst = substr(self::CHARS, ($i + $seed) % $total_chars, 1);
    $this->encrypt_sequence[$src] = $dst;
    $this->decrypt_sequence[$dst] = $src;
   }

   // Also add space
   $this->encrypt_sequence[' '] = ' ';
   $this->decrypt_sequence[' '] = ' ';
  }

  
/*
After generating the sequence for decryption of message we simply replace each bit of message with some sequence generated. Here I have used strstr function which replace each character of message with another character. 
*/


public function encrypt($value)
  {
   $value = strtoupper($value);
   return strtr($value,$this->encrypt_sequence );
  }

  public function decrypt($value)
  {
   $value = strtoupper($value);
   return strtr($value,$this->decrypt_sequence );
  }


/*This simply returns the array as array being protected it is not accessible to others i.e. not in this package so a public function is created to return array
*/ 
public function getEncryptSequence()
  {
   return $this->encrypt_sequence;
  }
  public function getDecryptSequence()
  {
   return $this->decrypt_sequence;
  }

  }


  // Run cypher

/*
*Although Random value is used you can use one constant value inorder to encrypt and decrypt you *message in future also, or remeber the seed value while encrypting and decrypting and make changes in 
* seed value for correct output
*/ 
$seed = mt_rand(1, 35);
  $cipher = new CaesarCipher($seed);

  $source = 'ADD YOUR MESSAGE HERE TO ENCRYPT';

  $encrypted = $cipher->encrypt($source);
  $decrypted = $cipher->decrypt($encrypted);



  // Print results
  echo "
CAESAR CIPHER (seed={$seed})\n\n";

  echo "Source:    {$source}\n";

  echo "Encrypted: {$encrypted}";

  echo "   ".($encrypted === $source ? "NOT ENCRYPTED :(" : "ENCRYPTED :)")."\n";



  echo "Decrypted: {$decrypted}";

  echo "   ".($decrypted === $source ? "MATCHES SOURCE! :)" : "DOES NOT MATCH SOURCE :(")."\n";



  echo "\n\n";





  // Print encryption/decryption sequences

  echo "Encryption:";

  foreach ($cipher->getEncryptSequence() as $k => $v)

  {

  if ($k === ' ') continue; // Don't display space

  echo " {$k}>{$v}";

  }

  echo "\n";



  echo "Decryption:";

  foreach ($cipher->getDecryptSequence() as $k => $v)

  {

  if ($k === ' ') continue; // Don't display space

  echo " {$k}>{$v}";

  }

  echo "\n";








Thursday, February 9, 2012

USING JAVA REFLECTOR API

JAVA REFLECTOR API 


Do you want to know how Java IDE knows about the functions name available in a class file?
Do you want to want to know dynamically about the functions that are publicly available in a Java class file.If the ans is Yes, You have to learn about Java Reflector API.If you ever tried to make an JAVA IDE this features can be very helpful in IDE.