4:37 PM

Origin of Logs

Posted by pradeep T

Links
http://logbase2.blogspot.com/2007/12/log-base-2.html


History of Logarithms
Logarithms were invented independently by John Napier, a Scotsman, and by Joost Burgi, a Swiss. Napier's logarithms were published in 1614; Burgi's logarithms were published in 1620. The objective of both men was to simplify mathematical calculations. This approach originally arose out of a desire to simplify multiplication and division to the level of addition and subtraction. Of course, in this era of the cheap hand calculator, this is not necessary anymore but it still serves as a useful way to introduce logarithms. Napier's approach was algebraic and Burgi's approach was geometric. The invention of the common system of logarithms is due to the combined effort of Napier and Henry Biggs in 1624. Natural logarithms first arose as more or less accidental variations of Napier's original logarithms. Their real significance was not recognized until later. The earliest natural logarithms occur in 1618.
It can’t be said too often: a logarithm is nothing more than an exponent. The basic concept of logarithms can be expressed as a shortcut........ Multiplication is a shortcut for Addition: 3 x 5 means 5 + 5 + 5
Exponents are a shortcut for Multiplication: 4^3 means 4 x 4 x 4
Logarithms are a shortcut for Exponents: 10^2 = 100.
The present definition of the logarithm is the exponent or power to which a stated
number, called the base, is raised to yield a specific number.
The logarithm of 100 to the base 10 is 2. This is written: log10 (100) = 2.
Before pocket calculators — only three decades ago, but in “student years” that’s the age of dinosaurs — the answer was simple. You needed logs to compute most powers and roots with fair accuracy; even multiplying and dividing most numbers were easier with logs. Every decent algebra books had pages and pages of log tables at the back.
The invention of logs in the early 1600s fueled the scientific revolution. Back then scientists, astronomers especially, used to spend huge amounts of time crunching numbers on paper. By cutting the time they spent doing arithmetic, logarithms effectively gave them a longer productive life. The slide rule, once almost a cartoon trademark of a scientist, was nothing more than a device built for doing various computations quickly, using logarithms. See Eli Maor’s e: The Story of a Number for more on this.
Today, logs are no longer used in routine number crunching. But there are still good reasons for studying them. Why do we use logarithms, anyway?
• To find the number of payments on a loan or the time to reach an investment goal
• To model many natural processes, particularly in living systems. We perceive loudness
of sound as the logarithm of the actual sound intensity, and dB (decibels) are a logarithmic scale. We also perceive brightness of light as the logarithm of the actual light energy, and star magnitudes are measured on a logarithmic scale.
• To measure the pH or acidity of a chemical solution. The pH is the negative logarithm of the concentration of free hydrogen ions.
• To measure earthquake intensity on the Richter scale.
• To analyze exponential processes. Because the log function is the inverse of the
exponential function, we often analyze an exponential curve by means of logarithms. Plotting a set of measured points on “log-log” or “semi-log” paper can reveal such relationships easily. Applications include cooling of a dead body, growth of bacteria, and decay of a radioactive isotopes. The spread of an epidemic in a population often follows a modified logarithmic curve called a “logistic”.
• To solve some forms of area problems in calculus.
(The area under the curve 1/x, between x=1 and x=A, equals ln A.)

1:54 PM

Algos Problems

Posted by pradeep T

Prime number computation
topological sorting - library of machine parts- each part should be placed in the order of useage
dynamic programming - DNA Matching - (A,B,C,D,F) .. (B,C,D) close match
convex hull or convex envelope
discrete Fourier transforms

1:16 PM

Links for DS

Posted by pradeep T

http://cgm.cs.mcgill.ca/~godfried/teaching/algorithms-web.html
http://sbge.tripod.com/DSIndex.html
http://www.cs.berkeley.edu/~jrs/61b/lec/07
http://www.cs.auckland.ac.nz/~jmor159/PLDS210/ds_ToC.html

Finite automata
Computation Theory
Complexity Theory

1:12 PM

Smart pointers

Posted by pradeep T

To be smarter than regular pointers, smart pointers need to do things that regular pointers don't. What could these things be? Probably the most common bugs in C++ (and C) are related to pointers and memory management: dangling pointers, memory leaks, allocation failures and other joys. Having a smart pointer take care of these things can save a lot of aspirin...

The simplest example of a smart pointer is auto_ptr, which is included in the standard C++ library. You can find it in the header , or take a look at Scott Meyers' auto_ptr implementation. Here is part of auto_ptr's implementation, to illustrate what it does:

template class auto_ptr
{
T* ptr;
public:
explicit auto_ptr(T* p = 0) : ptr(p) {}
~auto_ptr() {delete ptr;}
T& operator*() {return *ptr;}
T* operator->() {return ptr;}
// ...
};
As you can see, auto_ptr is a simple wrapper around a regular pointer. It forwards all meaningful operations to this pointer (dereferencing and indirection). Its smartness in the destructor: the destructor takes care of deleting the pointer.

9:39 PM

UIActivity Indicator

Posted by pradeep T

- (void) createProgressionAlertWithMessage:(NSString *)message withActivity:(BOOL)activity
{
progressAlert = [[UIAlertView alloc] initWithTitle: message
message: @"Please wait..."
delegate: self
cancelButtonTitle: nil
otherButtonTitles: nil];

// Create the progress bar and add it to the alert
if (activity) {
activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityView.frame = CGRectMake(139.0f-18.0f, 80.0f, 37.0f, 37.0f);
[progressAlert addSubview:activityView];
[activityView startAnimating];
} else {
progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(30.0f, 80.0f, 225.0f, 90.0f)];
[progressAlert addSubview:progressView];
[progressView setProgressViewStyle: UIProgressViewStyleBar];
}
[progressAlert show];
[progressAlert release];
}

9:38 PM

UIElements Complete Tutorials

Posted by pradeep T

UITextField

Code:
UITextField *username =[[UITextField alloc] initWithFrame:CGRectMake(24.5, 65, 270, 30)];
username.delegate=self;
username.textAlignment=UITextAlignmentCenter;
username.borderStyle=UITextBorderStyleRoundedRect;
username.placeholder=@"Username\n";
username.autocorrectionType=UITextAutocorrectionTypeNo;
username.autocapitalizationType=UITextAutocapitalizationTypeNone;
[self.view addSubview:username];
UIActionSheet
Code:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"This is where the information will go"
delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil
otherButtonTitles:@"Email", @"Tech Support",@"Website",@"Cancel", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
actionSheet.destructiveButtonIndex = 3; // make the second button red (destructive)
[actionSheet showInView:self.view];
[actionSheet release];
Selecting a button on UIActionSheet
Code:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0){
// do stuff
}
}

UISwitch
Code:
UISwitch *switchIt = [[UISwitch alloc] initWithFrame:CGRectZero];
switchIt.on=NO;
[self.contentView addSubview:switchIt];
UILabel
Code:
UILabel *usernameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
usernameLabel.text=@"Personal Location Checkin";
usernameLabel.adjustsFontSizeToFitWidth=YES;
[self.contentView addSubview:usernameLabel];
UISearchBar
Code:
UISearchBar *mySearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, 45)];
mySearchBar.delegate = self;
mySearchBar.showsCancelButton = YES;
mySearchBar.barStyle=UIBarStyleBlackOpaque;
mySearchBar.placeholder=@"Enter Name or Phone Number";
mySearchBar.keyboardType=UIKeyboardTypeNamePhonePad;


[self.view addSubview: mySearchBar];
UIView
Code:
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor grayColor];
self.view = contentView;
[contentView release];
UITableView
Code:
UITableView *myBeaconsTableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 45, self.view.bounds.size.width, 375)];
myBeaconsTableView.delegate=self;
myBeaconsTableView.dataSource=self;

[self.view addSubview:myBeaconsTableView];
Or to make a grouped table view (like in preferences)

Code:
UITableView *settingsTableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 40, self.view.bounds.size.width, 375) style:UITableViewStyleGrouped];
settingsTableView.delegate=self;
settingsTableView.dataSource=self;
[self.view addSubview:settingsTableView];
UINavigationBar
Plain no Title
Code:
myNavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, 45)];
[self.view addSubview:myNavBar];
Black Opaque (no title)
Code:
myNavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, 45)];
myNavBar.barStyle=UIBarStyleBlackOpaque;
[self.view addSubview:myNavBar];
Black Translucent (no title)
Code:
myNavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, 45)];
myNavBar.barStyle=UIBarStyleBlackTranslucent;
[self.view addSubview:myNavBar];
To add title and other buttons

Code:
UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:@"Around Me"];
[myNavBar pushNavigationItem: navItem];
To add buttons with image
Code:
refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(action:)];
[navItem setLeftBarButtonItem:refreshButton];
Add button with Text
Code:
refreshButton = [[UIBarButtonItem alloc] initWithTitle:@"About Us" style:UIBarButtonItemStyleBordered target:self action:@selector(action:)];
[navItem setRightBarButtonItem:refreshButton];
How to add comments
Code:
When you want to add a comment about a line of code you do this

// Comment

To do a multi-lined comment you would do this

/* This
is
multi-lined
comment
*/
UIWebView
Code:
dailyWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 45, self.view.bounds.size.width, 375)];
dailyWebView.delegate=self;
dailyWebView.scalesPageToFit=YES;
[dailyWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];
[self.view addSubview:dailyWebView];
UITextView
Code:
UITextView *textView = [[[UITextView alloc] initWithFrame:frame] autorelease];
textView.textColor = [UIColor blackColor];
textView.font = [UIFont fontWithName:@"Helvetica" size:15];
textView.delegate = self;
textView.backgroundColor = [UIColor whiteColor];

textView.text = @"TEXT TO GO IN HERE";
[self.view addSubView:textView];

UISegmentedControl
Code:
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:
[UIImage imageNamed:@"segment_check.png"],
[UIImage imageNamed:@"segment_search.png"],
[UIImage imageNamed:@"segment_tools.png"],
nil]];
frame = CGRectMake( 0,
0,
self.view.bounds.size.width,
35);
segmentedControl.frame = frame;
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
segmentedControl.selectedSegmentIndex = 1;
[self.view addSubview:segmentedControl];
UIAlertView
Code:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" message:@"Your message"
delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Button1", @"Button2", nil];
[alert show];
[alert release];
This is just some UI elements that can be added through code

11:04 AM

Device Orientation && UILABLE ROTATE

Posted by pradeep T

I have got my own custom UIViewController, which contains a UIScrollView with an UIImageView as it's subview. I would like to make the image to auto rotate when device orientation changes, but it doesn't seem to be working...

In the header file, I've got;

@interface MyViewController : UIViewController {
IBOutlet UIScrollView *containerView;
UIImageView *imageView;
}
These components are initialised in the loadView function as below;

containerView = [[UIScrollView alloc] initWithFrame:frame];

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://..."]];
UIImage *image = [[UIImage alloc] initWithData:data];
imageView = [[UIImageView alloc] initWithImage:image];
[image release];

[containerView addSubview:imageView];
And I have added the following method, assuming that's all I need to make the view auto-rotate...

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
MyViewController loads fine with the image I've specified to grab from the URL, and the shouldAutorotate... function is being called, with the correct UIInterfaceOrientation, when I flip the device too.

However, didRotateFromInterfaceOrientation method do not get called, and the image doesn't seem to rotate itself... Could someone please point out what I need to add, or what I have done wrong here?


UILABLE ROTATE :

/*************************
As August said, I'm not sure of your use case on this, but there's a reasonably straightforward way to do it using Core Animation. First, you'll need to add the QuartzCore framework to your project and do a

#import
somewhere in your headers.

Then, you can apply a rotational transform to your UILabel's underlying layer using the following:

yourLabel.layer.transform = CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f);
which will rotate the label's CALayer by 180 degrees (pi radians) about the Y axis, producing the mirror effect you're looking for.