Tuesday, July 19, 2016

iOS Unit Test case

Below are some of the disadvantages

More code: In projects with high test coverage it’s possible to have more test code than functional code.
More to maintain: When there is more code, there is more to maintain.
No silver bullet: Unit tests don’t (and can’t) ensure that your code is free of bugs.
Takes longer: Writing tests takes time — time you could spend learning new exciting stuff on raywenderlich.com!

Below are some of the advantages however

Confidence: You can demonstrate that your code works.
Quick feedback: You can use unit tests to quickly validate code that is buried many layers deep in your app navigation — things that are cumbersome to test manually.
Modularity: Unit tests help keep you focused on writing more modular code.
Focus: Writing tests for micro features keep you focused on the small details.
Regression: Be sure that the bugs you fixed stay fixed — and aren’t broken by subsequent fixes.
Refactoring: Until Xcode gets smart enough to refactor your code on its own, you’ll need unit tests to validate your refactoring.
Documentation: Unit tests describe what you think the code should do; they serve as another way to document your code.


references:

Monday, July 18, 2016

iOS Localization

Normally, below are the items localized

The text in the storyboards
The cover image
The dynamic message displayed by code
The name of the app as displayed in home screen

The "Message" given here is optional. "BOOK_PURCHASE" is checked in the Localizable string and they are substituted here. If not found, "BOOK_PURCHASE" itself will be displayed. 

- (IBAction)buy:(id)sender
{
    [[[UIAlertView alloc] initWithTitle:@"Confirmation"
                                message:NSLocalizedString(@"BOOK_PURCHASE", @"Message")
                               delegate:nil
                      cancelButtonTitle:@"OK"
                      otherButtonTitles:nil] show];
}

references:

iOS Using Unit Tests

Xcode supports three main types of testing. Functional tests focus on code functionality. Performance tests focus on measuring execution time. User Interface tests focus on flows through the user interface. Functional and performances tests are functions that you write. Each function sets up an environment for the test, executes the targeted parts of the app, and tears down the test environment. User interface tests are recordings you make as you use your app.

A test case exercises a unit of code in a specific way or measures a specific part of your app’s performance; if the result of the test is different from the expected result, the test case fails. A test suite is made up of a set of test cases

When you create a project or a target, Xcode includes a unit test target in the scheme that builds the app. The implementation file for the target includes stubs for the setUp, tearDown, and testExample methods. Complete these stub implementations and add other code as necessary to perform unit tests on your app.

references:

Wednesday, July 13, 2016

How Does the AAAA DNS response look like?


It looks like below

Frame 514: 182 bytes on wire (1456 bits), 182 bytes captured (1456 bits) on interface 0
Ethernet II, Src: 00:6c:bc:3c:e3:d6 (00:6c:bc:3c:e3:d6), Dst: Apple_c3:e1:a2 (78:31:c1:c3:e1:a2)
Internet Protocol Version 4, Src: 10.238.35.20, Dst: 10.238.64.113
User Datagram Protocol, Src Port: 53 (53), Dst Port: 49184 (49184)
Domain Name System (response)
    [Request In: 512]
    [Time: 0.007250000 seconds]
    Transaction ID: 0x81b7
    Flags: 0x8180 Standard query response, No error
    Questions: 1
    Answer RRs: 2
    Authority RRs: 0
    Additional RRs: 0
    Queries
        dualstack.pr-my-78232.us-east-1.elb.amazonaws.com: type AAAA, class IN
            Name: dualstack.pr-my-78232.us-east-1.elb.amazonaws.com
            [Name Length: 66]
            [Label Count: 6]
            Type: AAAA (IPv6 Address) (28)
            Class: IN (0x0001)
    Answers
        dualstack.pr-my-78232.us-east-1.elb.amazonaws.com: type AAAA, class IN, addr 9404:ba00:dd00::36b1:9f98
            Name: dualstack.pr-my-78232.us-east-1.elb.amazonaws.com
            Type: AAAA (IPv6 Address) (28)
            Class: IN (0x0001)
            Time to live: 59
            Data length: 16
            AAAA Address: 9404:ba00:dd00::36b1:9f98
        ddualstack.pr-my-78232.us-east-1.elb.amazonaws.com: type AAAA, class IN, addr 9404:ba00:dd00::36b1:9f97
            Name: dualstack.pr-my-78232.us-east-1.elb.amazonaws.com
            Type: AAAA (IPv6 Address) (28)
            Class: IN (0x0001)
            Time to live: 59
            Data length: 16

            AAAA Address: 9404:ba00:dd00::36b1:9f97

Tuesday, July 12, 2016

Running a Sails App - Installing dependancies

When trying to start a Sails App, it resulted in below few errors

module.js:327
    throw err;
    ^

Error: Cannot find module 'request-promise'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)


This appeared to be because some of the modules are not installed. This could get resolved by installing packages 
using the commands such as below 

npm install request-promise


references:

iOS 10 CallKit

In iOS 10, Callkit gives permission to integrate VOIP (voice over internet protocol) apps with the iPhone user interface, therefore user can give answer of VOIP app on iPhone lock screen as well as view contacts of VOIP app in the phone app’s favorites and recent views. 

Apple has given a SpeakerBox Example app as a reference to implement this, which is here


references

Sunday, July 10, 2016

Anatomy of a Sails app

API folder : This folder contains the vast majority of your app's back-end logic. It is home to the 'M' and 'C' in MVC Framework.

Controllers: Controllers contain most of the back-end logic for your app.
Models: Models are the structures that contain data for your Sails App.
Policies: Policies are typically used to authenticate clients and restrict access to certain parts of your app.
Responses: Server response logic (404 - Not Found, 500 - Server Error, etc)
Services: Services are similar to controller actions. They contain logic that used by your app that doesn't necessarily rely on .req() and .res().

references:

What is Amazon SES

Amazon Simple Email Service (Amazon SES) is a cost-effective email service built on the reliable and scalable infrastructure that Amazon.com developed to serve its own customer base. With Amazon SES, you can send transactional email, marketing messages, or any other type of high-quality content to your customers. You can also use Amazon SES to receive messages and deliver them to an Amazon S3 bucket, call your custom code via an AWS Lambda function, or publish notifications to Amazon SNS. With Amazon SES, you have no required minimum commitments – you pay as you go, and you only pay for what you use.

references:



What is Amazon SNS?

Amazon Simple Notification Service (Amazon SNS) is a web service that coordinates and manages the delivery or sending of messages to subscribing endpoints or clients. In Amazon SNS, there are two types of clients—publishers and subscribers—also referred to as producers and consumers. Publishers communicate asynchronously with subscribers by producing and sending a message to a topic, which is a logical access point and communication channel. Subscribers (i.e., web servers, email addresses, Amazon SQS queues, AWS Lambda functions) consume or receive the message or notification over one of the supported protocols (i.e., Amazon SQS, HTTP/S, email, SMS, Lambda) when they are subscribed to the topic.




When using Amazon SNS, you (as the owner) create a topic and control access to it by defining policies that determine which publishers and subscribers can communicate with the topic. A publisher sends messages to topics that they have created or to topics they have permission to publish to. Instead of including a specific destination address in each message, a publisher sends a message to the topic. Amazon SNS matches the topic to a list of subscribers who have subscribed to that topic, and delivers the message to each of those subscribers. Each topic has a unique name that identifies the Amazon SNS endpoint for publishers to post messages and subscribers to register for notifications. Subscribers receive all messages published to the topics to which they subscribe, and all subscribers to a topic receive the same messages.

references:

Saturday, July 9, 2016

Installing Sails on Mac

First ran the command 
sudo npm -g install sails 

after the sails framework is installed successfully, 

Run the command to create a test project 
sails new testProject

This created the below directory structure 

api => This contains directories such as controllers, models, policies, responses, services. In this only policies and responses contain some of the default information. 
assets => This folder contained js, favicon.ico, images, styles, templates, robots.txt  
config => Config contained lot of files, this seems to be the config files for the APIs which applications can use. For e.g. policies.js, socket.js http.js etc
node_modules => This seems to contain the library files 
tasks => 
views 
app.js
Gruntfile.js
package.son
README.md

After this, just had to run the command 
sails lift 

the above command needs to be run from the same directory as the project root, in this case “testProject” 

Now by default, this brings up the server on the port 1337 accessible like below 
http://localhost:1337/

references:

Google Powerpoint How to rotate text?

To rotate the text, basic idea is to create a shape, and add text inside and rotate the shape itself
this rotate shape can be put inside the actual content and can be placed. 

references:

What is Sails

Sails is, of course, a web framework. But take a step back. What does that mean? Sometimes, when we refer to the "web", we mean the "front-end web." We think of concepts like web standards, or HTML 5, or CSS 3; and frameworks like Backbone, or Angular, or jQuery. Sails is not "that kind" of a web framework. Sails works great with Angular and Backbone, but you would never use Sails instead of those libraries.

On the other hand, sometimes when we talk about "web frameworks", we mean the "back-end web." This evokes concepts like REST, or HTTP, or WebSockets; and technologies like Java, or Ruby, or Node.js. A "back-end web" framework helps you do things like build APIs, serve HTML files, and handle hundreds of thousands of simultaneous users. Sails is "that kind" of web framework.

Loose coupling with Sails 
Sails allow us to pick and choose the components that fit our requirements. In fact, it’s just plain lazy to create things any other way. Sails’s approach is to loosely couple components so that they can be added or subtracted from your app at will. Node at its core has created a “can do” culture eager to experiment and make things work. 

Sails accomplishes this loose coupling using plain-old require. No magic, other than the time to craft components that can be part of the whole but don’t need to be present in order for the whole to work. For example, controllers, models, and configuration files are just Node modules. Sails uses some convention to help.

Sails picks up on the name UserController.js in the Controllers folder to deduce that this is indeed a user controller. Another example involves policies. So policies allow you to have a bit of code that executes on controller or specific controller action. The cool part is that the configuration file that connects the policy with the controller/action are separate. That means you can write a bunch of different policies and they are completely portable between Sails apps.

Almost every component of Sails can either be omitted, overwritten, or extended. For example, Sails has a group of tools called blueprints. These blueprints make it really easy to get a project up and running with regard to routes and CRUD operations. But suppose you want to use the read, update, and delete operations but the create action needs some tender loving care. No problem, just build a create action and the other CRUD operations keep working. Your custom action subs in for the blueprint action. It’s just that simple. 

That Simple?  I would need to try this! 

references:

Wednesday, July 6, 2016

Android Audio Focus notes

Every app that plays audio must get the audio session before playing the audio 

for this the code is as below 

private void requestAudioFocusAndStartPlayer(boolean isResume)
{
    abandonAudioFocus();
    mAudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
    if(mAudioManager  != null)
    {
        int result = mAudioManager.requestAudioFocus(this,AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
        if(result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED)
        {
            Log.i(TAG,"Audio Focus request not granted result:"+result);
            stopPlayer();
        }
        else
        {
            if(isResume) {
                resumePlayer();
            }
            else
            {
                startPlayer();
            }
        }
    }
}

references:

Monday, July 4, 2016

El Captain - Do not see NAT 64 option?

It seems that we have to press Option Key while pressing Internet sharing when selecting the Sharing panel options on the left hand listing. 
On Windows keyboard, this seems to be Ctrl Key. With this, the NAT64 check box appear below the window. 

Btw, this option does appear only on El captains and not anything below this. 

references:

Sunday, July 3, 2016

Android Crash View not attached to window manager

java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355)
at android.view.WindowManagerImpl.updateViewLayout(WindowManagerImpl.java:191)
at android.view.Window$LocalWindowManager.updateViewLayout(Window.java:428)
at android.app.Dialog.onWindowAttributesChanged(Dialog.java:596)
at android.view.Window.setDefaultWindowFormat(Window.java:1013)

This looks to be because dismissing say a dialog which is not attached to Window yet. 

Below was the solution 

if(dialog != null && dialog.isShowing())
{
dialog.dismiss();
}

references:

Using Whats app web

This was pretty easy, Just select Whats App Web from the phone Whats app app
scan the QR Code, and then on the web page, the whole conversations appear! 

references: