Posts

Showing posts from 2017

Why Use Kotlin for Building Android Apps?

Kotlin is an officially supported language for building Android apps and this announcement came out at the  Google I/O 2017 . Kotlin isn't a language that was created a few months back, it has been around for 6 years. The creator of this language is JetBrains, the company that provides the best IDE's like IntelliJ IDEA, PyCharm for developers. Kotlin already has a considerable user base and these numbers will rise in the coming years. According to a prediction by Realm (the company behind the mobile-friendly database), Kotlin will overtake Java in December 2018 as the preferred language for Android app development. The report pointed out that the Android developers that are hesitant to learn Kotlin will face the same fate as the dinosaurs. Those are pretty harsh words, but if Oracle keeps creating issues , then Google will continue to push for better support for Kotlin. Many in the developer community see the current situation of apps building with Java or Ko

Create Your First Android Project with Kotlin

Image
Building Android apps with Kotlin is as simple as selecting an option when creating a project. For this you need Android Studio 3.0. Create a Kotlin Project: 1) Start a new project as you usually you do with Android Studio. 2) Here in the Create New Project window, you have to select the Include Kotlin Support option at the bottom. 3) The rest of the steps (selecting the SDK version, Selecting your starter activity and customizing it) remains the same. 4) Finally, click finish to create your first Kotlin project. Changes happened compared to Java project: 1) Instead of creating  MainActivity.java , the IDE now creates MainActivity.kt file. 2)  kotlin-android , kotlin-android-extensions plugins and appropriate dependency were added to the module level build.gradle file. apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib

Arithmetic Operations in Tensorflow

Image
In this article, we will learn about basic arithmetic operators supported by the Tensorflow. We will also perform these operations on the tensors and create a computational graph which can be viewed with the help of the Tensorboard. To get started, let's create two tensors of type constants. # Create two nodes node1 = tf.constant(35)  # dtype is int32 node2 = tf.constant(76)  # dtype is int32 You can add these two tensors using tf.add # Add node1 and node2 node_add = tf.add(node1, node2)  # dtype is int32 Ok now, lets learn how to subtract the two nodes. For this, I'm going to take our previous added result node_add as the first node and node3 as the second node. #  Create node3 node3 = tf.constant(11)  # dtype is int32 # Subtract node_add and node3 node_subtract = tf.subtract(node_add, node3)  # dtype is int32 Similarly, we use node_subtract, node4 for multiplication and node_multiply, node5 for division once we created the node4, node5. # Create node4 node4 =

How to Cast Integer to Float and Vice Versa in TensorFlow

In this article, we will learn to convert the data types of tensors to integer and float. First, let's create two nodes. node1 = tf.constant(5) # dtype is int32 node2 = tf.constant(6.0) # dtype is float32 Let's multiply the two nodes to create a new node node3 = tf.multiply(node1, node2) This will throw a TypeError: Input 'y' of 'Mul' Op has type float32 that does not match type int32 of argument 'x'. This is because the node1 data type is an integer while the data type of node2 is a float. Multiply method doesn't convert the types of its variables automatically. For now, we need to change them before performing any type of arithmetic operations on them. I hope this changes in the future releases. The correct way is to convert either of the node's type to match the other. Here, we are converting the node1 which is an integer to a float. tf.to_float(node1, name='ToFloat') Replacing the node1 with the above lin

TensorFlow - How to Use Placeholders

In this article, we will learn about Placeholders in TensorFlow, how to initialize them and how to pass the data to them. While Constants are used to feed data from inside the model, Placeholders are used to feed data from outside the model. In simpler terms, placeholders doesn't provide values while initializing, they are passed during the session. First, Initialize two placeholders. a = tf.placeholder(tf.float32) b = tf.placeholder(tf.float32) Take a look at the initialization, we aren't passing any value to the tensor. Next, let's add them. adder_node = tf.add(a, b) Now, Inside a session we can pass any number of inputs and the model performs operations and gives a value. # Add two numbers sess.run(adder_node, {a: 1.3, b: 5}) # Add two 1x2 matrices sess.run(adder_node, {a: [2, 8], b: [3, 5]}) Below is the code that initializes tensors with placeholders and passes the values at a later stage. Play with it for better understanding.

What is a Tensor Rank and Tensor Shape - TensorFlow

Image
In this article, we will learn about Tensor Ranks and Tensor Shapes. We know a tensor is an n-dimensional array. So, Rank is defined as the number of dimensions of that tensor. And, Tensor Shape represents the size of the each dimension. A tensor with rank 0 is a zero-dimensional array. The element of a zero-dimensional array is a point. This is represented as a Scalar in Math and has magnitude. Eg: s = 48.3 Shape - [] A tensor with rank 1 is a one-dimensional array. The elements of the one-dimensional array are points on a line. This line has magnitude, direction. and is represented as Vector in Math. Vector has n entries. Eg:  v = [1, 9, -6, 7, 0] Shape - [5] A tensor with rank 2 is a two-dimensional array. The elements of the two-dimensional array are lines on a surface. This surface is represented as a Matrix in Math and has two coordinates. The Matrix contains n x n entries. Eg: m = [[2.4, 5.1], [3.3, 7.9], [8.5, 6.1]] Shape - [3, 2] A tensor

How to Create Facebook Page

Image
Facebook pages are a great way to connect with your fans, brand loyalists, promote your cause and there are even more reasons to create a Facebook page. In this tutorial, we will learn to create a Facebook page. To get started, we need a Facebook account. 1. Go to Create a Page section of the Facebook. 2. Select a parent category for your page from the predefined six. Currently, these include i)   Local Business or Place ii)  Company, Organization or Institution iii) Brand or Product iv) Artist, Band or Public Figure v)  Entertainment vi) Cause or Community 3. Choose a sub category that matches your page after clicking on the drop down and give your page a name and address if you are a local business. 4. Finally, Click Get Started. That's it. Your page is successfully created. Now follow the page tips before you start sharing it with your friends and fans.

How to Create Facebook App

Image
In this tutorial, we will learn to create a Facebook app. To get started, you need a Facebook account. 1. Go to Facebook for developers website and log in if you haven't logged into your account. 2. In the top right-hand corner, hover over My Apps and click Add a New App. 3. Enter the name of the app, contact email and click Create App ID. That's it, you'll be taken to the Product Setup page. Here you can integrate various products offered by Facebook.

How to Update Circular Progressbar Color Endlessly

In this blog post, I'll be explaining how to change the color of an indeterminate circular progress bar not just once but every few seconds. This type of behavior is commonly seen in the Google's Inbox by Gmail app. It is simple to build. All we've to do is update the progress bar color every few seconds. This can be achieved by using the setIndeterminateTintList method and a Handler. The setIndeterminateTintList method changes the progress bar color while the handler makes sure this method is called continuously. Below is a sample code which mimics such behavior. One more thing to point out is that setIndeterminateTintList was added in API 21 which means it doesn't work on pre-lollipop devices. Only limited colors are added to the colorList and you can always add more colors or change the colors in the colorList. If you don't have the desired list of colors, you can randomize the color selection process. I hope this is helpful. If you guys know a b

Resources Not Found Exception in Android

There may be few newbies in Android programming having trouble understanding Resources Not Found Exception. So, I planned to explain it in this blog post and make the explanation as simple as I can. Resources Not Found Exception is thrown when the Resource API's failed to locate the resource. Let us go through an example to know in detail on why this exception is thrown. In this example, consider there is a text view on the UI which is used to show numbers from 10 to 1 and let's say we used a CountDownTimer class to achieve this task. If this was the code you've implemented, your app will crash when the onTick method gets executed for the first time. If you take a look at the log cat, you can see the API thrown a Resources Not Found Exception complaining that it cannot find the Strig Id. Simply, What this means is that the Resource API looked for a String named remainingTimeInSec and it failed to find it. This is because remainingTimeInSec is defined as int,