Rails Or Django – Which One To Choose?

Rails or Django - which one to choose?

Python and Ruby are the most popular dynamic programming languages. Developers are using these two languages for high-level application development. Python and Ruby are popular among web developers because of their rapid development cycle.

Here, I have discussed the most important difference between Python and Ruby:

Philosophy

Python has been designed to emphasize the programmer’s productivity and code readability. The philosophy of Python requires almost everything explicitly defined by a programmer, whereas Ruby allows programmers to reuse the in-built components in development.

The philosophy behind Ruby is that programmers should have the flexibility and privilege to write concise and compact code.

Functional Programming

Both Rails and Django use object-relational mapping to link the application to the underlying database. In Django, the developer is required to explicitly specify each attribute of every class.

But, In rails, all module attributes are not defined in the class definition. A developer can retrieve all the information from the database based on the class name.

In Rails database migrations is very easy and in-built compared to Django, as it uses third party library like South.

Convention over Configuration

Ruby on Rails defines certain features that make web programming more effective and user-friendly. Convention over configuration (CoC) is one of the important features of Rails.

“Convention over Configuration” means a developer only needs to specify unconventional aspects of the application. There are some predefined layout and sensible defaults available in rails projects.

All components such as models, controllers, and static CSS and JavaScript files are located in standard sub-directories and you just need to drop your implementation files into those directories.

CoC saves a lot of time of developers because in rails you don’t need to write the same code again and again.

While in Django, you have to specify the path where the component files are located. So the development cycles in Rails are shorter as compared to it’s counterparts.

Model-View-Controller and REST

Ruby on Rails is unique because it supports the REST protocol. It helps you to organize your application. In Rails, all model objects are accessed and handled in a uniform manner using the standard HTTP verbs like getting, PUT, DELETE, and POST.

CSS, JavaScript and images

Rails have an in-built asset pipeline. Rails’ asset pipeline is having feature of minifying, concatenating and compressing JavaScript and CSS files. Not only that, it also supports other languages such as Coffeescript, Sass and ERB.

Django’s support of assets it very amateurish compared to Rails and leaves everything to the developer. Django offers static files, which basically collects all static files from each application to a single location.

URL mapping

Both Rails and Django allow for the use of regular expressions to customize the mapping of URLs to controller actions. Both are flexible enough to allow you to create pretty much any mapping scheme you wish.
But, Rails does automatic URL mapping based on the class and function names within controllers by default.

Testing

Testing is very easy in Rails and there’s a much stronger emphasis on it in Rails than in Django.

Popularity

Python is generally more widely used than Ruby. Due to the rising popularity of the Ruby on Rails Web application development framework, Ruby’s popularity to has seen rapid growth.

Both Rails and Django are effective web frameworks powered by efficient programming languages. However, Rails is the best platform for rapid web app development.

Andolasoft offers quality rails development service. We specialize in developing database-driven web applications in an efficient and hassle-free way.

Recommended Blog: Steps to add ‘Elasticsearch’ to Rails App

Have something to add to this topic? Share it in the comments

How To Install Nagios Core on CentOS, Fedora, or RHEL Server

Nagios® Core™ is the industry standard Open Source system and network monitoring application which enables organizations to identify, resolve IT infrastructure problems before they affect critical business processes. It watches hosts and services that you specify, alerting you when things go bad and when they get better. Nagios Core serves as one of the foundation blocks of Nagios XI – commercial monitoring solution.

It was originally designed to run under Linux, although it should work under most other unices as well.

Steps to install :

STEP-1:

Install prerequisites packages

       #   yum  install  gd  gd-devel  httpd  php  gcc  glibc  glibc-common

STEP-2:

Disable selinux. open the file: /etc/selinux/config by issuing the following command          

       # vi /etc/selinux/config

Then, type “disable” opposite to “SELINUX” e.g  SELINUX= disable

STEP-3:

Create a user “nagios” and set password for it by typing the below commands.

       #   /usr/sbin/useradd -m nagios
       #   passwd nagios

STEP-4:

Create a new group “nagios” for allowing external commands to be submitted    through the web interface and add both the nagios user and the apache user to the group by following the below steps

       #    /usr/sbin/groupadd nagios
       #    /usr/sbin/usermod -a -G nagios nagios
       #    /usr/sbin/usermod -a -G nagios apache

STEP-5:

Create a directory “download “ and download nagios-core and plugins to it.

       #  mkdir download                  
       #  cd  download
       #  wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.4.tar.gz
       #  wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz

STEP-6:

Compile and Install nagios-core package by following below steps

  • Change directory to “download” folder
       #   cd ~/download
  • Untar the nagios-core tar bal
       #   tar xzf nagios-3.4.4.tar.gz
  • Change the directory to “nagios-3.4.4”
       # cd nagios-3.4.4
  • Configure the package and install
    #  ./configure
    #   make all
    #   make install
    #   make install-init
    #   make install-commandmode
    #   make install-config
    #   make install-webconf

STEP-7:

Create a password to log in to the web interface by issuing the following command.

       # htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

STEP-8: 

Start the service and set it on chkconfig to start at booting time.

       #  service nagios start
       #  chkconfig nagios on

STEP-9:  

Compile and Install nagios-plugin package by following below steps.

  • Change directory to “download” folder
       # cd   ~/download
  • Untar nagios-plugin tar ball
       # tar xzf  nagios-plugins-1.4.16.tar.gz
  • Change the directory to “nagios-plugins-1.4.16”
       # cd  nagios-plugins-1.4.16
  • Configure the package and install.
       # ./configure
       # make
       # make install

STEP-10:

Start the apache service and enable it on boot by issuing following command.

       # service httpd start
       # chkconfig httpd on

STEP-11:  Now, connect to your nagios server through browser by typing.

       # http://Your-Nagios-IP/nagios or  http://localhost/nagios

Then, enter login credentials.
Username: nagiosadmin & password you have chosen earlier

Features of NAGIOS Core

  • Monitoring of network services (SMTP, POP3, HTTP, NNTP, PING, etc.)
  • Monitoring of host resources (processor load, disk usage, etc.)
  • Simple plugin design that allows users to easily develop their own service checks
  • Parallelized service checks
  • Ability to define network host hierarchy using “parent” hosts, allowing detection of and distinction between hosts that are down and those that are unreachable
  • Contact notifications when service or host problems occur and get resolved (via email, pager, or user-defined method)
  • Ability to define event handlers to be run during service or host events for proactive problem resolution
  • Automatic log file rotation
  • Support for implementing redundant monitoring hosts
  • Optional web interface for viewing current network status, notification and problem history, log file, etc.

Recommended Blog: How to install and configure Jaspersoft in Linux Server(RHEL/Centos/Fedora)

I hope you liked this topic, if you have any questions or comments please feel free to put under comments!

How To Do Custom Pagination In CakePHP

Sometimes we need to do pagination in CakePHP using a traditional SQL query, thereby the CakePHP predefined pagination functionality is lost.

We can implement pagination method in the Model or Behavior when we are using standard SQL query in CakePHP. Just need to make sure that the result cannot be obtained with core model methods, or a custom finder before implementing custom queries pagination.

But we can’t just use the standard pagination on the custom queries, we have to override the paginate functions in model or behavior.

To use our own method/logic to override the CakePHP pagination in the model, we need to add two functions: paginate() and paginateCount().

In these functions, we can implement our own paginate logic.

Overriding paginate() function in CakePHP Post Model:

[php]public function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null, $extra = array()) {
$orderStr = ”;
foreach($order as $k => $ord) {
$orderStr[] = $k . ‘ ‘ . $ord;
}
$orderStr = ‘ORDER BY ‘. implode(‘, ‘, $orderStr);

$qryCond = ‘1’;
if (isset($conditions[‘Post.title LIKE’])) {
$qryCond = ‘title LIKE \”.$conditions[‘Post.title LIKE’].’\”;
}

$qryFlds = ‘*’;
if ($fields) {
$qryFlds = implode(‘, ‘, $fields);
}

$sql = ‘SELECT ‘.$qryFlds.’ FROM posts as Post WHERE ‘.$qryCond.’ ‘.$orderStr . ‘ LIMIT ‘ . (($page-1) * $limit) . ‘, ‘ . $limit;
$results = $this->query($sql);
return $results;
}[/php]

Overriding paginateCount() function in CakePHP Post Model:

[php]public function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
$qryCond = ‘1’;
if (isset($conditions[‘Post.title LIKE’])) {
$qryCond = ‘title LIKE \”.$conditions[‘Post.title LIKE’].’\”;
}

$sql = ‘SELECT COUNT(*) as count FROM posts as Post WHERE ‘.$qryCond;

$this->recursive = -1;

$results = $this->query($sql);
return $results[0][0][‘count’];
}[/php]

Using in the Post Controller: We can adjust the fields to get, column ordering, add certain conditions or adjust row limit per page.

[php]public function index() {
$this->paginate = array(
‘limit’ => 10,
‘fields’ => array(‘Post.id’, ‘Post.title’, ‘Post.created’),
‘conditions’ => array(‘Post.title LIKE’ => ‘%search_keyword%’),
‘order’ => array(‘Post.title’ => ‘asc’, ‘Post.id’ => ‘asc’)
);
try {
$this->set(‘posts’, $this->paginate(‘Post’));
} catch (NotFoundException $e) {
$this->redirect(‘index_custom’);
}
}[/php]

The above example is based on specific model and requirement, need to adjust the methods according to the requirements.

See Also: Creating a custom handler session in CakePHP 2.x

Best of luck and happy pagination.

Hope you liked this. Let me know if you want to add anything?

Grow Your Business For Your Mobile App With Google Analytics

In this digital era, information or data plays pivotal role in the process of development. The more information you have, more precise and accurate decision you can take. And this is also applies to mobile apps.

As per report comes from Portio “1.2 billion people worldwide were using mobile apps at the end of 2012. This is forecast to grow at a 29.8 percent each year, to reach 4.4 billion users by the end of 2017.” This simply indicates industry’s future growth potential; but to stand out this industry is not an easy job. Good news is that Google has its own free analytics tool that helps you to find out insight details of your mobile app which can be your vital part of our app development process.

In June 2012, Google introduced beta version of mobile app analytics ; but now it becomes the part of Universal Analytics. Today our purpose is to educate those developers or users who are not familiar with this influential API(Application Program Interface)

How To Setup Google Analytics for Mobile App?

Step 1:

Set up a new app property in your analytics accounts.
First login into your google analytic profile. Here you get two options:

  • Option One: You can create new account for your mobile app. For this go to admin section, then create new accounts from the account tab and choose “mobile app” tab. Now just provide details like Account name, App name, Industry category and time zone and you will get your tracking code. This option is more suitable if you want to see your analytic data of your mobile apps only.
  • Option Two: Here you can create a new property from your existing account. For this simply go to account where you want to add your new property and then select “Create new property” tab under property section and rest is similar to option one.This option is more suitable if you want to see analytic data of your web application as well as corresponding mobile application.

Step 2:

Download the Google Analytics SDK for Android or iOS from the same account screen that provides the tracking ID. Suggest to take help of mobile developer to implement tracking via SDK.

Never miss an update from us. Join 10,000+ marketers and leaders.

Once you setup your analytic for mobile app you can analyze your data through lots of cool features and out of them I have listed few features here:

  • Enhance your customer base by knowing who utilizes your app, on what platform, where they come from and what they looking for from Traffic Source report and Google play integration.Note: If you link your Google Analytics account to Google Play then your android apps will be automatically recognized in Google Analytic; but you have to associate each application separately with an analytic account.
  • Event tracking, Flow visualization, and Real time reporting helps you to identify scope of improvement for better customer engagement. With in-built crash and exception reporting, you can prioritize the issues which are impacting your visitors, helping you to serve better user experience. More you engage your visitor, better chance to achieve your objective.
  • Every single application has certain goals such as purchase, leads, signup or simply spending time on app. This helps you to setup and track those goals.
  • Google Analytics is now available on Admob. So you can get full analytic data either from Google Analytics or from Analyze tab of Admob account.

Recently, Google also released official Google Analytic app for iphone user (https://itunes.apple.com/app/google-analytics/id881599038). In future we may review this app for you.

See Also : Tips to increase your app download through App Store Optimization(ASO)

Andolasoft has been successfully delivered lots of iOS and Android app for his worldwide customer. You can check out our portfolio page. I would love to hear how you are using, or plan to use, this powerful Google API.

How to install and configure Jaspersoft in Linux Server(RHEL/Centos/Fedora)

Jaspersoft is a commercial open source software vendor focused on business intelligence, including data visualization, reporting, and analytics. It provides commercial as well as open source software, support services and licensing around the Jasper report, Jasper report server, Jaspersoft Studio, i-report and ETL products.

Jaspersoft is offered the communities open source edition as well as several commercial editions with broad support for various databases and data sources, including NoSQL and other big data sources. Jaspersoft’s main related product is JasperReports Server, a Java web application that provides advanced report server capabilities such as report scheduling, permissions, ad hoc reporting, dashboards, and multi-tenancy.

Unlike other traditional BI tools, it allows anyone to easily self-serve and get the answers they need inside their preferred app or on their favorite device. Our platform, unlike desktop visualization tools, scales architecturally and economically to reach everyone.

jaspersoft

Steps to Install ‘Jaspersoft Server’

STEP:1 Install JAVA 1.7 or above

STEP:2 Install Mysql server

# yum install mysql-server mysql php-mysql

STEP:3 Install tomcat 6 or tomcat 7
# yum install tomcat6 tomcat6-webapps tomcat6-admin-webapps

STEP:4 Download jaspersoft war file from “http://sourceforge.net/projects/jasperserver” by issuing the below command

# wget http://sourceforge.net/projects/jasperserver/files/JasperServer/JasperReports%20Server%20Community%20Edition%205.6.0/jasperreports-server-cp-5.6.0-bin.zip/download

STEP:5 Unzip zip file and move to “ opt “ directory

[sourcecode language=”plain”]# unzip jasperreports-server-cp-5.6.0-bin.zip
# mv jasperserver-ce-3.7.0-linux-installer.bin /opt/[/sourcecode]

STEP:6 Start Mysql service and Stop the tomcat service.

[sourcecode language=”plain”]# /etc/init.d/mysqld start
# /etc/init.d/tomcat6 stop[/sourcecode]

STEP:7
Go to this directory /opt/jasperreports-server-cp-5.6.0-bin/buildomatic
Then COPY “mysql_master.properties” file from this directory jasperreports-server-cp-5.6.0-bin/buildomatic/sample_conf/mysql_master.properties and Rename the “mysql_master.properties” to “default_master.properties”

STEP:8 Edit the default_master.properties file with vi editor

[sourcecode language=”plain”]# vi default_master.properties[/sourcecode]

Uncomment this below line

[sourcecode language=”plain”]# appServerType = tomcat6[/sourcecode]

Go to Tomcat app server root dir and modify“Catalina home and base “path as below
# If linux package managed tomcat instance, set two properties below

[sourcecode language=”plain”]CATALINA_HOME = /usr/share/tomcat6/
CATALINA_BASE = /var/lib/tomcat6/[/sourcecode]

# Change database location and connection settings setup as your own mysql passwd.

[sourcecode language=”plain”]dbHost=localhost
dbUsername=root
dbPassword=passwd[/sourcecode/]
# web app name
# (set one of these to deploy to a non-default war file name) uncomment as below any one
[sourcecode language="plain"]webAppNameCE = jasperserver
# webAppNamePro = jasperserver-pro[/sourcecode]

STEP:9 Download the mysql connector jar file from

[sourcecode language=”plain”]# wget https://total-pos.googlecode.com/files/mysql-connector-java-5.1.17-bin.jar[/sourcecode ]

<strong>STEP:10</strong> Put the mysql-connector-java-5.1.17-bin.jar file in tomcat directory
[sourcecode language="plain"]# /usr/share/tomcat6/lib/mysql-connector-java-5.1.17-bin.jar[/sourcecode]

STEP:11 Install this file under this directory

[sourcecode language=”plain”]# cd /opt/jasperreports-server-cp-5.6.0-bin/buildomatic
# ./js-install-ce.sh[/sourcecode]

STEP:12 Start the tomcat service

[sourcecode language=”plain”]# /etc/init.d/tomcat6 start[/sourcecode]

STEP:13 Browse in url

[sourcecode language=”plain”]# http://<ip-address>:8080/jasperserver[/sourcecode]

STEP:14 Login username and password
User login: jasperadmin
Passwd: jasperadmin

Conclusion:  Jaspersoft is available under an open source license for use in conjunction with open source infrastructure such as MySQL and JBoss, or a commercial license for enterprise deployments involving commercial databases and application servers. Jaspersoft’s main related product is JasperReports Server, a Java EE web application that provides advanced report server capabilities such as report scheduling and permissions.

Share your thoughts with comments

How To Setup CakePHP DataSource For Solr?

Imagine that you have millions of data and your SQL database is not optimized enough to handle them, then “Solr” is your best data source. Apache Solr is a fast search platform. It’s major features include full-text search faceted search, dynamic clustering, database integration, rich document handling. Solr is highly scalable and it is the most popular enterprise search engine.

This document will guide you through DataSource setup for Solr in CakePHP. Set-up the Solr DataSource in CakePHP and query Solr with your CakePHP model “find” function, just similar to querying any other SQL database.

/app/Config/database.php:

Configuring your the DataSource for Solr database connection:

  • host: Solr server address.
  • port: Solr server port.
  • datasource: This should match with your DataSource at /app/Model/Datasource/SolrSource.php

[php]class DATABASE_CONFIG {
public $solr = array(
‘datasource’ =&amp;amp;amp;gt; ‘SolrSource’,
‘host’ =&amp;amp;amp;gt; ‘192.168.2.131’,
‘port’ =&amp;amp;amp;gt; ‘9983’,
‘path’ =&amp;amp;amp;gt; ‘/solr/’
);
}[/php]

/app/Model/Solr.php:

Use the database config in your models like:

[php]class Solr extends AppModel {
 public $useTable = false;
 public $useDbConfig = ‘solr’;
 }[/php]

/app/Model/Datasource/SolrSource.php:

Below code describes only the most required functions.

  • You can find other required functions at http://book.cakephp.org/2.0/en/models/datasources.html
    Like: calculate($model, $func, $params) and others create(), update(), delete().
  • Below DataSource only implements read() function.
  • Create a file called SolrSource.php and use below code:

[php]App::uses(‘HttpSocket’, ‘Network/Http’);
require_once($_SERVER[‘DOCUMENT_ROOT’].’/root_folder/app/Vendor/Apache/Solr/Service.php’);
class SolrSource extends DataSource {

protected $_schema = array();
protected $_host;
protected $_port;

public function __construct($config){
parent::__construct($config);
$this-&amp;amp;amp;gt;Http = new HttpSocket();

$this-&amp;amp;amp;gt;host = $config[‘host’];
$this-&amp;amp;amp;gt;port = $config[‘port’];
$this-&amp;amp;amp;gt;_schema = $config[‘path’];

$this-&amp;amp;amp;gt;solr=new Apache_Solr_Service($this-&amp;amp;amp;gt;host, $this-&amp;amp;amp;gt;port, $this-&amp;amp;amp;gt;_schema);
}

public function read(Model $model, $queryData = array(), $recursive = null) {
$results = array();
$query = $queryData[‘conditions’][‘solr_query’];
if (Configure::read(‘log_solr_queries’) === true) {
CakeLog::write(‘debug’, $query); /* Logs the solr query in app/tmp/logs/debug.log file */
}

try {
$solr_docs = $this-&amp;amp;amp;gt;solr-&amp;amp;amp;gt;search($query, $queryData[‘offset’], $queryData[‘limit’], array(‘sort’ =&amp;amp;amp;gt; $queryData[‘order’]));
} catch (Exception $e) {
CakeLog::write(‘error’, $e-&amp;amp;amp;gt;getMessage()); /* Logs the solr errors message in app/tmp/logs/error.log file */
CakeLog::write(‘error’, $query); /* Logs the solr query in app/tmp/logs/error.log file */
}
$model-&amp;amp;amp;gt;params = $solr_docs-&amp;amp;amp;gt;responseHeader-&amp;amp;amp;gt;params;
$model-&amp;amp;amp;gt;numFound = $solr_docs-&amp;amp;amp;gt;response-&amp;amp;amp;gt;numFound;
$docs = $solr_docs-&amp;amp;amp;gt;response-&amp;amp;amp;gt;docs;
foreach ($docs as $doc) {
$document = array();
foreach ($doc as $fieldName =&amp;amp;amp;gt; $fieldValue) {
$document[$fieldName] = $fieldValue;
}
$results[] = $document;
}
return array($model-&amp;amp;amp;gt;alias =&amp;amp;amp;gt; $results);
}
}[/php]

/app/Controller/UsersController.php:

Getting data from Solr server by using above SolrSource.

[php]App::uses(‘AppController’, ‘Controller’);
class UsersController extends AppController {

public $name = ‘Users’; //Controller name
public $uses = array(‘Solr’); //Model name

function beforeFilter(){
parent::beforeFilter();
$this-&amp;amp;amp;gt;Auth-&amp;amp;amp;gt;allow(‘index’);
}

public function index(){
$cond = "active:1";
$sort = "timestamp desc";

$params = array(
‘conditions’ =&amp;amp;amp;gt;array(
‘solr_query’ =&amp;amp;amp;gt; $cond
),
‘order’ =&amp;amp;amp;gt; $sort,
‘offset’ =&amp;amp;amp;gt; 0,
‘limit’ =&amp;amp;amp;gt; 1
);

$result = $this-&amp;amp;amp;gt;Solr-&amp;amp;amp;gt;find(‘all’, $params);
$this-&amp;amp;amp;gt;layout = ‘ajax’;
header(‘Content-Type: application/json; charset=utf-8’); /* To send response in json format */
echo json_encode($result);
die;
}
}[/php]

See Also : How to use ‘neighbors’ with ‘find’ method

Debugging:

The above code has been tested and validated with CakePHP 2.2.3, PHP 5.3.1 .
Incase you face any problems:

  • First check the DataSource configuration in /app/Config/database.php.
  • Check /app/Model/Solr.php for this line: public $useDbConfig = ‘solr’;
  • Make sure Solr Service Vendor loaded in /app/Model/Datasource/SolrSource.php.
  • Check the path is correct for the Solr vendor.

Hope you liked this. Let me know if you want to add anything?