Sunday, 14 April 2013

Host multiple websites/domains on localhost.

Multiple websites/domains can be hosted on the local host/machine by tweaking httpd.conf file in apache.

Let's suppose, we want to host two sites website1.com and website2.com with root path as /www/website1 and /www/website2 respectively on local machine.

Add following lines at the end of httpd.conf file.

NameVirtualHost *:80



ServerAdmin webmaster@website1.com
DocumentRoot /www/website1
ServerName website1.com
ErrorLog logs/website1.com-error_log
CustomLog logs/website1.com-access_log common




ServerAdmin webmaster@website2.com
DocumentRoot /www/website2
ServerName website2.com
ErrorLog logs/website2.com-error_log
CustomLog logs/website2.com-access_log common


Now add following information in /etc/hosts file so that browser looks up for the domains on the local machine.

127.0.0.1 website1.com
127.0.0.1 website2.com


Restart apache.
Now all requests for website1 and website2 will be sent to the localhost.

For more info visit

Sunday, 24 March 2013

Draw on iPhone/iPad screen using Bezier paths | Core Graphics - iOS App Development

UIBezierpath class can be used to draw line segments, rectangles, polygons, arcs, curves, oval shapes and a lot more using vector based method.

Note: We will be viewing all our drawings in an UIImageView object.

1) Let's create a rectangle by drawing line segments using Bezier paths.

Add/Modify highlighted part of code in your app.

ViewController.h

#import
@interface ViewController : UIViewController
{
UIImageView *drawpad;
}
@property (retain, nonatomic) IBOutlet UIImageView *drawpad;
@end


ViewController.m

@implementation ViewController
@synthesize drawpad;
- (void)viewDidLoad
{
UIBezierPath *path = [[UIBezierPath alloc] init];
[path moveToPoint:CGPointMake(50.0f, 50.0f)];
[path addLineToPoint:CGPointMake(270.0f, 50.0f)];
[path addLineToPoint:CGPointMake(270.0f, 500.0f)];
[path addLineToPoint:CGPointMake(50.0f, 500.0f)];
[path closePath];
UIGraphicsBeginImageContext(self.view.frame.size);
path.lineCapStyle = kCGLineCapRound;
path.lineWidth = 10.0f;
[[UIColor blackColor] setStroke];
[[UIColor redColor] setFill];
[path stroke];
[path fill];
self.drawpad.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}


Note: I have placed an UIImageView object in XIB and connected it to the drawpad outlet. The object's size is same as of view.

Run the app and you will see a rectangle drawn on your screen.

2) Let's see how to create an arc on screen

Modify the code in viewDidLoad function as

UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150)
radius:30
startAngle:0
endAngle:(22.0f/7.0f)
clockwise:YES];
UIGraphicsBeginImageContext(self.view.frame.size);
path.lineCapStyle = kCGLineCapRound;
path.lineWidth = 10.0f;
[[UIColor blackColor] setStroke];
[path stroke];
self.drawpad.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


Run the app. An arc, part of circle with radius 30 and centre at (150,150), will be drawn with starting angle as 0 radian and ending angle as (22.0f/7.0f) radian.

For more info visit

Sunday, 3 March 2013

Index-Organized Tables – Oracle

Data is stored in B-Tree structure in Index-Organized tables(IOT). IOTs are unlike indexed tables in which index information is stored at a different place. Index is an object inside oracle database which stores index values corresponding to rowids for faster row access.

Suppose we have a table EMPLOYEE with some columns, and column emp_id is its primary key. As emp_id is the primary key, oracle would have automatically created index on emp_id. Now, if we fire a select query as

SELECT * FROM employee WHERE emp_id=12345;
Oracle will first consult index on this column to get rowid of row in the table. Once it gets the rowid, it accesses the row.

So, we can say that two i/o calls took place

1) to access the index object to get the rowid.

2) to access the table using the rowid.

This was about how indexed tables work.

Let's see what's different in IOTs
As told in the beginning, IOTs store data in B-Tree data structure. Data in these tables are sorted on primary key and stored in B-Tree. Not only the primary key, but other columns of the row are also stored within index leaf block of the B-Tree.

IOTs are more efficient than indexed tables as only one i/o call is needed to fetch data directly from B-Tree, and storage space is also reduced, as no separate index object is made.

IOT can be created by specifying ORGANIZATION INDEX qualifier while creating table. Also, it is necessary to create primary key, as data in IOT is sorted on primary key.

CREATE TABLE employee
(
emp_id NUMBER(10) PRIMARY KEY,
emp_name VARCHAR2(20),
phone_no NUMBER(10)
)
ORGANIZATION INDEX;


Some optional information can also be provided while creating IOT.

CREATE TABLE employee
(
emp_id NUMBER(10) PRIMARY KEY,
emp_name VARCHAR2(20),
phone_no NUMBER(10)
)
ORGANIZATION INDEX TABLESPACE tbs_01
PCTTHRESHOLD 30
INCLUDING emp_name
OVERFLOW TABLESPACE tbs_02;

Index blocks of IOT will be stored in tablespace tbs_01 in B-Tree structure.

Amount of data stored in index leaf blocks depends on PCTTHRESHOLD value. According to above value, only 30 % space of the block can be used to store row data, rest of the data will be stored in OVERFLOW TABLESPACE tbs_02. Row will be split at 30 % threshold with first part stored in index leaf block in tbs01 and rest of the part stored in OVERFLOW TABLESPACE tbs02. This 30% data may contain key as well as non key columns. Storage of non key columns depends on PCTTHRESHOLD value. INCLUDING option specify the non key columns which should be given preference to be stored in the index leaf block.

For more info visit

Monday, 11 February 2013

How to disable Ajax calls in jQuery Mobile?

Ajax calls can be disabled in jQuery Mobile by handling mobileinit event. This event is fired as soon as jQuery Mobile starts loading, and according to jQuery Mobile default settings, Ajax calls are always enabled. So, in order to get the results, you need to bind your event handler before jQuery Mobile is loaded.

Let's see how to do this 

<html>
<head>
<link href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" rel="stylesheet" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script>
$(document).bind("mobileinit",function(){
$.mobile.ajaxEnabled=false;
});
</script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
<body>
<!-- Content in body -->
</body>
</html>





Note: mobileinit event is bound before jQuery Mobile loads.

For more info visit

Sunday, 3 February 2013

How to integrate iAd in an iPhone/iPad app?

iAd framework was introduced in iOS 4.0. The framework does most of the things for you, such as downloading ads from remote network. You just need to integrate with this framework and place ads on your iPhone/iPad app.

Advertisements in iAd are available in

Banner view : Ads are displayed on a portion of device screen.

Full screen view : Occupies the whole screen during display.

User can interact with the ads by clicking on them and the app owner earns revenue when user views or interacts with the ad.

You should agree to iAd agreement on iTunes before integrating iAd services into your app. Also, iAd has to be explicitly enabled for each app before submitting the app to appstore.

Let's see how to integrate a Banner type ad into an app. I am using Navigation/Master-Detail ViewController app for this post.

1) Include iAd framework in your app.

2) Declare BannerViewContainer protocol as shown below in iAdIntegrationAppDelegate.h (assuming name of the app to be iAdIntegration). Add/Modify the highlighted part of code.

#import <UIKit/UIKit.h>
#import <iAd/iAd.h>


@protocol BannerViewContainer
- (void)showBannerView:(ADBannerView *)bannerView animated:(BOOL)animated;
- (void)hideBannerView:(ADBannerView *)bannerView animated:(BOOL)animated;
@end


Make sure that iAdIntegrationAppDelegate confirms to ADBannerViewDelegate. Also, declare an object of AdBannerView class.

@interface iAdIntegrationAppDelegate : NSObject <UINavigationControllerDelegate, UIApplicationDelegate,ADBannerViewDelegate> {
UIWindow *window;
UINavigationController *navigationController;
ADBannerView *ibannerView;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@end


3) Add/modify the highlighted part of code in iAdIntegrationAppDelegate.m file

Declare an object of UIViewController class to hold the current ViewController object.

UIViewController *icurrentController;

Instantiate ibannerView and make the current object as its delegate.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
ADBannerView *tempbannerView = [[ADBannerView alloc] initWithFrame:CGRectMake(0.0, 367.0, 0.0, 0.0)];
ibannerView = [tempbannerView retain];
[tempbannerView release];
ibannerView.delegate = self;

[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
icurrentController = nil;
return YES;
}


Implement methods of ADBannerViewDelegate

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
[icurrentController showBannerView:banner animated:YES];
}


- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[icurrentController hideBannerView:ibannerView animated:YES];
}


- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
//perform activities after the ad is clicked and before action is triggered.
return YES;
}


- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{
//perform activities after the app interface is restored.
}

Get the viewcontroller which confirms to BannerViewContainer protocol and call showBannerView method if banner is correctly loaded.(viewcontroller on which you want to display ads)

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
icurrentController = [viewController respondsToSelector:@selector(showBannerView:animated:)] ? (UIViewController *)viewController : nil;
if (ibannerView.bannerLoaded && (icurrentController != nil)) {
[(UIViewController *)viewController showBannerView:ibannerView animated:NO];

}
}


4) Now implement methods of BannerViewContainer protocol in the viewcontroller where you want to display ads.
Add/Modify the highlighted part of code in FirstViewController.h. Make sure FirstViewController confirms to BannerViewContainer protocol.

@interface FirstViewController : UIViewController<BannerViewContainer>
Add/Modify the highlighted part of code in FirstViewController.m. Implement the methods of BannerViewContainer protocol.

ADBannerView *_bannerView;

- (void)showBannerView:(ADBannerView *)bannerView animated:(BOOL)animated
{
_bannerView = bannerView;
[self.view addSubview:_bannerView];
}


- (void)hideBannerView:(ADBannerView *)bannerView animated:(BOOL)animated
{
_bannerView = nil;
}


For more info visit

Tuesday, 29 January 2013

Synonyms in Oracle.

Synonyms are aliases for objects in database. Synonyms make it easy for a schema to access objects in other schema. Normally objects in other schema can be accessed by prefixing schema name to the object, but with the use of synonym there is no need to use schema name while accessing the object.

Synonyms can be public as well as private.

Public Synonym : Public synonyms are objects of public schema and can be accessed by any schema in the same or different database(assuming databases are connected by a link).

Let's see how to create a public synonym.

CREATE PUBLIC SYNONYM tab1 FOR sch1.tab1;
Now the table tab1 can be accessed by any schema using name tab1.

Private Synonym : Private synonyms are private to a schema. They can be referenced only by schema which owns the object. Private synonym can be created by removing the private keyword from the above CREATE statement.

CREATE SYNONYM tab1 FOR sch1.tab1;
Note :

1) Knowing a public synonym for an object doesn't mean that a schema can access the object as it wants. Access policies to the object will always be determined by access permissions granted to the schema for the object.

2) Permission for creation of a public synonym has to be granted by DBA.

For more info visit.

Sunday, 20 January 2013

Pin objects in Oracle shared pool using DBMS_SHARED_POOL package.

DBMS_SHARED_POOL package can be used to pin PL/SQL objects, SQL cursors, triggers, sequence inside shared pool area in Oracle database memory.

Oracle has shared pool inside System Global Area(SGA) where it caches compiled PL/SQL and SQL code to improve response and reduce execution time when the same code is executed again. Whenever we execute a SQL or PL/SQL code then Oracle checks for  compiled version of the code in the shared pool area. If it finds the compiled version then the code is executed from the shared pool area, this is known as soft parse, or else, code is fetched from disk, compiled, executed and stored in the shared pool area for future reference.

Shared pool area has a memory limit, so Oracle keeps moving out objects as new objects come in, i.e. aging process is followed to move older objects out of the memory to make space for new objects. Sometimes, for improving performance, there is a need to keep some objects in the shared pool area and skip the usual aging process irrespective of the new objects coming in, so we pin those objects permanently inside the shared pool area. These objects will then not be removed by usual aging process unless we explicitly ask Oracle to unpin them.

Let's see how to use this package.

This package consists of some procedures which can be called to pin/unpin the objects.

PROCEDURE DBMS_SHARED_POOL.KEEP
(name IN VARCHAR2
,flag IN CHAR DEFAULT 'P');

KEEP procedure can be used to pin object inside shared pool area.
name: Name of the object to be pinned.
flag: Type of the object to be pinned.

Value of flag can be
P : Procedure/Function/Package
T : Type
Q : Sequence
C : Cursor
R : Trigger

PROCEDURE DBMS_SHARED_POOL.UNKEEP
(name IN VARCHAR2
,flag IN CHAR DEFAULT 'P');

UNKEEP procedure can be used to unpin object from shared pool area. Object will follow normal aging process once unpinned.
name: Name of the object to be unpinned.
flag: Type of the object to be unpinned.

PROCEDURE DBMS_SHARED_POOL.SIZES
(minsize IN NUMBER);

SIZES procedure can be used to get information about all objects which are currently in shared pool area and exceed the size specified in parameter of the procedure.

PROCEDURE DBMS_SHARED_POOL.ABORTED_REQUEST_THRESHOLD
(threshold_size IN NUMBER);

ABORTED_REQUEST_THRESHOLD procedure can be used to avoid Oracle flushing old objects in order to make space for a big new object. When threshold is set then any object greater than threshold size will not be allowed in memory if sufficient memory space is not available in shared pool.

NOTE: DBMS_SHARED_POOL is not accessible by a normal user, also there is no public synonym referencing the package. This package is mostly used by the Oracle DBAs.

For more info visit

Sunday, 6 January 2013

Use copy command to copy tables on local or remote database.

Generally we use CREATE TABLE tab1 AS SELECT..... to copy a table's data to some other table.

There are some limitations with this method.

1) Oracle doesn't commit in between while copying data, so undo segment may run out of space.

2) This technique cannot be used to copy LONG type columns in a table.

Let's see how to use copy command to get rid of these problems.

Suppose we want to create a new table tab_new with data of table tab_old. In this case copy command will be used as

COPY FROM username/password@db_name
CREATE tab_new
USING SELECT * FROM tab_old;

This will create a new table tab_new with data of table tab_old.

Some other options which can be used in place of CREATE are

INSERT : Inserts records in an existing table.

APPEND : Creates the target table, if it doesn't exists, and inserts records.

REPLACE : Drops the existing table, creates new table and inserts records.

For more info visit.