Wednesday, February 17, 2010

Sample Paypal Integration Code

- (void)sendPayPalRequestPOST{

NSString *parameterString = [NSString stringWithFormat:@"USER=usernamehere"

"&PWD=passwordhere"

"&SIGNATURE=signaturekeyhere"

"&METHOD=DoDirectPayment"

"&CREDITCARDTYPE=%@"

"&ACCT=%@"

"&EXPDATE=%@"

"&CVV2=256"

"&AMT=%@"

"&FIRSTNAME=%@"

"&LASTNAME=%@"

"&STREET=%@"

"&CITY=%@"

"&STATE=%@"

"&COUNTRY=%@"

"&ZIP=%@"

"&COUNTRYCODE=US"

"&PAYMENTACTION=Sale"

"&VERSION=2.3",

txtCreditCardType.text,txtAccountNumber.text,txtExpireDate.text,txtTotalAmount.text,txtFirstName.text,txtLastName.text,txtStreet.text,txtCity.text,txtState.text,txtCountry.text,txtZip.text];

NSURL *url = [NSURL URLWithString:@"https://api-3t.sandbox.paypal.com/nvp"];

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];

NSString *msgLength = [NSString stringWithFormat:@"%d", [parameterString length]];

[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];

[theRequest setHTTPMethod:@"POST"];

[theRequest setHTTPBody: [parameterString dataUsingEncoding:NSUTF8StringEncoding]];


NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];


if(theConnection){

webData = [[NSMutableData data] retain];

}else{

}

}


Monday, May 11, 2009

How to create a multimonitor setup ?

Article found in CHIP megazine Nov 2008 page no: 114

Sequence & Series Formulas

Arithmatic Progression
a,a+d,a+2d...., a+nd

  • nth term of arithmatic progression
Tn = a + (n-1) d
  • Sum of n - terms of arithmatic progression
Sn= (n/2) [ 2a + (n - 1) d]
  • if a,b and c are in arithmatic progression then b = (a + c)/2.
Geomatric Progression
a,ar,ar^2,..., ar^n
  • nth term of geomatric progression is given by Tn = a r^(n-1).
  • Sum of the first n terms of geomatric progression is given by;
Sn = a [ (1 - r^n) / (1 - r) ] , for r<1>
Sn = a [ (r^n - 1)/ (r - 1) ], for r>1
  • if three quantities a,b and c are in GM then b = Sqrt(ac);
  • Infinite Geomatric Series
when |r|<1   
S* = a / (1 - r);
when |r|>1 then 
S*= Infinity;
Harmonic Mean
  • HM of a and b is 2ab/(a+b).
  • nth terms of Harmonic Progression is  Tn = 1 / [ a + (n-1) d ]
Other Important Formulas

  • Sum of first n - natural number is given by:  summation (r=1 to n)  : n (n + 1) / 2.
  • Sum of squares of first n - natural number is given by summation (r=1 to n) :[ n ( n + 1 ) (2n + 1)  ] / 6 
  • Sum of cubes of first n - natural number is given by summation (r=1 to n) : [n^2 (n+1)^2 ]
/4.



Sunday, May 10, 2009

Paging Program

Paging Related C Program: 
Input : 45 
Output : 10 + 10 + 10 + 10 + 5

#include
#include

void main()
{
int numberoflinksperpage=10;
int n,low,high,i=0;
clrscr();
printf("Enter number : ");
scanf("%d",&n);

while(n>numberoflinksperpage)
{
low=i;
high=i+1;
i++;
printf("\n display results from %d to %d ",numberoflinksperpage*low,numberoflinksperpage*high);
n=n-numberoflinksperpage;
}
low=i;
high=i+1;
printf("\n display results from %d to %d ",numberoflinksperpage*low,numberoflinksperpage*(high-1)+n);

getch();
}

Wednesday, April 29, 2009

Decimal to Binary

Input : any Decimal Number

Output : Binary format 

Logic:

1) Take any natural number say..10.
2)  divide by 2, and find remainder...repeat the same process until u get 0.
divisor number remainder
         2 10 (0)
          ---------------------------------
      2 5 (1)
      ----------------------------------
      2 2 (0)
      ----------------------------------
      2 1 (1)
      ----------------------------------
            0
3) Now look at the remainder pattern from bottom to top, ie. 1010 which is an equivallent for decimal number 10.

Sunday, April 26, 2009

Combination of Strings

Input : Any number of Strings
Output : Combinations of Strings
for eg: A,B,C(input)
then Output : 
A
B
C
AB
AC
AD
BC
BD
CD
ABC

mathematical formula : nCr =  n ! / (n-r) ! r !

Algorithm with explanations:

1) Enter the number of strings.
          Let say 3. A,B and C.
2) now loop from i=1 to 2^3-1 = 7 (in general (2^n) -1 ).
3) Observe binary patterns for each of the numbers coming in that loop.
     like in the following case.
Number Bianry Pattern
(A) (B) (C)
  1 0 0 1
2 0 1 0
3 0 1 1
4 1 0 0
5 1 0 1
6 1 1 0
7 1 1 1       
4) now put the appropriate string where 1 appears, and put nothing in case of 0.
ie.
1st entry becomes C
2nd entry B
3 BC
4 A
5 AC
6 AB
7 ABC

Thats all  u need.
Thanks