Ruby

Ruby : Attribute Accessor using Metaprogramming


Lets create a new class Accessor where we will define our brand new class method accessor and we will define getter and setter methods using class_eval: class Accessor def self.accessor(attribute) class_eval ” def #{attribute} @#{attribute} end def #{attribute}=(value) @#{attribute} = value end ” end end Now, lets use our accessor method instead of attr_accessor: class… Continue reading Ruby : Attribute Accessor using Metaprogramming

Ruby

Interesting Ruby (String, Array, Hash)


Let’s concatenate strings : ‘con’ ‘cate’ ‘nate’ >> concatenate ‘con’ + ‘cate’ + ‘nate’ >> concatenate ‘con’ << 'cate' <> concatenate # Using instance method : str = ‘concate’ str.concat(‘nate’) >> concatenate Let’s declare an array of size 5, prefilled with nil: Array.new(5) >> [nil, nil, nil, nil, nil] An Array of size 5, prefilled… Continue reading Interesting Ruby (String, Array, Hash)

Elastic Search · Ruby · Ruby on Rails

Add Robust Search functionality in your Rails 4 app using Elasticsearch and Typeahead JS


Install ElasticSearch : — For Ubuntu 14.04 Install Java Default Runtime & JDK sudo apt-get install default-jre sudo apt-get install default-jdk Install ElasticSearch from Debian software package wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.7.deb dpkg -i elasticsearch-0.90.7.deb Test ElasticSearch install curl -X GET ‘http://localhost:9200&#8217; We will get a response like this: { “ok” : true, “status” : 200, “name” :… Continue reading Add Robust Search functionality in your Rails 4 app using Elasticsearch and Typeahead JS

Git

Generate Beautiful Report from Git Log / Commit History


Writing report is a boring work for a developer and we can minimize the pain by following some easy work-flow. Personally I prefer to write brief commit message and now it’s a matter of fun to generate report using those messages. Git log provides us the history and we can format that for our own… Continue reading Generate Beautiful Report from Git Log / Commit History

Uncategorized

Rails 4 with Postgres – Let me help you to get rid of your trouble!


sudo apt-get update sudo apt-get install postgresql postgresql-contrib libpq-dev sudo -i -u postgres Create a new role by typing: createuser –interactive It will ask you for the name of the role and will it be a superuser. Give your system username as Role and superuser previledge. exit Now create rails app with Postgresql as database… Continue reading Rails 4 with Postgres – Let me help you to get rid of your trouble!

Best Practices

Practices I Follow For Writing Readable Code


When many developers work in a project simultaneously, coding conventions have to be followed. Code readability is very much important and it is one of the first things we learn as developers. In this article I’ll try to discuss some good practices when righting readable code. Naming conventions Function names may start with a lowercase… Continue reading Practices I Follow For Writing Readable Code

Git · Ubuntu-14.04

Git — Software Version Control @ Ubuntu 14.04


INSTALL Open Terminal (Ctrl+Alt+T) and run the following command to install : sudo apt-get install git SET YOUR IDENTITY git config –global user.name “Your Name” git config –global user.email your_email@example.com BOOKS AND REFERENCES FOR LEARN USING GIT Pro Git Book by Scott Chacon and published by Apress, is available here. All content is licensed under… Continue reading Git — Software Version Control @ Ubuntu 14.04