What is the Importance of Filters in Rails

Rails

In Ruby on Rails development, filters play a vital role. They are the methods executed ‘before’, ‘after’  or  ‘around’ a controller action.

For example, one filter might check to see if the user has the credentials to access that particular controller or action.

Filters are inherited, so if you set a filter on ‘ApplicationController’, it would run on every controller in your application.

Below is an example to explain how a filter can be used to restrict a non-logged in user to access specified actions in a controller

Step#1

  • In Application controller write the following block of code according to the requirement.
def user_login_required
 if !session[:username]
 flash[:notice] = "Oops you need to login!"
 redirect_to :controller => "user_sessions", :action => "new"
 end
end

Step#2

  • Now write the before_filter block in the controller you want to restrict the not registered users. You can also restrict particular actions of a controller by writing the action name.
class UsersController < ApplicationController
 before_filter :user_login_required, :only => [:profile]
 def profile
 [Your code block goes here]
 end
end

In the above block the ‘before_filter’ restrict the not registered user to access
the profile page and redirect them to login page. We can also restrict multiple
actions by writing like this

before_filter :user_login_required, :only => [:profile,:edit]

In this case the filter is applied to only these two methods of a particular controller.

before_filter :user_login_required, :except => [:index,:show]

In this case the filter is applied to all other actions except index and show
action of a particular controller.

If you write the before_filter block in the “ApplicationController” then the
filter will be applied to all the controllers.

Planning anything on Ruby on Rails? Talk to Andolasoft’s experts to get a clearer idea.

New Secure Password Hashing API In PHP 5.5

The fifth release of PHP, also known as PHP 5.5, was released in this year with great new features and updated standards. One of the most exciting aspects of the update is the Password Hashing API, which aims to provide a universal standard for password hashing functions.

Hashing is a way to store user passwords so that they are not stored in clear text but can still be verified when users log in again. With this new standard, you can use one function (password_hash) to create an account verification token for your user login system. You use another function (password_verify) to validate a hashed password when users sign up or reset their password again.

From the analysis reports, it is now believed that work has officially begun on PHP 5.5. It will be the first major update since the release of the version earlier this year.

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

In recent years major update releases for PHP were very slow, so it will be interesting to see how fast or slow PHP 5.5 will come into the development process.

Among all the updates in PHP 5.5 the most impressive feature is the new Password Hashing API.

According to some recent security attacks, it is now revealed that a vast majority of PHP developers either don’t understand the password hashing or don’t think it’s worth an effort.

The current implementation of password hashing using crypt() is difficult to implement and work with, but by providing a simple API for password hashing, it will become easier for the developers to simply call the API which will take care of all the issues of the PHP development. Eventually, more projects and developers will be able to use secure password hashing.

It makes sense to include this feature, but let’s just hope for an early official release of this version, so that the PHP developers can take advantage of this security innovation.

Conclusion

The Password Hashing API is a great addition to PHP. It simplifies the process of creating and verifying password hashes. The API is compatible with existing methods and can be used for many different systems, which makes it a useful tool for developers. The Password Hashing API is available in PHP 5.5 and newer versions. This new standard aims to unify the password hashing process and create a universal method to create and verify password hashes.

Cloud Services’ Popularity among Small Businesses.The Major Factors

Cloud ServicesRecently it’s been found that around 80% of private businesses who are involved in foreign trade are small in size and startups.

Many of these are growing or looking to expand their company by choosing innovative solutions to provide better services to their customers.

Cloud computing can be a viable option for startup companies that can boost their business productivity.

The foremost reason to choose a cloud management service is to get the benefits of big business infrastructure.  In the recent past, servers were configured in the office, which was troublesome and required a lot of resources like expensive.

Hardware, faster processors, dedicated server administrators, and 365×24×7 internet connection. To avoid such headaches, it is beneficial to opt for cloud-based computing power for more productivity at a lower budget.

As the servers are accessed remotely, it offers better flexibility than traditional IT infrastructures. The administrators can access remote servers from anywhere by using various mobile devices.

This flexibility in accessing the servers saves time, money, and also helps to fix issues immediately when required.

Cloud server monitoring also facilitates better collaboration with clients. It enables the company to share specific client-related issues with other departments, in order to solve the problem. Taking notes, sharing client files, and working together to solve the problem has become easier than before.

Data security is one of the most important reasons to use cloud management services.

The remote infrastructures provided by cloud service consider clients ‘data security’ as their top priority. Many people wrongly assume that cloud monitoring is less secure than native servers.

Due to this reason cloud server monitoring is managed by IT professionals who stress themselves to keep their data safe and out of the reach of hackers. But choosing cloud services can reduce these threats and the business can acquire various legal requirements regarding the security of data.

Planning anything on Cloud? Andolasoft provides Best-in-Class Cloud Management Services for Businesses of all kinds. Let’s have a quick discussion.

Vuzix’s Smart Glass will Change the Way We Work with Computers

vuzix-smart-glassesWith the advancing technology, computers have been evolving through the years to become more compact to the users. First, there were desktops then they came to the laps and then to the hands, now the next generation computers will be right in front of our eyes in the form of wearable eyeglasses.

There are a lot of companies, who have been developing wearable computers, but they were shipped only for military purposes and never to the public.

Recently Google stunned the technology industry by announcing its plans to sell Google Glass to the public market.

But it turned out that Google isn’t the only one trying to make smart glasses in order to bring computers to a person’s field of vision.

A New-York based technology industry ‘Vuzix’ has unveiled a hands-free smart device that comes with an integrated “virtual display” eyepiece, Wi-Fi and Bluetooth connectivity, a 720p HD camera, and motion sensors.

The Vuzix smart glasses can sync up a smartphone or tablet. It contains a microphone, an earpiece, a camera, and motion and GPS sensors, and it’s capable enough to run any version of the Android operating system.

Bluetooth and Wi-Fi enable it to be linked to a smartphone to project a small display, positioned in the wearer’s vision, which provides a comfortable viewing area equivalent to having a four-inch smartphone display in hands.

The device is ideal for those who need to be connected to the cloud at all times.

The device is expected to start with relatively few features but eventually, it will become more impressive as the Android app developers develop software for it.

The glasses will get data and information from an app installed on a user’s Android device.

This technology will change the way we experience and work with computers and smartphones. It will also bring new possibility for the android application developers to create apps specifically for the Vuzix smart glasses.

How To Send Files To Remote Server Via SSH In PHP

You may have faced a situation where you need to send server files to a remote server. If you are working on a website that requires remote server access and files regularly, it is impossible to keep on transferring the file every time they are updated.

This means that you cannot keep these files in your local system and need to transfer them to the remote server only when they’re updated. To do this, you will need SSH access to the server so that you can send files securely via SFTP or any other secure file transfer protocol.

Once you learn how to set up SSH access, there are some things that you need to know about how SSH works and how it’s used with different servers.

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

This example describes ‘How to SSH to remote server in PHP and send files from one server to another server using libssh2.’

ssh2_connect() – Connect to a remote server
ssh2_scp_send() – Send a file via SSH
ssh2_exec() – Execute a command on a remote server

Install libssh2 and then install PECL SSH2 extension for PHP.

Example:   

$ip = "192.168.2.101";
$username = "test";
$port = 22;
$public_ssh_key = "/var/www/html/ssh_keys/id_dsa.pub";
$private_ssh_key = "/var/www/html/ssh_keys/id_dsa";
 
if(function_exists("ssh2_connect")) {
$ssh_conn = ssh2_connect($ip, $port);
if($ssh_conn) {
//Validate your username with ssh keys
if(ssh2_auth_pubkey_file($ssh_conn, $username, $public_ssh_key, $private_ssh_key, 'secret')) {
 
// Check file list
$stream = ssh2_exec($ssh_conn, 'ls -l /home/test/');
if($stream) {
stream_set_blocking($stream, true);
while ($buf = fread($stream,4096)) {
flush(); // comment this line
$data.=$buf;
print_r($buf); // comment this line
}
fclose($stream);
}
 
// send file from one server to another
ssh2_scp_send($ssh_conn, '/path/from/file.ext', '/home/test/file.ext', 0777);
 
}
else {
die("SSH validation failed using Username: ".$username." (specify valid SSH keys or check your SSH key path)");
}
}
else {
die("SSH validation failed for IP: ".$ip);
}
}
else {
die("'ssh2_connect()' doesn't exists. Install libssh2 with PECL SSH2 extension");
}

Other commands:

ssh2_sftp() – Initialize SFTP subsystem
ssh2_sftp_mkdir()– Create directory on remote server

$sftp = ssh2_sftp($ssh_conn);
ssh2_sftp_mkdir($sftp, '/var/www/html/test');

ssh2_auth_password()  – Authenticate over SSH using a plain password
ssh2_auth_pubkey_file() – Authenticate using a public key
ssh2_shell() – Request an interactive shell
ssh2_tunnel() – Open a tunnel through a remote server

Apple AppStore, Google Play & Revenue Earnings

Apple Store, Google Play StoreWe all know that Google and Apple are the most dominating players in the smartphone industry and they get most of their revenues from their application stores i.e. ‘Google Play’ and ‘App Store’ respectively.

But according to a new study from App Annie Intelligence, both Google and Apple have shown interesting numbers in their respective application stores.

App Annie Intelligence has been monitoring numerous apps from Google Play and App Store to measure their performance based on the volume of apps being downloaded and the revenues being earned from their apps.

According to their report, Google Play has seen phenomenal growth in revenue in October 2012, which has increased by a staggering 311% compared to January 2012, but it’s still unable to match App Store, which attracted four times more revenues despite of growing just 12.9% in the same period.

Since the release of the report, Apple has disagreed App Annie’s numbers by saying that App Store’s revenue grew over 200% and not just 12.9%, but later it was revealed that both companies were right in their own way because the two entities were looking at the growth differently.

Practically Apple has grown around 200% every year, but according to App Annie, Apple’s growth is 12.9% in October 2012 counting from January 2012. So it turned out that both Apple and App Annie were right.

According to other findings from the study, there are other interesting statistics like:

  • 10% more free downloads are available from App Store compared to Google Play
  • Only 3.3% growth in app downloads for App Store whereas 48% growth is seen for Google Play in the last five months

In the recent past USA was listed for the highest iOS app downloads with 26% than the rest of the world and the revenue collected for the same was 33% of the rest of the world.

Whereas for Android 21% of app downloads came from USA and collected around 29% of revenue from Japan. Among the free mobile game apps for iOS, companies like EA, Gameloft and Facebook pulled maximum downloads and for Google Play, the top free app publishers are Google, Facebook, Rovio, Go Launcher.

Taking revenue into consideration the grossing iOS apps were from companies like EA, Zynga, Supercell. For Google Play the leaders were DeNA, COLOPL and GungHo Online.

There are other free iPhone and Android apps which also play a major role in generating revenues and traffic to the application stores. At the same time, iPhone application development and Android application development both are improving day by day.

We at Andolasoft have team of iPhone application developers and Android application developers to provide business solutions. We have developed iOS apps like Orangewall, Andolapic and kurrentjobs and Android apps like Christmas Tree Puzzle which you can download Free from App Store and Google Play.