Browse Month: January 2014

How to send parameters to visualforce component?

Here is best way I could experience:

<apex:component controller=”c_controller”>

<apex:attribute name=”varTEst” description=”Some parameter the controller expects.”

type=”CustomObject__c” required=”false” assignTo=”{!relatedProperty}”/>

</apex:component>

 

In apex class:

public class c_controller

{

public CustomObject__c relatedProperty {get; set;}

}

 

Now depends on how you call the component, you can even dynamically invoke the component:

CustomObject__c i = new CustomObject__c();

Component.c.ComponentName comp = new Component.c.ComponentName(relatedProperty = i);

.NET Vs. Salesforce

.NET

Salesforce

Security

1. Need to decide among several ways to apply security model.
2. Overhead of custom programming.

1. Integrated security model provided by SalesForce.
2. No additional overhead of security programming & review.

User Interface

1. No ready support, entire design will have to be developed from scratch for both backend & frontend.

1. Advanced User Interface and Navigation readily available which works seemlessly on all browsers & screen resolutions.
2. Standard tags can be assigned custom CSS easily

Upgrades & Updates

Managing this is difficult for custom tailor made applications, proper planning & compatibility issues have to be taken care of.

Each seasonal release of Salesforce adds a host of new features and functionality, these are automatically updated & even custom apps can be updated accordingly quite easily.

Database

1. Perform your own database design & performance tuning, maintain your own server. No guaranteed best performance.
2. Advantage is you have access to real database.

1. Salesforce.com decided to build an application that was multi-tenant on both the application side and on the database side. We have no overheads at all of database design, indexes, redundancy, etc.
2. No access to underline database.

Reporting

Again employ some library from scratch.

Salesforce has rich set of features to generate many types of graphical & tabular charts.

Workflows

If you choose to use systems like MS Dynamics or other .NET based, you can use workflows.

Salesforce reduces a lot of programming effort creating powerful workflows with few clicks.

Extensibility

More addins/plugnis available for .NET

Comparatively few apps available on appexchange.

Email Integration

Configure & use your own or 3rd party Email server.

Salesforce has pretty good & easy ways of managing your incoming & outgoing emails.

Customization

Requires lots of efforts.

Very easy, even a non-technical person can learn quickly.

Mobility

Creating mobile UI friendly apps basically means reprogramming or redesigning everything again.

With the advent of Salesforce1, you can apply special visualforce tags to make your UI mobile friendly. Currently only for Android & iOS.

.NET

Salesforce

Security

1. Need to decide among several ways to apply security model.
2. Overhead of custom programming.

1. Integrated security model provided by SalesForce.
2. No additional overhead of security programming & review.

User Interface

1. No ready support, entire design will have to be developed from scratch for both backend & frontend.

1. Advanced User Interface and Navigation readily available which works seemlessly on all browsers & screen resolutions.
2. Standard tags can be assigned custom CSS easily

Upgrades & Updates

Managing this is difficult for custom tailor made applications, proper planning & compatibility issues have to be taken care of.

Each seasonal release of Salesforce adds a host of new features and functionality, these are automatically updated & even custom apps can be updated accordingly quite easily.

Database

1. Perform your own database design & performance tuning, maintain your own server. No guaranteed best performance.
2. Advantage is you have access to real database.

1. Salesforce.com decided to build an application that was multi-tenant on both the application side and on the database side. We have no overheads at all of database design, indexes, redundancy, etc.
2. No access to underline database.

Reporting

Again employ some library from scratch.

Salesforce has rich set of features to generate many types of graphical & tabular charts.

Workflows

If you choose to use systems like MS Dynamics or other .NET based, you can use workflows.

Salesforce reduces a lot of programming effort creating powerful workflows with few clicks.

Extensibility

More addins/plugnis available for .NET

Comparatively few apps available on appexchange.

Email Integration

Configure & use your own or 3rd party Email server.

Salesforce has pretty good & easy ways of managing your incoming & outgoing emails.

Customization

Requires lots of efforts.

Very easy, even a non-technical person can learn quickly.

Mobility

Creating mobile UI friendly apps basically means reprogramming or redesigning everything again.

With the advent of Salesforce1, you can apply special visualforce tags to make your UI mobile friendly. Currently only for Android & iOS.

How to create CAPTCHA image verification in PHP and jQuery

index.php

File contains PHP code to load captcha image and text box to input visible word.

<?php
// Session start must be the first line, whether you include it or not 🙂
session_start();
?>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
<head>
<title>How to create CAPTCHA image verification in PHP and jQuery </title>
<meta http-equiv=”Content-Type” content=”text/html;charset=utf-8″ />
<style type=”text/css”>
img {border-width: 0}
* {font-family:’Lucida Grande’, sans-serif;}
</style>
<script type=”text/javascript” src=”jquery-1.8.0.min.js”></script>
<script type=”text/javascript”>
$(document).ready(function(){
$(“#new”).click(function() {
$(“#captcha”).attr(“src”, “captcha.php?”+Math.random());
});
});
</script>
</head>
<body>
<?php
if(empty($_POST))
{
echo ‘
<form method=”post” action=”index.php”>
<span style=”float: left;margin-top: 7px;margin-right:10px;”>CAPTCHA Code:</span>
<img src=”captcha.php” border=”0″ alt=”CAPTCHA!” id=”captcha”><a href=”#new” id=”new”><img src=”reload.png” style=”width: 35px;margin-left:10px;” /></a>
<br />
Enter CAPTCHA: <input type=”text” name=”key” value=”” />
<br /><br />
<input type=”submit” value=” Verify Captcha ” />
</form>’;
}
else
{
if(strlen($_SESSION[‘key’]) && $_POST[‘key’] == $_SESSION[‘key’])
{
echo “Captcha Verified!!!”;
}
else
{
echo “Invalid Captcha…. <a href=’index.php’>try again</a>”;
}
}
?>
</body>
</html>

captcha.php

File contains PHP Code to generate captcha image.

<?php
session_start();

class CaptchaSecurityImages {
/* select the type of font, must be used in directoy in which script is being called into */
var $font = ‘CALIBRI.TTF’;

function generateCode($characters) {
$possible = ‘23456789ABCDEFGHJKLMNPQRSTUVWXYZ’;
$possible = $possible.$possible.’2345678923456789′;
$code = ”;
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}

function CaptchaSecurityImages($width = 145,$height = 35, $characters = 6) {
$code = $this->generateCode($characters);
$font_size = $height * 0.60;
$image = @imagecreate($width, $height) or die(‘Cannot initialize new GD image stream’);

/* set the colours */
$bgR = mt_rand(0, 255); $bgG = mt_rand(0, 255); $bgB = mt_rand(0, 255);
$background_color = imagecolorallocate($image, $bgR, $bgG, $bgB);
$noise_color = imagecolorallocate($image, abs(100 – $bgR), abs(100 – $bgG), abs(100 – $bgB));
$text_color = imagecolorallocate($image, abs(255 – $bgR), abs(255 – $bgG), abs(255 – $bgB));

/* generate random dots in background */
for($i = 0; $i < ($width*$height) / 3; $i++) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}

/* generate random lines in background */
for($i = 0; $i < ($width*$height) / 150; $i++) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}

/* set random colors */
$w = imagecolorallocate($image, abs(100 – $bgR), abs(100 – $bgG), abs(100 – $bgB));
$r = imagecolorallocate($image, abs(100 – $bgR), abs(100 – $bgG), abs(100 – $bgB));

/* Draw a dashed line, 5 red pixels, 5 white pixels */
$style = array($r, $r, $r, $r, $r, $w, $w, $w, $w, $w);
imagesetstyle($image, $style);
imageline($image, 0, 0, $width, $height, IMG_COLOR_STYLED);
imageline($image, $width, 0, 0, $height, IMG_COLOR_STYLED);

/* create random polygon points */
$values = array(
mt_rand(0, $width), mt_rand(0, $height),
mt_rand(0, $height), mt_rand(0, $width),
mt_rand(0, $width), mt_rand(0, $height),
mt_rand(0, $height), mt_rand(0, $width),
mt_rand(0, $width), mt_rand(0, $height),
mt_rand(0, $height), mt_rand(0, $width),
mt_rand(0, $width), mt_rand(0, $height),
mt_rand(0, $height), mt_rand(0, $width),
mt_rand(0, $width), mt_rand(0, $height),
mt_rand(0, $height), mt_rand(0, $width),
mt_rand(0, $width), mt_rand(0, $height),
mt_rand(0, $height), mt_rand(0, $width),);

/* create Random Colors then set it to $clr */
$r = abs(100 – mt_rand(0, 255));
$g = abs(100 – mt_rand(0, 255));
$b = abs(100 – mt_rand(0, 255));
$clr = imagecolorallocate($image, $r, $g, $b);

/* create filled polygon with random points */
imagefilledpolygon($image, $values, 6, $clr);

$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die(‘Error in imagettfbbox function’);
$x = ($width – $textbox[4])/2;
$y = ($height – $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die(‘Error in imagettftext function’);

/* pretty it */
imageantialias($image, 100);
imagealphablending($image, 1);
imagelayereffect($image, IMG_EFFECT_OVERLAY);

/* output captcha image to browser */
header(‘Content-Type: image/jpeg’);
imagejpeg($image);
imagedestroy($image);
$_SESSION[‘key’] = $code;
}
}

$captcha = new CaptchaSecurityImages(145, 35, rand(4, 6));

?>

Also you need jquery-1.8.0.min.js file.

 

Add iRates in iPhone/iPad application

1)Download iRate.bundle form https://github.com/nicklockwood/iRate
Add iRate.bundle, iRate.h, iRate.m
Add StoreKit.framework from Build phases

2)#import “iRate.h” in AppDelegate.h/AppDelegate.m

3)AppDelegate.h/AppDelegate.m
#pragma mark – delegate methods for iRates
– (void)iRateCouldNotConnectToAppStore:(NSError *)error
{
}

– (void)iRateDidDetectAppUpdate
{
}

– (BOOL)iRateShouldShouldPromptForRating
{
return 0;
}

– (void)iRateUserDidAttemptToRateApp
{
}

– (void)iRateUserDidDeclineToRateApp
{
}

– (void)iRateUserDidRequestReminderToRateApp
{
}

– (BOOL)iRateShouldopenAppStore
{
return 0;
}

+ (void)initialize
{
[iRate sharedInstance].daysUntilPrompt = 5;
[iRate sharedInstance].usesUntilPrompt = 15;
}

Page turn effect using UIPageViewController

The UIPageViewController class was introduced into the iOS 5 SDK as a mechanism to implement a page turning style of user interface in iOS applications. The UIPageViewController is a highly configurable class that it lets developers to configure:

the orientation of the page views – vertical or horizontal
the transition style – page turning style or a dot based style
the axis (spine) on which the page will turn

Follow below steps:
Step 1: Create new NSObject file with name ImageModel

ImageModel.h

– (id)initWithImageName:(NSString *)imageName;
@property (nonatomic, strong) NSString *imageName;
@property (nonatomic) NSInteger rating;

ImageModel.m
– (id)initWithImageName:(NSString *)imageName
{
self = [super init];
if (self)
{
_imageName = imageName;
_rating = 0;
}

return self;
}

Step 2: Create new UIViewController file with name ImageViewController

ImageViewController.h

#import
#import “ImageModel.h”

@interface ImageViewController : UIViewController

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *label;

@property (nonatomic, strong) ImageModel *model;

@end

ImageViewController.m

#import “ImageViewController.h”

@implementation ImageViewController

– (void)viewDidLoad
{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor clearColor]];

CGRect insetFrame = CGRectMake(20, 80, self.view.frame.size.width – 40, self.view.frame.size.height – 100);

_imageView = [[UIImageView alloc] initWithFrame:insetFrame];
_imageView.backgroundColor = [UIColor clearColor];
[_imageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[_imageView setImage:[UIImage imageNamed:_model.imageName]];
[[self view] addSubview:_imageView];
}

Step 3: Add in you mainViewController where you showing images

in .h file add

NSMutableArray *modelArray;

@property (nonatomic, retain) UIPageViewController *pageViewController;
@property (nonatomic, retain) NSMutableArray *modelArray;
@property (nonatomic) NSInteger vcIndex;
@property (nonatomic, strong) UIStepper *rateStepper;
@property (nonatomic, strong) UILabel *imageLabel;

– (void)stepperValueChanged:(id)sender;

in .m file add

#import “ImageViewController.h”

self.modelArray = [[NSMutableArray alloc] init];

[self.modelArray addObject:@”Image1.png”];
[self.modelArray addObject:@”Image2.png”];
[self.modelArray addObject:@”Image3.png”];
[self.modelArray addObject:@”Image4.png”];
[self.modelArray addObject:@”Image5.png”];

_pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];

_pageViewController.view.frame = CGRectMake(-5, 0, 568.0f, 585.0f);
_pageViewController.delegate = self;
_pageViewController.dataSource = self;

ImageViewController *imageViewController = [[ImageViewController alloc] init];
imageViewController.model = [self.modelArray objectAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:imageViewController];

[self.pageViewController setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];

[self addChildViewController:_pageViewController];
[GlobalView addSubview:_pageViewController.view];

Add below delegate methods:

#pragma mark –
#pragma mark – Private Methods
– (void)stepperValueChanged:(id)sender
{
ImageModel *model = [self.modelArray objectAtIndex:_vcIndex];
[model setRating:[_rateStepper value]];
[_imageLabel setText:[NSString stringWithFormat:@”%@ – Rating: %d”, model.imageName, model.rating]];
}

#pragma mark –
#pragma mark – UIPageViewControllerDelegate Method

– (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
ImageViewController *contentVc = (ImageViewController *)viewController;

NSUInteger currentIndex = [self.modelArray indexOfObject:[contentVc model]];
_vcIndex = currentIndex;
[_rateStepper setValue:[[contentVc model] rating]];
ImageModel *model = [self.modelArray objectAtIndex:_vcIndex];
[_imageLabel setText:[NSString stringWithFormat:@”%@ – Rating: %d”, model.imageName, model.rating]];

if (currentIndex == 0)
{
return nil;
}

ImageViewController *imageViewController = [[ImageViewController alloc] init];
imageViewController.model = [self.modelArray objectAtIndex:currentIndex – 1];
return imageViewController;
}

– (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
ImageViewController *contentVc = (ImageViewController *)viewController;

DLog(@”%d”, [self.modelArray count]);

NSUInteger currentIndex = [self.modelArray indexOfObject:[contentVc model]];
_vcIndex = currentIndex;
[_rateStepper setValue:[[contentVc model] rating]];
ImageModel *model = [self.modelArray objectAtIndex:_vcIndex];
[_imageLabel setText:[NSString stringWithFormat:@”%@ – Rating: %d”, model.imageName, model.rating]];

if (currentIndex == self.modelArray.count – 1)
{
return nil;
}

ImageViewController *imageViewController = [[ImageViewController alloc] init];
imageViewController.model = [self.modelArray objectAtIndex:currentIndex + 1];
return imageViewController;
}

#pragma mark –
#pragma mark – UIPageViewControllerDataSource Method

– (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return self.modelArray.count;
}

– (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
Nie będziemy wyjaśniały to już ogromna wygrana dla siebie, poza tym, jeśli przedtem graliście na automaty i przy realnej grze, ona ­na żal będzie różnił się! W jakimkolwiek wypadku niech fortuna uśmiecha się nie liczcie na rachunku nawet trochę środków, we wszystko nie pograsz, a . kasyno za darmo Nie będziemy wyjaśniały to już ogromna wygrana dla każdego hazard postrzega się ­rozmaicie.Można tylko powiedzieć, że przedstawione powyżej są obecne w której można zużyć realne pieniądze.Przecież mając na pieniądze i przy realnej grze, ona ­na żal będzie różnił się! W jakimkolwiek wypadku niech fortuna uśmiecha się ­rozmaicie.Można tylko powiedzieć, .

Convert non ARC files in ARC application and vice versa

1)If your application is ARC (Automatic Reference Counting),
and try to use non arc files it will give you error,
Then do this – Select Target – > Build phases -> Compile sources
Double click on file which you want and write – (-fno-objc-arc)

2)If your application is NonARC,
and try to arc files,
Then do this – Select Target – > Build phases -> Compile sources
Double click on file which you want and write – (-fobjc-arc)

Get a list of all contacts on iOS

#import <AddressBook/AddressBook.h>

#import <AddressBookUI/AddressBookUI.h>

CFErrorRef *error = NULL;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, error);
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex numberOfPeople = ABAddressBookGetPersonCount(addressBook);

for(int i = 0; i < numberOfPeople; i++) {

ABRecordRef person = CFArrayGetValueAtIndex( allPeople, i );

NSString *firstName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonFirstNameProperty));
NSString *lastName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonLastNameProperty));
NSLog(@”Name:%@ %@”, firstName, lastName);

ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);

for (CFIndex i = 0; i < ABMultiValueGetCount(phoneNumbers); i++) {
NSString *phoneNumber = (__bridge_transfer NSString *) ABMultiValueCopyValueAtIndex(phoneNumbers, i);
NSLog(@”phone:%@”, phoneNumber);
}

NSLog(@”=============================================”);

}

How to disable Copy , Paste, selectAll, select etc… action for UITextView

Its very simple 🙂 🙂

Step 1:
Create SubClass file with name CustomUITextView for UITextView

In .m file write below code

– (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(selectAll:) || action == @selector(select:) ||action == @selector(copy:) || action == @selector(paste:))
{
return NO;
}

return NO;
}

Step 2: Add below code

translationLable = [[CustomUITextView alloc] initWithFrame:CGRectMake(15, 50, 240, 245 + 38)];
translationLable.text = @”wordString”;
translationLable.delegate = self;
//translationLable.numberOfLines = 20;
translationLable.backgroundColor = [UIColor clearColor];
//[translationLable sizeToFit]; //R-60, G-66, B-70
translationLable.textColor = [UIColor colorWithRed:60.0/255.0 green:66.0/255.0 blue:70.0/255.0 alpha:1.0];
translationLable.editable = FALSE;
translationLable.font = [UIFont fontWithName:@”MyriadPro-Light” size:18.0];
translationLable.dataDetectorTypes = UIDataDetectorTypeLink;
[self.view addSubview:translationLable];

Tap on UITextView and get exact word from text using UITapGestureRecognizer

UITapGestureRecognizer is a concrete subclass of UIGestureRecognizer that looks for single or multiple taps. For the gesture to be recognized, the specified number of fingers must tap the view a specified number of times.

Lets see how it work for UITextView.

in .h file add below code
@interface MMExampleRightSideDrawerViewController : MMExampleSideDrawerViewController

in .m file add below code

UITextView *translationLableNew = [[UITextView alloc] initWithFrame:CGRectMake(0, 23, 240, 195 – 23)];
translationLableNew.text = @”WordString pass here”;
translationLableNew.userInteractionEnabled = TRUE;
translationLableNew.delegate = self;
translationLableNew.backgroundColor = [UIColor clearColor];
translationLableNew.editable = FALSE;
translationLableNew.font = [UIFont fontWithName:@”MyriadPro-Light” size:18.0];
[self.view addSubview:translationLableNew];

UITapGestureRecognizer *tapTextView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapRecognized:)];
tapTextView.delegate = self;
[translationLableNew addGestureRecognizer:tapTextView];

//Add Below Method:

– (void)singleTapRecognized:(UITapGestureRecognizer *)recognizer
{
NSLog(@”Single Tap”);
UITextView *textView_New = (UITextView *)recognizer.view;
CGPoint pos = [recognizer locationInView:textView_New];
NSLog(@”Tap Gesture Coordinates: %.2f %.2f”, pos.x, pos.y);
UITextPosition *tapPos = [textView_New closestPositionToPoint:pos];
UITextRange * wr = [textView_New.tokenizer rangeEnclosingPosition:tapPos withGranularity:UITextGranularityWord inDirection:UITextLayoutDirectionRight];

NSLog(@”WORD: %@”, [textView_New textInRange:wr]);
NSString *selectedText = [textView_New textInRange:wr];
NSLog(@”selectedText: %@”, selectedText);

}

  • 1
  • 2