Wednesday, 22 April 2015

IOS : Automation Testing


For creating IOS automation test script use below links and i have also attached sample code that will tell you how in write and how to use automation script in IOS.




IOS : Watch Kit


There are few links to give information about how to code for iWatch.






Function by which watch app communicate with iPhone app

# Write function in WKInterfaceController

WKInterfaceController.openParentApplication(param, reply: { (replyValues, error) -> Void in }

//param is value to send 
// replyValues is result which we get
);

# Write method in iOS app appDelegates

func application(application: UIApplication!, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]!, reply: (([NSObject : AnyObject]!) -> Void)!) {
    // retrieved parameters from Apple Watch
    println(userInfo["value1"])
    println(userInfo["value2"])

    // pass back values to Apple Watch
    var retValues = Dictionary<String,String>()

    retValues["retVal1"] = "return Test 1"
    retValues["retVal2"] = "return Test 2"

    reply(retValues)
}

# Add group Id in Your app Provision Profile 

Going to Provision portal,identifiers->App IDs, your id, edit, app groups enable, edit set app group and save. Now go to provision profile and re-generate all the inactive Provision profiles and download them.

Monday, 20 April 2015

Grep Ruby: Configure Nginx with Unicorn on Ubuntu(Linux)

Grep Ruby Practices: Configure Nginx with Unicorn on Ubuntu(Linux): Introduction So finally you choose to go with  Nginx +  Unicorn for your rails application.  Thats great! We will go through with all...

Friday, 17 April 2015

Absolute URL / Full URL in Rails 4

Rails 4

Controller:

def absolute_url
  request.base_url + request.original_fullpath
end

Action Mailer Notable changes in 4.2 release:


http://guides.rubyonrails.org/4_2_release_notes.html

  • link_to and url_for generate absolute URLs by default in templates, it is no longer needed to pass only_path: false. (Commit)
View:

If you use the _url suffix, the generated URL is absolute. Use _path to get a relative URL.



<%= link_to "User Home", user_url %>



Thursday, 16 April 2015

Highlite your code for your blog

So you wanted to highlight your code for your blog ?


Nice looking code snippet is always important for you technical blog. For example you have below code

  def manager?
    role.downcase == "manager"
  end

  def bidder?
    role.downcase == "bidder"
  end


That doesn't look good at all.

Here are the pretty version of above code



  def manager?
    role.downcase == "manager"
  end
  
  def bidder?
    role.downcase == "bidder"
  end


Isn't it good?

Yes it is. You can use online tool to highlight your code. http://hilite.me/ does pretty nice job.
Keep using it.

Thanks!!!

Wednesday, 15 April 2015

Way to clean up gem OR remove old versions to keep the most recent

Way to clean out any old versions of gems.

    > sudo gem cleanup

If you just want to see a list of what would be removed you can use:

    > sudo gem cleanup -d

You can also cleanup just a specific gem by specifying its name:

    > sudo gem cleanup gemname

for remove specific version like 1.1.9 only

   >  gem uninstall gemname --version 1.1.9

If you still facing some exception to install gem, like:

invalid gem: package is corrupt, exception while verifying: undefined method `size' for nil:NilClass (NoMethodError) in /home/rails/.rvm/gems/[email protected]/cache/nokogiri-1.6.6.2.gem

the, you can remove it from cache:

    > rm /home/rails/.rvm/gems/[email protected]/cache/nokogiri-1.6.6.2.gem

Friday, 10 April 2015

With running Rspec my Ubuntu 14 incredibly slow


The ext4 or fourth extended filesystem is a journaling file system for Linux

As I found, Ubuntu and ext4 partitions dont work good together - I don't know why :(

What I found a way to fix it:

> sudo vi  /etc/fstab

Previously it was following:

UUID=7d4ba8b6-8c0f-493a-bcc7-6d2230ce217a /               ext4   errors=remount-ro 0       1

I did add barrier=0 in following way
UUID=7d4ba8b6-8c0f-493a-bcc7-6d2230ce217a /               ext4   barrier=0,errors=remount-ro 0       1

After above changes in file then:

Restart and run rspec again. If it works then You should see a difference


Also It helps with Ubuntu 14 and Rails 4, Selenium+Capybara tests (no Rspec)

Thursday, 9 April 2015

PhantomJS and setup steps on linux Ubuntu 14.04.1


What is phantomjs!


Full web stack and No browser required

PhantomJS is a headless WebKit scriptable with a JavaScript API. 

> sudo apt-get install phantomjs

If:
> phantomjs --version
-bash: /usr/local/bin/phantomjs: No such file or directory

Then:
>  whereis phantomjs
phantomjs: /usr/bin/phantomjs /usr/lib/phantomjs /usr/bin/X11/phantomjs

> sudo ln -s /usr/bin/phantomjs /usr/local/bin/phantomjs


Check If it works:
> phantomjs --version
1.9.0

That's all!


Monday, 6 April 2015

Compare RUBY ON RAILS

Ruby on Rails (RoR) is very popular Web application frameworks. It is easy for developers to compare Ruby on Rails with other frameworks.
Let’s look at basic differences between Ruby and other languages, below comparison give a simple idea to advantages and disadvantages in Web development:
Ruby vs PHP:
  • A PHP code can executes faster than a RoR code. but a Ruby on Rails application has fewer lines of coding as compared to the same complex application written in PHP :(
  • Ruby on Rails applications works well with UNIX-based server
  • TDD/BDD with test suite code in Ruby on Rails application is simple and fast. In PHP, testing modules and coding is a bit difficult and not easy to understand as compare to rails.
  • RoR application has a clear code structure(mvc) than PHP
  • few frameworks like Zend, Codeigniter, and CakePHP support PHP. In the same way, Vintage, Sinatra and Rails support Ruby.
  • PHP requires less memory space than Ruby. Therefore, PHP applications generally run faster than Ruby on Rails applications.
  • .
  • .
  • .
  • .....

Wednesday, 1 April 2015

Custom Error Pages with Rails 4

Here is how we can integrate custom error pages instead of  default Rails error pages, for 400(Not Found) and other Server Errors.

Following is the example code snippet :

First step is to remove the Rails default error pages from applications "public" folder.

Application Config
#config/application.rb
config.exceptions_app = self.routes

For Production make sure you have following setting in your environment file:

#config/production.rb
config.consider_all_requests_local = false

Also, if you want to test the changes on your local server, do the same setting in your development env file :

#config/development.rb
config.consider_all_requests_local = false

Routes
#config/routes.rb
if Rails.env.production?
   get '404', :to => 'application#page_not_found'
   get '422', :to => 'application#server_error'
   get '500', :to => 'application#server_error'
end

Errors Controller
#controllers/errors_controller.rb
def page_not_found
  respond_to do |format|
    format.html { render template: 'errors/not_found_error', layout: 'layouts/application', status: 404 }
    format.all  { render nothing: true, status: 404 }
  end
end

def server_error
  respond_to do |format|
    format.html { render template: 'errors/internal_server_error', layout: 'layouts/error', status: 500 }
    format.all  { render nothing: true, status: 500}
  end
end

Errors Layout (totally static -- for server errors only)

#views/layouts/error.html.erb
<!DOCTYPE html>
<html>
<head>
  <title><%= action_name.titleize %> :: <%= site_name %></title>
  <%= csrf_meta_tags %>
  <style>
    body {
        background: #fff;
        font-family: Helvetica, Arial, Sans-Serif;
        font-size: 14px;
    }
    .error_container {
        display: block;
        margin: auto;
        margin: 10% auto 0 auto;
        width: 40%;
    }
    .error_container .error {
        display: block; 
        text-align: center;
    }
    .error_container .error img {
        display: block;
        margin: 0 auto 25px auto;
    }
    .error_container .message strong {
        font-weight: bold;
        color: #f00;
    }
    .error_container .contact_info {
        display: block;
        text-align: center;
        margin: 25px 0 0 0;
    }
    .error_container .contact_info a {
        display: inline-block;
        margin: 0 5px;
        opacity: 0.4;
        transition: opacity 0.15s ease;
    }
    .error_container .contact_info a:hover {
        opacity: 0.8;
    }
  </style>
</head>
<body>
  <div class="error_container">
      <%= yield %>
  </div>
</body>
</html>

Error Views

#views/errors/not_found_error.html.erb    
<div class="error">
    <h2>Sorry, this page has moved, or doesn't exist!</h2>
</div>

#views/errors/internal_server_error.html.erb
<div class="error">
    <%= image_tag('layouts/error/alert.png', :width => "150") %>
    <div class="message">
        <strong>Error!</strong>
        We're sorry, but our server is experiencing problems :(
    </div>
    <div class="contact_info">
        <%= link_to image_tag('layouts/error/contact/twitter.png'), "", :title => "Follow Updates On Twitter", :target => "_blank" %>
        <%= link_to image_tag('layouts/error/contact/facebook.png'), "http://www.facebook.com/", :title => "See Progress On Facebook", :target => "_blank" %>
        <%= link_to image_tag('layouts/error/contact/fusion.png'), "", :title => "Catch Our Fusion Feed Updates", :target => "_blank"  %>
        <%= link_to image_tag('layouts/error/contact/instagram.png'), "", :title => "See Updates On Instagram", :target => "_blank"  %>
        <%= link_to image_tag('layouts/error/contact/youtube.png'), "", :title => "See Updates On YouTube", :target => "_blank"  %>
    </div>
</div>

And thats it.... ;)

Go and test it by raising some error in your application like: routing errors etc.