Thursday, September 5, 2019

AWS Lambda function for Fibonacci recursive function

Here I will show you how to run a simple recursive function in AWS lambda.

1) Login to AWS console.
2) Select Lambda from services menu.
3) Select "Create Function" button on the page.
4) Select "Author from scratch" option and enter the function details as shown in the screenshot.
 Provide a name to your function, select Python 3.7 in the runtime and choose the option to "Create a new role with basic Lambda permissions".













5) This will create the function and bring up the following screen with the ARN displaying on top right.













6) Paste the following code in the code editor. This code is to calculate a fibincacci for a passed in number.

import json

def lambda_handler(event, context):
    return getFibonacci(event.get("item"));
#return result;
  
def getFibonacci(n):
    if(n == 0):
        return 0
    else:
        if(n == 1):
            return n 
        else:
            if(n > 1):
                return getFibonacci(n-1) + getFibonacci(n-2)


Code is also available at  https://github.com/singadi/awslambda/blob/master/pythonFibonacci.py

7) Testing
Configure a test event by selecting the test event from the dropdown as show below.







Create the test event as show


8) Select this new test event and test your function. You should see the following in your execution result log.







Hope this helps you with creating a simple AWS lambda function.

Thursday, July 21, 2011

iAdd sample for Monotouch app.

This sample shows how to display a banner Add on a montouch app.
I'm using a simple example to show the use of AdBannerView control.
Create a sample Iphone Navigation-based project from Monodevelop.
In Main.cs/AppDelegate class/FinishedLaunching() method add the following code.

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
        ADBannerView banner = new ADBannerView(); 
        banner.CurrentContentSizeIdentifier = "ADBannerContentSizePortrait";
        banner.AdLoaded += delegate(object sender, EventArgs e) {
        banner.Hidden = false;
        };
        banner.FailedToReceiveAd += delegate(object sender, AdErrorEventArgs e) {
        banner.Hidden = true;
        };
        banner.Frame = new System.Drawing.RectangleF(0, 30, 320, 50);
        navigationController.Add(banner);
        window.AddSubview (navigationController.View);
        window.MakeKeyAndVisible ();
        return true;
}

The banner must be set to "ADBannerContentSizePortrait" or "ADBannerContentSizeLandscape" using CurrentContentSizeIdentifier property. In this example I'm only targeting portrait layout.
There are two delegates associated with the banner.
FailedToReceiveAd - This is when there is no connection between the app and the iAdd server, the banner is hidden in this case.
AdLoaded - When the iAdd server sends the Add content to display, this is then showed on the Add.




Tuesday, February 1, 2011

Hide Right Bar(EDIT) Button of MoreNavigationController of a UITabBarController using Monotouch

To remove the Edit button from the "More" Navigation controller in a UITabBarController as shown.



First assign a delegate class to the instance of the MoreNavigatioController in the AppDelegate class

tabBarController.MoreNavigationController.Delegate = new MoreNavigationControllerDelegate();


public partial class AppDelegate : UIApplicationDelegate
{
  TabBarController tabBarController;
  // This method is invoked when the application has loaded its UI and its ready to run
  public override bool FinishedLaunching (UIApplication app, NSDictionary options)
  {
     // Create the tabs
      tabBarController = new TabBarController ();
      tabBarController.MoreNavigationController.Delegate = new MoreNavigationControllerDelegate();
   
     // Create the main window and add the navigation controller as a subview
      window = new UIWindow (UIScreen.MainScreen.Bounds);
      window.AddSubview(tabBarController.View);
      window.MakeKeyAndVisible ();
      return true;
  }

  // This method is required in iPhoneOS 3.0
  public override void OnActivated (UIApplication application)
  {
  }
}
 


  • Add a new class "MoreNavigationControllerDelegate" to the project.
  • This class should implement "UINavigationControllerDelegate".
  • Add an override method  "WillShowViewController" to this class - This method is called whenever its time to load the MoreNavigation view controller.
  • Set the RightBarButtonItem to null in this method.
The following code in "WillShowViewController" method will hide "Edit" button in the "More" controller of UITabBarController.

public class MoreNavigationControllerDelegate : UINavigationControllerDelegate
 {
  public MoreNavigationControllerDelegate () : base()
  {
  }
  
  public override void WillShowViewController (UINavigationController navigationController, UIViewController viewController, bool animated)
  {
   if(navigationController.NavigationBar.TopItem.Title == "More")
    navigationController.NavigationBar.TopItem.RightBarButtonItem = null;
  }
 }



Note- I have the condition if(navigationController.NavigationBar.TopItem.Title == "More"), since I still want to show the right bar button when I select the "Motivation", "Tips" and "Glossary" view controller as shown below.


Thursday, December 9, 2010

Monotouch - Set custom RGB colors.

If you have a custom color with its corresponding RGB values, you can create a new UIColor variable by using the following code.

   float red = 0.0f;           // Defines the red component of the color object. This range is from 0.0f to 255.0f
   float green = 255.0f;       // Defines the green component of the color object. This range is from 0.0f to 255.0f
   float blue = 0.0f;          // Defines the blue component of the color object. This range is from 0.0f to 255.0f
   float alpha = 1.0f;         // Defines the opacity value of the color object. This range is from 0.0f to 1.0f

   UIColor newColor = new UIColor(red/255.0f, green/255.0f, blue/255.0f, alpha);
 

Following website is helpful if you are looking for RGB values for a color.
http://www.colorschemer.com/online.html

Wednesday, November 10, 2010