Validating RSS Feeds in Rails

Rails1FeedValidator is a gem which validates the RSS feeds through SOAP protocol of the W3C Feed Validation service. It helps to find out errors in RSS or ATOM feeds. In Rails app we can do the feed validation by installing the gem.

    Step#1

  • Install the FeedValidator as a gem:
  • gem feedvalidator

    Run the bundler to install the gem
    Step#2

  • Include the require ‘feed_validator’ into your controller
  • Step#3

  • Generate a migration file and edit the file to add the following fields
  • class CreateFeeds < ActiveRecord::Migration
    def self.up
    create_table :feeds do |t|
    t.string :title
    t.timestamps
    end
    end
    def self.down
    drop_table :feeds
    end
    end
    

    Step#4

  • Validate your feed URL in your controller
  • def create
    site_url = params[:feed][:title].sub(/(\/)+$/,'')
    begin
    v = W3C::FeedValidator.new
    if v.validate_url(site_url) && v.valid?
    @feed = Feed.new(:title => site_url)
    @feed.save
    end
    rescue
    # Do nothing
    end
    redirect_to request.referrer
    end

How To Convert Documents To PDF in PHP?

‘Unoconv’ is the tool to convert doc, Docx, ODT to PDF file in PHP.

‘Unoconv’ is a command-line utility that can convert files from any ‘OpenOffice’ supported formats to a different ‘OpenOffice’ supporting the format.

Installation Required:

  • OpenOffice and Unoconv

You can provide one or more files as arguments to convert each of them to the specified output format.

Example:

unoconv -f pdf  example.doc

bove command will convert the example.doc to example.pdf in the current working directory.

Some other commands are:

unoconv -f odt example.doc
unoconv -f doc example.odt
unoconv -f jpg example.odt
unoconv -f xsl example.csv

Merge And Split PDF In PHP Using PDFtk

Merge a group of PDF files to a single PDF file without disturbing the contents using PDFtk.

  • PDFtk runs on a variety of platforms, including Windows, Linux, Mac OSX, FreeBSD, and Solaris.
  • It does not require Acrobat and allows you to manipulate PDF easily and freely.

What All You Can Do in PHP Using PDFtk

  • Merge PDF documents to one.
  • Rotate PDF Pages or documents.
  • Split the pages of the PDF into a new document.
  • Encrypt the output as desired.
  • Decrypt the Input as necessary but requires a password
  • Background watermark or a foreground stamp can be applied
  • Report on PDF metrics can be generated such as metadata, bookmarks, and page labels.
  • Update PDF metadata.
  • Attach numerous files to the PDF document.
  • Compress a PDF document into a single page.

Under the GPL, PDFtk is licensed for the public.

Download Link: https://github.com/bensquire/php-pdtfk-toolkit

Examples:

You can provide two or more PDF files as arguments to create a single PDF file as output.
Merge two or more PDFs into a new PDF file with all the original contents

  • pdftk example1.pdf example2.pdf example3.pdf cat output result.pdf

Rotate the first page of a PDF to 90 degrees clockwise

  • pdftk in.pdf cat 1E 2-end output out.pdf

Rotate all the pages of the PDF document by 180 degrees

  • pdftk in.pdf cat 1-endS output out.pdf

Report on PDF document metadata, bookmarks and page labels

  • pdftk mydoc.pdf dump_data output report.txt

iPhone 4S Has Taken The Market Sales High Compared To iPhone 5

Soon after the release of the iPhone 5, it went on to become the highest-selling iPhone in history, but based on the recent survey, it has shown some reports for which Apple’s investors are alarmed of possible unfavorable events.

According to new research, this suggested that consumer’s interest in Apple’s popular iPhone 5 lineup may have peaked.

But shares of Apple have decreased since the last month from September. The share has decreased over 25% from as high as $705.07, for which investors are now beginning to panic about Apple’s future.

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

UBS analyst Steve Milunovich has estimated for Apple’s fiscal year 2013 and 2014 and has also dropped his price target on Apple shares to $700 from an earlier target of $780.

Milunovich quoted “Some of our Chinese sources do not expect the iPhone5 to do as well as the iPhone 4S”.

Recently consumers in China have also revealed that they would prefer iPhone 4S over the new iPhone5.

The Wall Street Journal wrote over the iPhone5 launch as “arguably the least eventful launch of an Apple device in the company’s four-year history in the Chinese capital”.

Apple’s iPhone 5 demand didn’t show up as expected because of the fact that Apple delivered iPhone 5 with a familiar design and without any exciting features which was much expected by most of the consumers, along with that the malfunctioning iOS6 map apps also played a major part in decreasing iPhone 5 sales this year, even less than the iPhone 4S.

As per the latest survey, it is found that developers still prefer iOS5 over iOS6 for iPhone application development.

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 implement Multiple Database(DB) Connection in Rails3

Rails 3In some scenarios, we need data from an external database to execute in different applications. Here, we need a bridge that will connect these two different databases.

In Ruby on Rails, this can be achieved through ActiveRecord’s establish_connection().

Following are the steps to create a rails application which uses multiple databases, where the existing database and the external database will work simultaneously.

Let’s say there are two different rails applications say “myapp” and “remoteapp” where “myapp” depends upon “remoteapp” user table.

Step#1

Edit the ‘database.yml‘ file for the ‘myapp‘ project
Add a new connection for ‘remoteapp‘ as below:

# Connection name, it will be used to connect from myapp
connect_remote:
adapter: mysql2
username: user_name             # username of the remoteapp database
password: password             # password of the remoteapp database
pool: 5
database: remoteapp_db_name    # database name of the remoteapp
host: www.remoteapphost.com      # host name of the db

Step#2

In models folder create a new file called user.rb if it is not already there. Write below code to establish connection with remote app’s database.

class User < ActiveRecord::Base
establish_connection("connect_remote")
end

Here use the connection name defined in the database.yml file in the establish_connection() method.
Like this you can create models to connect with remote databases.
Step#3

It will give you the flexibility for managing users’ data of remote app’s database like it is present in the myapp database.
Use the normal way to get data from the user’s table like

User.all                   #To get all the records
User.find(id)              #To get required record

Here you can also insert or update data in users table by normal way as it is
present in myapp application

#insert new record
user = User.new params[:user]
user.save
 
#update existing record
user = User.find params[:id]
user.update_attributes(params[:user])