Posts

Client side validations + Dynamic forms

Few things that might be helpful when working with client side validations. I am using client side validations in rails using gem Client side validations To validate forms dynamically added to the page, we need to use the validate function manually for that form. For example: If you dynamically render the following rails template into you view: <%= form_for @model, :validate => true, :id => 'my_dynamic_form' do |f| %> <%= f.text_field :some_attribute %> <% end %> $("form#my_dynamic_form").validate(); Reset Validations $("form#my_dynamic_form").resetClientSideValidations();

Inserting and Moving elements inside Ruby Array

Here's is an array with 5 elements 2.1.2 :001 > arr = ["a", "b", "c", "d", "e"] => ["a", "b", "c", "d", "e"] Lets look at few different cases Insert a new element at starting position Using unshift 2.1.2 :002 > arr.unshift("f") => ["f", "a", "b", "c", "d", "e"] Using insert 2.1.2 :005 > arr.insert(0, "f") => ["f", "a", "b", "c", "d", "e"] In the above example 0 is the position(index) Move existing element from one position to another The element in this case is "e" Using uniq to show only unique elements 2.1.2 :009 > arr.insert(0, "e").uniq => ["e", "a", "b", "c", "d"] With uniq we are only showing unique records but the element is listed ...

Execute JavaScript + Capybara

There are certain cases where we need some custom JavaScript while writing some Integration test cases. For such cases you can use page.execute_script. For Example page.execute_script("$('#blog-hover-#{blog.id}').show();")

Setting the size of Browser Window + Selenium and Capybara

window = Capybara.current_session.driver.browser.manage.window window.resize_to(1200, 800) You can add this inside setup block. class CapybaraIntegrationTest < ActionDispatch::IntegrationTest # Make the Capybara DSL available in all integration tests include Capybara::DSL setup do window = Capybara.current_session.driver.browser.manage.window window.resize_to(1250, 800) end end

Committing partial changes from file in Git

git add -p file -p stands for patch mode, You can also use git add --patch file This gives the user a chance to review the difference before adding modified contents to the index.

Revert the pushed code in wrong git branch using Cherry pick

git checkout wrong_branch git revert commitsha1 # Code for wrong commit git revert commitsha2 # Code for wrong commit git checkout right_branch git cherry-pick commitsha1 # Code for wrong commit git cherry-pick commitsha2 # Code for wrong commit   If you have multiple commits and there are no commits pushed after your dirty commits, you can even use git reset to get that wrong branch to a state just before your commits and then follow that again using git cherry-pick to get your commits into the right branch. git checkout wrong_branch git reset commitsha3 #commit just before commitsha2, this will reset the whole branch to previous state git checkout right_branch git cherry-pick commitsha1 git cherry-pick commitsha2

Install phpMyAdmin with mysql on ubuntu

To install it on your ubuntu system you can use apt-get which is the easiest way. phpMyAdmin is a good option, if you don't want to install LAMPP. Please follow the below mentioned steps, these will guide you through each and every step of installation. Step 1 sudo apt-get install phpmyadmin Step 2 Select Apache2 for the server Step 3 Choose YES when asked about whether to Configure the database for phpmyadmin with dbconfig-common Step 4 Enter your MySQL password when prompted Step 5 Enter the password that you want to use to log into phpmyadmin Step 6 After the installation has completed, add phpmyadmin to the apache configuration. sudo nano /etc/apache2/apache2.conf If you are not comfortable with nano, you can use gedit sudo gedit /etc/apache2/apache2.conf Step 7 Add the phpmyadmin config to the file. Include /etc/phpmyadmin/apache.conf Step 8 Restart apache: sudo service apache2 restart