Encoding Problems in Ruby

String encoding is something that we don't really think until we see Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT Or when users complains about missing special characters like "’" (apostrophe copied from Microsoft Word) or when "菜医生" becomes "иЏњеЊ»з”џ". Before we go into encoding problems, lets understand what encoding is. A string can be considered as an array of bytes: irb(main):001:0> "world".bytes => [119, 111, 114, 108, 100] Here 119 means w, 111 means o and so on. This relationship between bytes and characters is

Hubspot CRM - how, what and benefits

Recently while working on one of our project we came across requirement where we wanted Hubspot integration with our application for ease of sales team to manage user's data and understand their interactions and trends in application. I will quickly explain few things about Hubspot here in my article. What is Hubspot? In brief, Hubspot is a CRM which helps you monitor and fine tune many things regarding your application. Based on my analysis I will shortly list down few most important of them in order to give you more insights about it - Closely monitoring user interactions with your

Introduction to Regular Expressions (aka regex) (Part 1)

A regular expression is a pattern describing a certain amount of text and is a type of shorthand to describe a search pattern. It is used to find text which matches a pattern within a larger text, to replace the matching text or to split the matching text into groups. Regular expressions power of extracting specific text from documents resides in their ability to replace many lines of code with as little as one line. Some terms used in regular expressions: Literal - A literal is a character we use in a search or matching expression. For example, to find

Dynamic Ruby

Ruby is too dynamic. We can do almost anything in runtime, from creating the classes at runtime to creating methods dynamically. If you are coming from some other language, it would be shocking for you too know that nothing is private in ruby. You can access private and protected method from anywhere you want. You can call this a flexibility or a curse. But a smart developer knows when to utilize the power of extreme flexibility that Ruby provides and when to stay away from it. Is this all Ruby can do in terms of flexibility? Definitely not. Ruby have

Ruby 2.0 Lazy Enumerator

What is Lazy Enumerator Ruby 2.0 lazy enumerator allows you to iterate over infinite values and take the values you want for your calculation.This code would result in an infinite loop. range = 1..Float::Infinity range.collect { |x| x*x }.first(10) The code results in an infinite loop because the Enumerable#collect is eager.It means that first collect processes all the values from the first array and then save it in the second array.Since we have an infinite range here first method would never get a chance to execute. With ruby 2.0 you can

Comments in Ruby and JavaScript

Ruby Comments There are basically two types of comments in Ruby. And they work in the same way as follows: The block comment The comment block is created with the =begin and =end delimiters. def welcome =begin This will print the welcome message. You can also add your custom message. =end puts "Welcome to ruby comments learning :)" end The line comment This is the simple comment where you place an octothorpe(#) as the first non-whitespace character of the line, and everything else written is excluded from being interpreted by Ruby. def welcome # This will print the welcome message.

Quick dive into Elixir, Phoenix and Erlang ecosystem

Few weeks back I was reading a blog about concurrency limitations in Ruby (which we all are aware since long) and how Elixir is evolving. Thus I was extremely curious to know this new dynamic functional programming language "Elixir", the two decades old Erlang language & Erlang Virtual Machine (VM) known for running low-latency, distributed and fault-tolerant systems. This article is a result of my curiosity about Elixir and Erlang. This article does not cover (i.e. out of scope) installation steps of Elixir & Erlang on Mac, Ubuntu or Windows machine as lot of help is already

RUBY Quick Tip : Share your local folder with everyone over LAN

This is very useful Ruby command to share your local folder with everyone on the same network. Thanks to Rohan! As we were working on something and he wanted me to share my local folder quickly. Rohan shared this Ruby command with me and since then every now and then I am using it in office to share stuff with teams. Command is: ruby -rwebrick -e 'WEBrick::HTTPServer.new(:Port=>PORT_NUMBER,:DocumentRoot=>”DIRECTORY_PATH").start' e.g. ruby -rwebrick -e 'WEBrick::HTTPServer.new(:Port=>2121,:DocumentRoot=>”/home/public/picture").start' PORT_NUMBER - Port to listen a request DIRECTORY_

Evernote Create Note - EDAMUserException - ENML_VALIDATION

If you have an application which creates notes, learning how to integrate evernote to sync notes will be very handy. You may refer this ruby gem - [evernote_oauth][1] which has useful methods to access your existing evernote notebooks, create notebooks and notes, etc. The gem is well documented. Refer this blog to understand and see code to create note on evernote - [Create Note on Evernote][2] If you refer the code in the above blog to create a note - just this particular snippet - n_body = "" n_body += "" n_body += "#{note_

Integration of Redactor Rails in Active Admin

In our current app, there was a requirement to have a nice editor which will provide the basic functionalities like bold,italic and also image upload. We decided to use redactor-rails gem Github-Documentation-Link(Github Doc) . So i took following steps: In Gemfile i included: gem 'redactor-rails' Then for image uploading and storing i included two more gems as: gem 'carrierwave' gem 'mini_magik' Bundle it. rails generate redactor:install rails generate redactor:config In application.js //= require redactor-rails In active_admin.scss on the top include: *= require redactor-rails In ActiveAdmin model i wrote: f.input :name, input_html: {class: 'redactor'}