Sunday, September 30, 2018

Firebase Storage - How to attach timestamp to the pushed record?

Below is the code snippet for it

public class Member {
    private String name; //name of the member
    private String ID; //email for e.g
    private Map timestamp;
    private String fireBaseKey;

    public String getName(){return this.name;}
    public String getID(){return this.ID;}
    public Map getTimestamp() {return timestamp;}
    public String getFireBaseKey(){return this.fireBaseKey;}

    public void setName(String name){this.name = name;}
    public void setID(String ID){this.ID = ID;}
    public void setTimestamp(Map ts) {this.timestamp= ts;}
    public void setFireBaseKey(String key){this.fireBaseKey = key;}
}



Map map = new HashMap();
map.put("timestamp", ServerValue.TIMESTAMP);

Member member = new  Member();
member.setID(userID);
member.setName(name);
member.setTimestamp(ServerValue.TIMESTAMP);

DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();
        String pathName = APP_NAME + "/" + conversation.getConversationPath();
        final DatabaseReference messagesRef = databaseReference.child(pathName).child(conversation.getFbRecordKey()).child("members");
        messagesRef.push().setValue(member);


Saturday, September 29, 2018

Javascript some quirks

the first one is for loop. In the below, the value idx is index into the array and not the object itself. coming from

for (idx in result){
    var obj = result[idx];
}

another surprise was the year from Date object

var sDate = startTimeField.getYear() +"-"+(startTimeField.getMonth()) +"-"+ startTimeField.getDate();

the output is 118-8-29, though expected outcome was 2018-9-29

Below code gives this result. getFullYear is different from getYear!

var sDate = startTimeField.getFullYear() +"-"+(startTimeField.getMonth()+1) +"-"+ startTimeField.getDate();


Thursday, September 27, 2018

What is cloudwatch?

Amazon CloudWatch monitors your Amazon Web Services (AWS) resources and the applications you run on AWS in real time. You can use CloudWatch to collect and track metrics, which are variables you can measure for your resources and applications. CloudWatch alarms send notifications or automatically make changes to the resources you are monitoring based on rules that you define. For example, you can monitor the CPU usage and disk reads and writes of your Amazon EC2 instances and then use this data to determine whether you should launch additional instances to handle increased load. You can also use this data to stop under-used instances to save money. In addition to monitoring the built-in metrics that come with AWS, you can monitor your own custom metrics. With CloudWatch, you gain system-wide visibility into resource utilization, application performance, and operational health.


Amazon CloudWatch console — https://console.aws.amazon.com/cloudwatch/
AWS CLI — For more information, see Getting Set Up with the AWS Command Line Interface in the AWS Command Line Interface User Guide.
CloudWatch API — For more information, see the Amazon CloudWatch API Reference.
AWS SDKs — For more information, see Tools for Amazon Web Services.


Below are the related services to the cloudwatch

Amazon Simple Notification Service (Amazon SNS) coordinates and manages the delivery or sending of messages to subscribing endpoints or clients. You use Amazon SNS with CloudWatch to send messages when an alarm threshold has been reached. For more information, see Set Up Amazon SNS Notifications.
Amazon EC2 Auto Scaling enables you to automatically launch or terminate Amazon EC2 instances based on user-defined policies, health status checks, and schedules. You can use a CloudWatch alarm with Amazon EC2 Auto Scaling to scale your EC2 instances based on demand. For more information, see Dynamic Scaling in the Amazon EC2 Auto Scaling User Guide.
AWS CloudTrail enables you to monitor the calls made to the Amazon CloudWatch API for your account, including calls made by the AWS Management Console, AWS CLI, and other services. When CloudTrail logging is turned on, CloudWatch writes log files to the Amazon S3 bucket that you specified when you configured CloudTrail. For more information, see Logging Amazon CloudWatch API Calls with AWS CloudTrail.
AWS Identity and Access Management (IAM) is a web service that helps you securely control access to AWS resources for your users. Use IAM to control who can use your AWS resources (authentication) and what resources they can use in which ways (authorization). For more information, see Authentication and Access Control for Amazon CloudWatch.

references
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html

Wednesday, September 26, 2018

An Alternative to everymac - iPhone models

Interestingly when iPhone XS and XR released, i was trying to get the model number of these and was unable to get from everymac.com , the usual site idepend on. But there seems to be another site which is below

https://gist.github.com/adamawolf/3048717

The model properties are

iPhone11,4: iPhone XS Max
iPhone11,6: iPhone XS Max China

iPhone11,8: iPhone XR
iPhone11,2: iPhone XS                       

Tuesday, September 25, 2018

Opening Containing app from Today extension

self.extensionContext?.open(URL(string: "appscheme://")!, completionHandler: nil)

In the containing app, the scheme needs to be defined.

Also in the app delegate, below to be implemented as well

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool
    {
        if url.scheme == "appscheme"
        {
// navigate to appropriate areas in the app.     
        }
        return true
    }

Even without having the above method implemented, it will launch the app. However, it won't be able to navigate to specific areas until the code is in place for it.

Implementation wise, one can just have the button on the today widget main interface.storyboard file and link it to the TodayViewController and handle the actions via IBaction outlets. It is pretty easy.

references:
https://hackernoon.com/app-extensions-and-today-extensions-widget-in-ios-10-e2d9fd9957a8

Today widget Content update life cycle

To help your widget look up to date, the system occasionally captures snapshots of your widget’s view. When the widget becomes visible again, the most recent snapshot is displayed until the system replaces it with a live version of the view.

widgetPerformUpdate :
called when widget is updated in background.
called before widget snapshot is taken.

func widgetPerformUpdate(completionHandler: @escaping (NCUpdateResult) -> Swift.Void)
    {
        completionHandler(.newData)
    }

references:
https://hackernoon.com/app-extensions-and-today-extensions-widget-in-ios-10-e2d9fd9957a8

Whats different in iOS 10 for Today Extensions?

In iOS 8 and iOS 9, Show More/Show Less needed to be handled explicitly by the developers. It was a tedious task since it required constraint and layout handling to adjust the widget’s height according to the content. But in iOS 10, Apple provided APIs to handle such functionality without taking much pain.

NCWidgetDisplayMode
There exist 2 modes in which you can display data in your widget. These modes are categorized under NCWidgetDisplayMode as compact and expanded.
Compact mode has a fixed height of 110 and
Expanded mode is used for variable height according to your content.
Show More or Show Less buttons are shown in the widget’s top right corner according to the widget’s active display mode i.e. in compact mode, show more is visible and in expanded mode, show less is visible.

override func viewDidLoad()
    {
        super.viewDidLoad()
        self.extensionContext?.widgetLargestAvailableDisplayMode = .expanded
    }

widgetLargestAvailableDisplayMode signifies the largest display mode supported by your app.
When set to compact, your app will only support compact mode i.e. show more/show less functionality will no longer be supported and your widget will have a fixed height of 110.
When set to expanded, the app will support both compact and expanded mode and show more/show less functionality will work accordingly.


Handling Height according to Display Mode
NCWidgetProviding protocol provides a delegate method widgetActiveDisplayModeDidChange(_: maxSize:) that handles the size of the widget in compact and expanded mode.
Width of the widget remains same according to the device you are using. There is no provision provided to change it.
Height of the widget can be changed according to the active display mode.

func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize)
    {
        if activeDisplayMode == .expanded
        {
            preferredContentSize = CGSize(width: 0.0, height: 220)
        }
        else
        {
            preferredContentSize = maxSize
        }
    }

references:
https://hackernoon.com/app-extensions-and-today-extensions-widget-in-ios-10-e2d9fd9957a8