Getting started with Android and Kotlin

Android Experience

With Google IO 2017, Google announced Kotlin as the officially supported language for Android.

Kotlin will be now shipped with Android Studio working out of the box, starting with version 3.0. No extra installations needed. No more incompatible plugins. All thanks to close collaboration between JetBrains and Google.

Why Kotlin?

Most importantly, it was because we think Kotlin is a great language that will make writing Android apps easier and more enjoyable.

Kotlin is also a great match for the existing Android ecosystem. It is 100% compatible with the Java programming language. We can add as little or as much Kotlin into our existing codebase as we want and mix the two languages freely within the same project.

A Quick Tour

here is a quick tour of some of the particularly appealing aspects of Kotlin:

1.Null Safety

One of the Kotlin’s best features is null safety. The Kotlin compiler enforces…

View original post 558 more words

Advertisements
Posted in General | Leave a comment

Feature Testing Using Capybara

techie

Feature testing is high level testing that allows us to go through our entire system, ensuring that each and every component is working perfectly fine. The test-cases written for it are termed as feature specs, which requires capybara.

In this blog, we will be focussing on writing feature specs using capybara with rspec. More specifically, we are going to look at capybara key features as well as, how capybara specs looks like.

We as a developer are mainly focussed about the underlying things, but we should also consider end user’s view. So, Capybara comes to rescue, it lets you write yours test-cases from user’s perceptive i.e, how end users would interact with your system. It is a ruby gem build on the top of underlying web-based driver and these drivers drive our browsers based on what our master ‘capybara’ says.

There are multiple web-drivers supported by capybara, some of…

View original post 568 more words

Posted in General | Leave a comment

Redirect HTTP to HTTPS when using ELB

Background – I have my site hosted on AWS EC2 server which is behind ELB (Elastic Load Balancing). I wanted my site to work on HTTPS. So I provisioned SSL certificate through AWS certificate manager and uploaded it on ELB. ELB receives traffic on both ports 80 and 443 and forwards it to single port 80 on server.

Setup – EC2 server, ELB, nginx, SSL certificate from AWS certificate manager, ROR

Problem – As port 80 is open on ELB, even non secure connection can be established to my site. To avoid this I had 2 choices

  1. Block port 80 and accept request only on port 443. But that is not a good user experience as he will always have to type https://  in url.
  2. Redirect all traffic coming to port 80 to port 443 so that connection gets converted to secure connection.

I decided to go with option 2 and then my search started on how to do it. After searching a lot I did not find single place which gave solution to my problem. But could get lot of pointers. After combining all these pointers I came up with following solution.

Solution –

Step 1- Forward traffic coming on port 80 of ELB and 443 to two different ports on server. In this example I am using port 8080 and 80. Forwarding traffic coming to port 80 of ELB to port 8080 of server and traffic coming on port 443 to port 80 of server.

Screen Shot 2017-06-21 at 11.08.35 AM

Allow inbound traffic for both ports 80 and 8080 on your server.

Screen Shot 2017-06-21 at 11.09.48 AM

Step 2 – Add 2 server blocks in nginx config as follows. Port 80 will serve actual site and port 8080 will be used to redirect traffic coming to it, to https.

server {

listen 80 default;
server_name http://www.mysite.com mysite.com;
root /www/mysite/current/public;
passenger_enabled on;
rails_env production;

. . . . . . . . .

}

server {

listen 8080;
return 301 https://www.mysite.com/$request_uri;

}

In case you have multiple domains then nginx server setup can be done as follows

server {

listen 80 default;
server_name sales.mysite.com sales.my-new-site.com;
root /www/mysite/current/public;
passenger_enabled on;
rails_env production;

. . . . . . . . .

}

server {

listen 8080;
server_name sales.mysite.com sales.my-new-site.com;
return 301 https://$host$request_uri;

}

I hope this will help you and save your time in doing this setup.

 

Posted in General | Leave a comment

SEO tricks to boost Rails application’s Google ranking

Planet Rails

You might be able to develop the greatest Ruby on Rails web application in the world… But is anyone going to find it?

The time is changing. Now your clients not only want well coded websites but they also need higher Google ranking for their website. In this blog, I intend to address how SEO can be done in RoR framework. Below are few techniques that can be used to improve website ranking.

Enable Server-side Compression

Website loading time plays an important role in Google Algorithm. The faster a web page loads, the better ranking it has on Google. Server-side compression is a simple way to speed up your website loading.

To implement this we need to add the following lines in nginx configuration file. Inside http block of your configuration file add the below lines.

I have used the most basic set of options for enabling Server-side compression. To…

View original post 605 more words

Posted in General | Leave a comment

Importance of Promise Object in angular js

Site Title

Hey guys, Writing this blog just to share an experience with you all. We have an input box which accepts keyword from user. We are sending api call to search that keyword, not when user enters full keyword, but when user enters a single character. And then it displays those keywords in drop-down.

We are using ngTagsInput plugin to add or select keyword. We send first api call when user enters first three characters and other calls are sent for each character entered by user. Due to this one issue occurs. Api responses are not received at same speed at which the user is entering the characters. So old response were displayed in the drop-down instead of new ones.

Ex. -> user entered ‘abcdef’, so, we have response for the api call which is given for ‘abcd’, but response for ‘abcde’ and ‘abcdef’ are pending. What we expect, is that…

View original post 388 more words

Posted in General | Leave a comment

Rails image_tag with Mustache template

amoludage

Recently I have been working on one rails project, In which I have used Mustache.js.

Mustache is a logic-less template which is used for client side dynamic template rendering.

You can check this link Mustache for more details.

As I’m rails developer it’s common to use image_tag for displaying images in rails, so I preferred to use image_tag for displaying images.

So when I was trying to use image_tag with mustache, I was surprised!! Why? Because, that image_tag was not working as expected. So I thought something is wrong with image_tag. And then I read more details about image_tag.

See below code…(In which image_tag was not working)

app/assets/javascripts/sample.coffee

app/views/sample.html.slim

After using above code I got compiled version of image_tag as below.

Then I realized that image_tag is compiled at server side & then it sends compiled(html tag) to the client side. But mustache template is compiled at client side. So the…

View original post 97 more words

Posted in General | Leave a comment

ProTips: Elastic Search & Rails

Learn with fun

In this blog post I am not going to tell you about how to setup elasticsearch with Rails. There are plenty of blog posts available for that. I referred this blog post to begin with elastic search and rails.

In this blog post, I will be showing how to set “ignore malformed” option. This may sound trivial but unfortunately the usage is neither in the ES-rails documentation nor I could find any content on the web.

I spent a few hours digging in the ES-rails code and finally deciphered it. Hope this helps you save the time.

Problem

Recently we started using elastic search in our project. One of the table had around 9 Million records. After configurations/setting we started the indexing. Monitored a few thousand records and indexes were correctly getting generated. However, at the end found out that the indexing of 5k records failed.  I was puzzled, why only…

View original post 566 more words

Posted in General | Leave a comment