Vinsol is a Choice for Transforming The Software of Your Company!

At Vinsol, we consider ourselves pioneers instead of simple coders. This sets us apart from our competitors because it drives how we approach problem solving. With an extensive team of talented Ruby on Rails, iOS and Android developers, Vinsol can provide solutions that range from a few dedicated iOS resources to complete, end-to-end project implementations. We understand that every client is different and so, too, are their needs. This awareness in combination with our methodical approach has allowed us to satisfy clients in North America, Europe, Australia, Africa and Asia for over well over a decade.

We are delighted to announce that for the second year in a row Clutch has recognized us as one of the top developers in India. This year the report 2015 Top Web Developers India, showcases a series of outstanding developers with proven track records of client success. Continue reading

 

Writing command line programs in Elixir: Vowel Counter

Note: This is a very basic example of mix tool and escript utility. One can skip this post if already have an idea about these tools.

Lets write a simple command line program which would take a String as a command line argument and display the number of vowels in it. We’ll use Elixir’s mix build tool and OptionParser to parse command line arguments.

Lets start by setting up the application:

$ mix new vowel_counter

Open mix.exs, you will see something like:


defmodule VowelCounter.Mixfile do
  use Mix.Project

  def project do
    [app: :vowel_counter,
     version: "0.0.1",
     elixir: "~> 1.1",
     build_embedded: Mix.env == :prod,
     start_permanent: Mix.env == :prod,
     deps: deps]
  end

  # Configuration for the OTP application
  #
  # Type "mix help compile.app" for more information
  def application do
    [applications: [:logger]]
  end

  # Dependencies can be Hex packages:
  #
  #   {:mydep, "~> 0.3.0"}
  #
  # Or git/path repositories:
  #
  #   {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"}
  #
  # Type "mix help deps" for more examples and options
  defp deps do
    []
  end
end

We’ll be using Erlang’s escript utility to precompile our app and package our application’s code along with its dependencies(no dependencies in this example app) in one single executable. So lets add escript: escript_config to project method in our mix.exs to define our escript configuration, also define a private method escript_config to specify the the main_module. In this case, after these changes our mix.exs would look like:

defmodule VowelCounter.Mixfile do
  use Mix.Project

  def project do
    [app: :vowel_counter,
     version: "0.0.1",
     elixir: "~> 1.1",
     escript: escript_config, 
     build_embedded: Mix.env == :prod,
     start_permanent: Mix.env == :prod,
     deps: deps]
  end

  # Configuration for the OTP application
  #
  # Type "mix help compile.app" for more information
  def application do
    [applications: [:logger]]
  end

  # Dependencies can be Hex packages:
  #
  #   {:mydep, "~> 0.3.0"}
  #
  # Or git/path repositories:
  #
  #   {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"}
  #
  # Type "mix help deps" for more examples and options
  defp deps do
    []
  end

  defp escript_config do
    [main_module: VowelCounter]
  end
end

Lets compile and run our application by running:
$ mix escript.build
$ ./vowel_counter "my test string"

Since we have specified VovelCounter module as our main_module in elixir_config, our app expects and call the main method from this module and pass command line arguments to it. We haven’t defined this main method yet, so we should see something similar when we execute our app:

** (UndefinedFunctionError) undefined function: VowelCounter.main/1
    (vowel_counter) VowelCounter.main(["my test string"])
    (elixir) lib/kernel/cli.ex:76: anonymous fn/3 in Kernel.CLI.exec_fun/2

Lets open lib/vowel_counter.ex and define main method as:

defmodule VowelCounter do
  # Take command line arguments
  # Then parse them
  # Then count number of vowel
  # Print the outpu
  def main(args) do
    args 
      |> parse_args
      |> count_vowel
      |> IO.puts
  end

  defp parse_args(args) do
    # Covering only expected arguments. We can add code to handle cases when unexpected arguments are passed or help text etc.
    # Checkout OptionParser lib for details. 
    {_, [str], _} = OptionParser.parse(args)
    str
  end

  defp count_vowel(str) do
    # Scan for vowels and take the list's length
    len = length(Regex.scan(~r/[aeiou]/i, str))
    "There are #{len} vowels"
  end
end

Lets re-compile and re-run our application by:
$ mix escript.build
$ ./vowel_counter "This string has 5 vowels."
We should see: “There are 5 vowels”

Your comments/suggestions are most welcome.

 

Trying my hands on Elixir

Recently, I began spending some of my time with Elixir and started following Dave Thomas’ Programming Elixir. Though, I am half way through with the book and still don’t have a very good hold on the language but after reading about processes in Elixir, I thought to write something on my own so I wrote a small ping-pong program:


defmodule PingPong do
  import :timer
  @timer  500
  def ping(x) do
    receive do
      {pong_pid, n} when n <= x ->  IO.puts ("Ping #{n}")
                                        send pong_pid, { self, (n) }
                                        sleep @timer
                                        ping(x)
    end
  end

  def pong(x) do
    receive do
      {ping_pid, n} when n <= x -> IO.puts ("Pong #{n}")
                                        send ping_pid, {self, (n + 1) }
                                        pong(x)
    end
  end

  def run(n) do
    {ping_pid, _} = spawn_monitor(PingPong, :ping, [n])
    {pong_pid, _} = spawn_monitor(PingPong, :pong, [n])
    send ping_pid, {pong_pid, 1}

    receive do
      msg -> IO.puts "Message received: #{msg}"
    end
  end
end

PingPong.run(30)

I am pretty sure there is much scope of improvement but this is what I could write as of now. Your comments/suggestions are welcome, kindly add them below.

 

Net Neutrality – Is it Neutral?

What is Net Neutrality?

Net neutrality simply means that you are in control of what you do on the Internet. Net Neutrality is the principle that Internet Service Providers (ISPs) should not discriminate or promote any form of data over the internet. It prevents ISPs from charging differentially based on content, user, site, etc.

net-neutrality-money-drain-for-all

Why this fuss about Net Neutrality in India?

In December 2014, Airtel, a leading telecom network and ISP, changed its service terms for 2G and 3G data packs so that Voice over Internet Protocol (VoIP) data was excluded from the set amount of free data. So, Airtel would levy additional charges for making voice calls using Continue reading

 

Multiple-Databases In Single Rails Application

This is a simple post to list some of the challenges faced during multiple database setup in a single rails application. The content in the post is available over the internet, we have consolidated it here to bring it at one place.

While integrating multiple third party services we felt the need to store each and every pair of request-response shared between our application and others. We decided to use database tables to store this information instead of files or other options so to have an easy disintegration of data. This helped us in filtering for some particular handshakes based on certain scenarios. Also we could pick requests that failed to respond or if any request claimed to be sent to us but never did.

We thought it would be better to place this in a separate database to avoid clouding our main database. Plus we could also avoid picking up this content while backing up our already big database, as this was not that “critical”.

So we set our sails in this direction and Rails made it very easy by letting us set up different database connections for such classes/models.
Continue reading

 

Integrating Interswitch WebPay Payment Gateway With Rails

Interswitch WebPay is a leading Nigerian payment gateway and integrating WebPAY with any website is fairly simple. At a high level this integration can be achieved with following steps:

  • Calculate a request hash based on input parameters like transaction reference, amount, callback url etc. to ensure transaction integrity.
  • Provide a URL at which WebPAY would post back the authorization response (callback url).
  • POST these transaction details to WebPAY page
  • Once the transaction is done, query the transaction details directly from WebPAY to ensure the actual transaction amount and the transaction status.

To integrate WebPay with any rails application seamlessly we have extracted the code into WebPay Interswitch Gem. Continue reading

 

Migrating from Protected Attributes to Strong Parameters

In Rails3, we use attr_accessible or attr_protected(Protected Attributes) to white-list attributes of a model for mass assignment.
In Rails4, Protected Attributes was moved out as a Gem and similar feature was implemented at the controller level, which is now known as Strong Parameters.

We were migrating one of our project from Rails3 to Rails4 and decided to use Rails’ Strong Parameter instead of using the Protected Attributes Gem. While migrating from Protected Attributes to Strong Parameters we found ourself in a situation where we were repeating the same code. To elaborate, in Rails3 when we used Protected Attribute, all our white-listed attributes were at one place i.e. in the model itself. But when we used Strong Parameters, all these attributes of model came into the controllers, so if we had more than one controller dealing with same model, we were repeating the code for white-listing attributes in each controller. Continue reading

 

EmberJS: Snagged by belongsTo association

Writing Javascript code using MVC framework and rendering templates at client side is the new fancy way of writing web applications. As they say, when Rails is the backend, Emberjs at frontend is a good fit.

The beauty of the architecture along with our excitement has impelled us to dive into this framework. It started with revamping of an eCommerce site by building its version-2 using Emberjs as frontend framework and Rails as an api server. Initially, everything was working fine and we were enjoying our Emberjs learning and implementation, but in the following scenario belongsTo association has become a stumbling block for us.

Before we talk about the obstacle, let us share what tools we are using and how we are trying to integrate Emberjs and Rails.

Continue reading

 

Custom Edit Control for UITableViewCell

In one of my recent iOS project I was supposed to replace table view cell default edit control with a custom button to match the designs. I guess everyone knows that its pretty simple to change edit control’s color for selected state, we simply need to set cell’s tint color.

custom-edit-controls-for-uitableviewcell-01
custom-edit-controls-for-uitableviewcell-02

But there is no way to customise selected or default state of cell edit control with our own custom image because there is no public API to access this control. So, to customise this we have to write our own code. Steps below will guide you to achieve this.

Continue reading

 

Droidcon India 2014 Experience

Last week we attended Droidcon 2014, held in Bengaluru. First thing we noticed was that we had underestimated it a lot. The event was humongous. With around 250-300 attendees, most of which were either cream Android devs or entrepreneurs.

The content selection panel as well seemed to have done a great job. Topics ranged from core technical (hacking through Android source code) to all the way upto UI centric stuffs (delightful user experience). The speakers were highly experienced and most of them were either business owners or with hands-on experience in product development. Even the promotional interactions were highly informative and bent towards their technical details.

Following are some talks we would like to mention particulars about:

Continue reading