Wednesday 22 February 2017

[SOLVED] Rails multiple databases not cleaning up in tests.

So the other day I was facing this issue with Rails where the data created in a test would not get deleted from my secondary database.

The database was not cleaning up after the first test. the order didn’t matter. which ever test runs first the records created in that block were not deleted. after thorough debugging i found that there is a block inside actived record which rollsback the db. here is that block (https://github.com/rails/rails/blob/master/activerecord/lib/active_record/fixtures.rb#L1008).

 So in case of the first test the @fixture_connections count is 1 it only contains the primary db connection.

So for my secondary db I had created an abstract class SecondaryModel  which inherited from  ActiveRecord::Base 
So adding SecondaryModel.connection to test_helper solved this problem.

hope this helped!

Wednesday 11 January 2017

[SOLVED] Mac Self Assigned IP Address issue with wifi

The other day I was facing this problem while connecting to the new internet connection in my office. after searching on the interned it took me a while to fix
The solution I am going to present is same as pulling the plug but it worked for me.

So this solution worked in the below scenario for me where the router IP is not present.
click on the wifi icon => select open network preferences => click advanced => select TCP/IP

Now if you have this scenario simply follow the below steps

-- Open the finder
-- click file => Go
-- Enter '/Library/Preferences/SystemConfiguration'
-- And delete the below files (Dont worry the OS will regenerate these files but to be on safe side just move them to trash)
com.apple.airport.preferences.plist
com.apple.network.eapolclient.configuration.plist
NetworkInterfaces.plist
preferences.plist
-- Restart your computer
This worked for me. let me know if it doesn't work for you.

Wednesday 10 August 2016

How to set flash error when devise reset password token is expired in Active Admin

So I was facing this issue a while ago when I wanted to show an error on Active Admin when the password token is expired. By default devise doesn't show error when the token is expired. check the below devise update code

  # PUT /resource/password
  def update
    self.resource = resource_class.reset_password_by_token(resource_params)
    yield resource if block_given?
    if resource.errors.empty?
      resource.unlock_access! if unlockable?(resource)
      if Devise.sign_in_after_reset_password
        flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
        set_flash_message(:notice, flash_message) if is_flashing_format?
        sign_in(resource_name, resource)
      else
        set_flash_message(:notice, :updated_not_active) if is_flashing_format?
      end
      respond_with resource, location: after_resetting_password_path_for(resource)
    else
      set_minimum_password_length
      respond_with resource
    end
  end

So as you can see if the condition resource.errors.empty?  is false it does not set any errors in the else block.
So one way to solve this is to override the whole method and add flash[:error] in the else block like this

ActiveAdmin::Devise::PasswordsController.class_eval do
  def update
    self.resource = resource_class.reset_password_by_token(resource_params)
    yield resource if block_given?

    if resource.errors.empty?
      resource.unlock_access! if unlockable?(resource)
      if Devise.sign_in_after_reset_password
        flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
        set_flash_message(:notice, flash_message) if is_flashing_format?
        sign_in(resource_name, resource)
      else
        set_flash_message(:notice, :updated_not_active) if is_flashing_format?
      end
      respond_with resource, location: after_resetting_password_path_for(resource)
    else
      flash[:error] = resource.errors.full_messages.to_sentence
      set_minimum_password_length
      respond_with resource
    end
  end
end

but this is not a very smart way to handle this as I am repeating a lot of the code. so I thought of another DRY way to do this

ActiveAdmin::Devise::PasswordsController.class_eval do
  def update
    super
    if resource.errors.any?
      flash[:error] = resource.errors.full_messages.to_sentence
    end
  end
end

Although this looks fine but it doesn't work as the flash message is shown in the next request.
after a while of searching here and there my eye caught the following code in the devise method

yield resource if block_given?

 and here is the solution I came up with.

ActiveAdmin::Devise::PasswordsController.class_eval do
  def update
    super do |resource|
      if resource.errors.any?
        flash[:notice] = resource.errors.full_messages.to_sentence
      end
    end
  end
end

Hope it helped :)

Sunday 7 February 2016

My experience of Crossover hiring process

I am writing this post to share my experience of applying for a remote position at crossover as i wasn't able to find any online article about the whole experience of it before taking their tests and trials while the ones I found were very biased and i think did not reflect the truth.
The position I applied for was for ruby software engineer.Although i wasn't selected for the position but i would still try to be unbiased about the whole process.

Step 1:
So I visited their website created an account and it took me to a link where i was supposed to take a test by hackerrank. The test was no very complicated and after completing the test I received an email that I would be notified by an email with in 24hours. The next day i received an email from them saying them that i scored well on my test and I was already in the top 10%.

Step 2:
Next Step was to create to a profile that was pretty easy as i just have to import my linkedIn profile in and I was good to go

Step 3:
Step 3 is the most important one where you are given a technical trial. You have to complete it with in 3 days. They tell you that its almost a 10 hour job but believe me it takes more than that.

Here is what they asked me to develop in the technical trial

Preconditions

You should work on your local machine.
You may use any development IDE.
You may use Rails framework or you can use another Ruby web framework.
You may use MySql

Requirements
Objective

Create a simple task scheduler using an agent client and a server task controller.

Functional Specifications

Create a agent / server application, which will execute scheduled tasks in client side.



Technical Specifications

The following list of technical specifications should be adhered to:

1)For the web application
Create a database with any required tables.
Create a  web REST application.
Create a website which will show the following data from servers scheduled tasks  :
Start date and time
Execution time
Stop date and time
Process executed
Website should be configurable, you must include a CRUD to schedule tasks, using the                       fields :
-Task name
-Executable path
-Start date and time
-End date and time
-Days of the week to be executed.
-Server which will execute the task. (When installing the agent, it will provide a key to the                     server, this key will link server-task)

                Website will show a log of  the tasks executed and failed.
Apply input validations and constraints wherever necessary to create a stable application.
Create an Agent client which will be installed and should run automatically in client side.
2)For the web service
Create a secured REST web service.
3)The application and services should not be dependent on each other in any way.
4)Even if you are not able to complete all the tasks, try to achieve a working application and                   service.

Deliverables

Application Demo

Record the demonstration of the web application/agent using Wink. Do not upload the video.               Save it to your local machine.

Database script

Create a single SQL script file to create the database, its schema, any stored procedure and any           test data you may use.

Readme

Create a txt file with the following information

Steps to create and initialize the database
Steps to prepare the source code.
Any assumptions made and missing requirements that are not covered in the requirements
Any feedback you may wish to give about improving the assignment.  
Design diagrams

Create a doc file containing the following information and diagrams

List of technologies and design patterns used
An overall activity diagram

To be evaluated
The quality of the output (functionality)
Code quality and completeness
Technologies applied
Extra validations and assumptions which are not described
Add missing requirements to the implementation, according to your experience.
     
Delivery / What to submit
Please, read and follow this section carefully. Any delivery that does not follow this section will         score much less or simply won't be evaluated.

Delivery for this assignment should consist of an archive named <your_name> - Software                   Engineer - Ruby.zip containing the following

Source code/project
Wink recording, download version 2 from Wink, render the video to swf format
Readme.txt containing the instructions to configure and run the application, notes and feedback
Design.doc with needed diagrams
Structure of the resulting zip file should be of the following format

<your_name> - Software Engineer - Ruby.zip
<your_name> - Software Engineer - Ruby.zip \Readme.txt
<your_name> - Software Engineer - Ruby.zip \Design.doc
<your_name> - Software Engineer - Ruby.zip \Wink\   <<< this folder should contain the wink            recording
<your_name> - Software Engineer - Ruby.zip \Source\   <<< this folder should contain the                 complete source code for the project(s)



So first of all as you can see the requirements are incomplete so be prepared to make alot of assumptions, secondly wink is a very outdated software and doesn't work properly with Linux i don't know why they put this condition in the trial. and yes when you start your trial you are not supposed to ask any questions regarding the trial.

I stared the trial a few days late during that time i received a call from their US number that I should attempt it as soon as possible as they are hiring on rolling basis and that i scored pretty well on my hackerrank test.
You can request for an extension,which I did as well, although my reason was very legit they gave me an extension as well,

Step 4:
After submitting the project i got an email next day that I have to appear for a skype interview, I thought that my project was accepted as on the website it was mentioned that skype interview is the next stage of the process.
During this time i received another call from them saying that i should schedule my interview asap.
When i appeared for the skype interview a guy named omar valadez was taking my interview. Before the interview i looked him up on the internet and i found out that he was a .Net specialist at that point i was skeptical about this whole process that why a .NET specialist is interviewing for the position of ruby engineer.
Anyways during the interview he told me that they liked my project and asked some very simple questions which i answered instantly and told me share my screen for a small coding task.

The task required me to do some prime number manipulation which was pretty easy to do.

After I explained the task he said well done and if i had any questions, I asked about time flexibility but he said you can discuss that in your next interview with manager and that i would receive an email about the interview in a few days.

Everything was going good and exactly after one hour i received an email that they were unable to continue with my application as my trial project(The 3 day project in step 3) was not selected because i didn't include the test data in the project.

Now I don't understand if they didn't liked my project why did they called me for an interview. I received a call twice on my number suggesting that I am performing well so far and all of a sudden they rejected my application which was very disappointing not because i wasn't selected but because of the time I spent on this whole process.
My opinion is that they do not have a big enough client base and more people are applying for remote positions so they have to reject alot of candidates to avoid over hiring.(I might be wrong this is just an opinion)

Anyways this article was just about sharing my experience of the crossover hiring process so that people applying in future should know about the process before hand.