Monday, June 25, 2018

Notes about a few common codecs

Below given is a compilation of various codecs.



Sunday, June 24, 2018

Android - How to hide app icon



references:
https://readyandroid.wordpress.com/hideunhide-app-icon-programmatically-android/

Nginx How to specify the certificate chain

Providing the certificate chain is pretty easy.


Git find which branch contains a commit

to find which branches in a repo contains a commit with given commit id, below command can be used

git branch --contains  

for e.g.

git branch --contains e1eb22f630a659c0ce1eb22f630a659c0c

Type of AWS load balancing

Application Load Balancer
Application Load Balancer is best suited for load balancing of HTTP and HTTPS traffic and provides advanced request routing targeted at the delivery of modern application architectures, including microservices and containers. Operating at the individual request level (Layer 7), Application Load Balancer routes traffic to targets within Amazon Virtual Private Cloud (Amazon VPC) based on the content of the request.

Network Load Balancer
Network Load Balancer is best suited for load balancing of TCP traffic where extreme performance is required. Operating at the connection level (Layer 4), Network Load Balancer routes traffic to targets within Amazon Virtual Private Cloud (Amazon VPC) and is capable of handling millions of requests per second while maintaining ultra-low latencies. Network Load Balancer is also optimized to handle sudden and volatile traffic patterns.

Classic Load Balancer
Classic Load Balancer provides basic load balancing across multiple Amazon EC2 instances and operates at both the request level and connection level. Classic Load Balancer is intended for applications that were built within the EC2-Classic network.

references:
https://aws.amazon.com/elasticloadbalancing/?sc_channel=PS&sc_campaign=acquisition_IN&sc_publisher=google&sc_medium=load_balancing_b&sc_content=aws_load_balancer_e&sc_detail=aws%20load%20balancer&sc_category=load_balancing&sc_segment=159808182919&sc_matchtype=e&sc_country=IN&s_kwcid=AL!4422!3!159808182919!e!!g!!aws%20load%20balancer&ef_id=WNq5gAAAAI0yW6dy:20180625011629:s

Wednesday, June 13, 2018

Flutter get started - Installation

This below gives some notes from my attempt to get Started with installation on Mac OSX.
Does not seem like a heavy system requirement for installing the SDK, which is great.

It asked to download the SDK which is a zip file. and extract it and add it to the tool path.
Then a series of instruction as mentioned in the link was followed and basically got the app running
the first app that i could run was flutter gallery. Amazing to say in one word! rich set of ui components


export PATH=`pwd`/flutter/bin:$PATH

Set up the iOS simulator

open -a Simulator
brew update
brew install --HEAD libimobiledevice
brew install ideviceinstaller ios-deploy cocoapods
pod setup

tried to directly run it was not working in Xcode
but then ran the flutter run command and then opened in the Xcode using the workspace and it worked.

references:
https://flutter.io/get-started/

What is bearer token authentication

Bearer authentication (also called token authentication) is an HTTP authentication schemethat involves security tokens called bearer tokens. The name “Bearer authentication” can be understood as “give access to the bearer of this token.” The bearer token is a cryptic string, usually generated by the server in response to a login request. The client must send this token in the Authorization header when making requests to protected resources:

Authorization: Bearer

The Bearer authentication scheme was originally created as part of OAuth 2.0 in RFC 6750, but is sometimes also used on its own. Similarly to Basic authentication, Bearer authentication should only be used over HTTPS (SSL).

references:
https://swagger.io/docs/specification/authentication/bearer-authentication/

Tuesday, June 12, 2018

DTMF - A bit of details

Dual Tone Multi Frequency, or DTMF as it is popularly known, is the technical term for the sound frequencies produced when a telephonic key is pressed.
DTMF also known as touch tone was primarily used for telephone signaling to and from the local exchange, though today it finds several applications in the field of telecommunications and call centers.
A different frequency is assigned to each key in the telephone and there are two tones – one low frequency and another high frequency – that are played simultaneously when a key is pressed. This combination of two tones makes it nearly impossible to reproduce by the human voice.

Each of the four rows of keys in a telephone is assigned a low frequency tone and each of the three columns is assigned a high frequency tone. A fourth column of keys labeled as A, B, C, and D is optional and is mostly used in military networks.

A bit of history :
Research on DTMF was initiated by Bell labs in the late fifties in an attempt to allow tone signals for long distance dialing. DTMF was being developed as the future of electronic telecommunications as opposed to the mechanical telecommunication networks that were prevalent at that time.

DTMF was introduced on November 18, 1963 under the trademark of ‘Touch Tone’ by Bell Systems. The first Touch Tone telephone was the Western Electric model 1500 with ten buttons, which was introduced on the same year. Using audio tones for signaling was not new and the Multi‐Frequency signaling (MF) which was used by telephone exchanges for communicating with each other using in‐band signaling was already around. Multi‐frequency signaling uses a combination of two pure sine wave frequencies for signaling. Both CCITT and Bell System devised various MF signaling protocols. The in‐band signaling between exchanges was based on a sixteen‐digit keypad, which a telephone operator used to input the next leg of the destination telephone number for connecting to the downstream telephone operator. This semi‐automated signaling and switching technology had the twin advantage of cost and time effectiveness as it was faster and cheaper to use MF.

The initial research team had also examined the possibility of accessing computers through telephone lines and surveyed several companies to identify their needs for this. The # (hash) and *(star) keys were added based on the inputs received. A set of lettered keys A, B, C, and D were also added to facilitate menu selection, though it was later dropped from most phones.

The technology side of it : DTMF is a very reliable means of signaling used by telecom companies to process information from customers. Whenever a number is dialed, the DTMF is decoded by the local exchange in order to route the call.

DTMF can be transmitted over telephone lines as well as over the internet. The tones are decoded on the receiving end and used for practical applications such as interacting with computer systems and answering machines. The interaction with a computer system is achieved using an IVR system. Over a regular landline, DTMF is sent as audio signals. DTMF tones are transmitted through the same wires that carry the voice signals. In the case of mobile phones, DTMF tones can be generated only after the connection is established. This feature is often used by call centers for gathering inputs from callers for selection of IVR menus, capturing account information for phone banking facilities and so on. In a VoIP phone, DTMF is transmitted as a data packet over the internet, however this is prone to errors such as echo or packet loss during transmission, distorting the data and making it difficult to rebuild the key press combination at the receiving end.

DTMF technology supports acoustic transfer. This means that DTMF tones can be transmitted by a standard speaker and received by a standard microphone.

Speech recognition technologies are another alternative used by call centers to offer the callers more flexibility for providing inputs during a call. However, speech recognition technologies have still a long way to go to achieve a high degree of accuracy and therefore most call centers prefer DTMF for user inputs as it is more reliable. The flip side of using DTMF is that with just 16 distinct tones, there are a limited number of permutations that can be used to transmit information.

DTMF Frequencies
There are sixteen DTMF signals, each of which is made up of two tones from eight different frequency signals. Twelve of these are commonly used by consumers with four being reserved for military use or use by exchanges. The keys A, B, C, D are usually absent from telephone sets used in homes and offices. These keys are system tones used for configuring telephone exchanges and to carry out special functions. The DTMF keypad for consumer use is designed in a four‐row by three‐ column matrix. Each dial row is represented by a low tone frequency and each column by a high tone frequency.

The frequencies used are 697 Hz, 770 Hz, 852 Hz, 941 Hz, 1209 Hz, 1336 Hz, 1477Hz, and 1633 Hz. The frequencies were carefully chosen in such a way as to prevent harmonics. Thus, one can notice that no frequency is a multiple of another and the difference or sum between any two frequencies is not equal to any other frequency. The frequencies were initially designed with a ratio of 21/19, which is slightly less than a whole tone.

Additionally, the frequencies generated have to be within an error tolerance of 1.5% and the higher frequency is transmitted at 3 dB louder to compensate for any high frequency roll‐off. The pair of signals represents the digit or symbol at the intersection of the row and column. For example, if the digit 5 has to be sent, the frequencies transmitted are 1336 Hz and 770 Hz in a sinusoidal combination.



It is necessary that transmission paths are linear and distortion free in order to permit the accurate transmission of DTMF signals. Any distortion between the source and the decoder can result in inter‐modulation products and consequent unreliable decoding. An example is the 2A‐B inert modulation calculation where a distortion in the transmission path can cause a star (941 Hz and 1209 Hz) to be decoded as a pound (941 and 1477). Here A = 1209 and B = 941 and the formula will give 2A‐B = 1477 which represents a pound.


references:
https://www.specialtyansweringservice.net/wp-content/uploads/resources_papers/dtmf-tone/Dual-Tone-Multi-Frequency-Signalling.pdf

DTMF programming

There are several ways in which DTMF sequences can be used to program characters. The table below shows how alphabets and numerals can be transmitted using a standard DTMF sequence.
However, the sequence varies with the equipment or application that is being used. The above table shows the sequence on a standard 3X4 keypad where the digit 1 has no corresponding alphabet value and every other digit has three or four alphabets and one numerical digit associated with them. However, if a keypad were designed in such a way as to assign an alphabetic value to the 1 key, then all other values would change accordingly

When programming with DTMF, the tones are usually repeated until the specific character is displayed in the display panel of the equipment. Once a character is entered a * or # is entered before the next character is programmed. The * key is used for deleting characters and # is used to indicate a new character, though this can vary with the characteristics of the receiving equipment. Apart from programming words, DTMF strings can be also used to perform certain functions on an application or equipment.




references:
https://www.specialtyansweringservice.net/wp-content/uploads/resources_papers/dtmf-tone/Dual-Tone-Multi-Frequency-Signalling.pdf


VoIP and DTMF

There are multiple ways in which DTMF tones are transmitted over a VoIP connection. These include:

Inband – In this method, the DTMF tones are transmitted just as normal voice audio using the same codec and with no special coding to identify it as different from the voice.
RFC2833 – In this case, DTMF is transmitted based on the defined standards for DTMF tones, fax tones etc.
SIP signaling – This can be done only through SIP channels where DTMF tones are transmitted through an SIP message after a handshake with the receiving end for negotiating preferences and establishing the parameters for the call.

DTMF over VoIP is more prone to errors, as the receiving end often fails to recognize the DTMF or interprets it incorrectly. One of the possible causes of trouble is when there is switching between in‐band DTMF and RFC2833 modes in the VoIP route. For example, assume a VoIP device is transmitting an in‐band DTMF signal and a switch converts it to RFC2833 DTMF for further transmission, which finally terminates in a system that requires a regeneration of the in‐band audible tones. Sometimes, the switch fails to completely remove the audible DTMF tones while converting to RFC2833, thus resulting in a combined garbled message received by the voicemail system, causing it to report an error.

Yet another cause of concern is packet loss, which creates issues in DTMF over VoIP transmissions. Changing the DTMF settings is one way of troubleshooting such problems, and the RFC2833 DTMF setting is the most reliable. The in‐band DTMF where the G729 codec is used is the most un‐reliable due to compression related issues.

So, in terms of SIP, how is this RFC 2833 stream created and managed?  Through Session Description Protocol (SDP), of course.  SDP is used to describe the voice stream (e.g. G.729) and it’s also used to inform the recipient that RFC 2833 is available.  Specifically, it uses something called telephone-event.  Here is an example of an SDP media description that you might see in the body of an Invite message.  Note the format of “0 – 16.”  This represents the ten digits plus *, #, A, B, D, E, and Flash.

m=audio 12346 RTP/AVP 101
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16

That’s probably about as much as you really need to understand about RFC 2833 and how it works.  Its purpose is to create a separate stream for DTMF to allow voice codecs to strictly deal with creating the best possible voice stream using the fewest number of bytes.  If you remember that you will be ahead of the game.

references:
https://www.specialtyansweringservice.net/wp-content/uploads/resources_papers/dtmf-tone/Dual-Tone-Multi-Frequency-Signalling.pdf

Wednesday, June 6, 2018

iOS 12 Machine Learning

Apple introduced Core ML2. This said to enable apps to be built with intelligence.

In addition to supporting extensive deep learning with over 30 layer types, it also supports standard models such as tree ensembles, SVMs, and generalized linear models. Because it’s built on top of low level technologies like Metal and Accelerate, Core ML seamlessly takes advantage of the CPU and GPU to provide maximum performance and efficiency. You can run machine learning models on the device so data doesn't need to leave the device to be analyzed.

Machine learning includes vision APIs too. Supported features include face tracking, face detection, landmarks, text detection, rectangle detection, barcode detection, object tracking, and image registration.

The Natural Language framework is a new framework apps can use to analyze natural language text and deduce its language-specific metadata. Apps can use this framework with Create ML to train and deploy custom NLP models.

Core ML work with Core ML Models, Apple has provided tools to create new models or use some of the existing ones

references:
https://developer.apple.com/machine-learning/

R - A language and environment for statistical computing!

R is a language and environment for statistical computing and graphics. It is a GNU project which is similar to the S language and environment which was developed at Bell Laboratories (formerly AT&T, now Lucent Technologies) by John Chambers and colleagues. R can be considered as a different implementation of S. There are some important differences, but much code written for S runs unaltered under R.

R is an integrated suite of software facilities for data manipulation, calculation and graphical display. It includes

an effective data handling and storage facility,
a suite of operators for calculations on arrays, in particular matrices,
a large, coherent, integrated collection of intermediate tools for data analysis,
graphical facilities for data analysis and display either on-screen or on hardcopy, and
a well-developed, simple and effective programming language which includes conditionals, loops, user-defined recursive functions and input and output facilities.

R, like S, is designed around a true computer language, and it allows users to add additional functionality by defining new functions. Much of the system is itself written in the R dialect of S, which makes it easy for users to follow the algorithmic choices made. For computationally-intensive tasks, C, C++ and Fortran code can be linked and called at run time. Advanced users can write C code to manipulate R objects directly.

references
https://www.r-project.org/about.html

Sunday, June 3, 2018

Using Room Data Storage in Android

the database is accessed via an abstract class that is extended from RoomDatabase.
Below code can open the database and give a callback

There are three main components in this

1. Database access
2. Creating an entity
3. Mapping a Java object to SQL query (i.e. as a Dao)
4. Accessing the database via Repository

INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                            WordRoomDatabase.class, "word_database")
                            // Wipes and rebuilds instead of migrating if no Migration object.
                            // Migration is not part of this codelab.
                            .fallbackToDestructiveMigration()
                            .addCallback(sRoomDatabaseCallback)
                            .build();

 private static RoomDatabase.Callback sRoomDatabaseCallback = new RoomDatabase.Callback(){

        @Override
        public void onOpen (@NonNull SupportSQLiteDatabase db){
            super.onOpen(db);
            // If you want to keep the data through app restarts,
            // comment out the following line.
            new PopulateDbAsync(INSTANCE).execute();
        }
    };

like shown above, once the database is opened, Database is populated to read the contents from it.

Now how do we map a java object to an SQL query? This is done using the annotations. Below is a sample Dao

@Dao marks a class as data access object.


@Dao
public interface WordDao {

    // LiveData is a data holder class that can be observed within a given lifecycle.
    // Always holds/caches latest version of data. Notifies its active observers when the
    // data has changed. Since we are getting all the contents of the database,
    // we are notified whenever any of the database contents have changed.
    @Query("SELECT * from word_table ORDER BY word ASC")
    LiveData> getAlphabetizedWords();

    // We do not need a conflict strategy, because the word is our primary key, and you cannot
    // add two items with the same primary key to the database. If the table has more than one
    // column, you can use @Insert(onConflict = OnConflictStrategy.REPLACE) to update a row.
    @Insert
    void insert(Word word);

    @Query("DELETE FROM word_table")
    void deleteAll();
}


references:
https://developer.android.com/training/data-storage/room/

Friday, June 1, 2018

Javascript - Nesting function is good?

Nay! .. so far my reading goes, it is not . The reason is that in Javascript, every function is a value. with nested functions,

In a setup like below,

function foo(a, b) {
    function bar() {
        return a + b;
    }
    return bar();
}

foo(1, 2);

An outer function, foo(), contains an inner function, bar(), and calls that inner function to do work. Many developers forget that functions are values in JavaScript. When you declare a function in your code, the JavaScript engine creates a corresponding function object—a value that can be assigned to a variable or passed to another function. The act of creating a function object resembles that of any other type of value; the JavaScript engine doesn't create it until it needs to. So in the case of the above code, the JavaScript engine doesn't create the inner bar() function until foo() executes. When foo() exits, the bar() function object is destroyed.

The fact that foo() has a name implies it will be called multiple times throughout the application. While one execution of foo() would be considered OK, subsequent calls cause unnecessary work for the JavaScript engine because it has to recreate a bar() function object for every foo() execution. So, if you call foo() 100 times in an application, the JavaScript engine has to create and destroy 100 bar() function objects. Big deal, right? The engine has to create other local variables within a function every time it's called, so why care about functions?

references:
https://code.tutsplus.com/tutorials/stop-nesting-functions-but-not-all-of-them--net-22315

EJS partials and variables

Partials and variables allows one to define templates. for e.g. if an application want to send out an email in a predefined nice html but with a dynamically populated data, a template html can be defined inside which there can be partials or variables and do the below to generate a proper output html.

var template = ejs.compile(html);
var htmlToSend = template(dataObj.htmlData);

the difference between partial and variable is subtle in terms of syntax.

<%- %> => partial
<%= %> => variable

partials allows one to specify something that is not escaped. For e.g if the intention is to include a snippet, then snippet can be used. but if the intention is to replace only the variable, variable can be used.

references:
https://coligo.io/templating-node-and-express-apps-with-ejs/