Test Stripe.js Elements with Capybara

To access and test Stripe.js Element objects with Capybara, try the following:

card_frame = page.evaluate_script("$(\"iframe[src*='fieldName']\").attr(\"name\")")
within_frame card_frame do
  find(".InputElement").set("value")
end

Where fieldName is the name of the Stripe.js Element, for example ‘cardNumber’, and the value is whatever you would like to set the field value to (e.g. 4242 4242 4242 4242)

Note, you may need to wait for the Stripe elements to load, depending on your implementation.

Github: Expand all collapsed files in PR diffs

GitHub will occasionally hide the Diff for various files in your pull requests (PRs). During a large review, this can get a little annoying.

I wanted to avoid installing an extension to solve the problem, so this code will open each of the “Load Diff” areas automatically from the console:

for(i=0; i‹document.getElementsByClassName(“js-button-text”).length; i++){ document.getElementsByClassName(“js-button-text”)[i].click();}

Rails, Capistrano, Database.yml

I’ve found the easiest way to manage the config/database.yml file in a Rails + Capistrano configuration is to add the following line to your capistrano config/deploy.rb configuration file:

set :linked_files, %w{config/database.yml}

Then add config/database.yml to your .gitignore file.

After which, add your environment’s database.yml file to the appropriate location on the remote server(s):

#{deploy_to}/appname/shared/config/database.yml

Where deploy_to is the deploy_to capistrano configuration setting.

This way the configuration parameters are not stored in your repository, but they are still easily updated if needed.

Activate Vuforia in Unity 2017.2+

To activate Vuforia in Unity 2017.2+

  • – Open the “File” menu in the main top menu of Unity.
  • – Select “Build Settings”
  • – In the lower left corner of the “Build Settings” dialog, click the “Player Settings” option
  • – This will open the “Player Settings” dialog in your inspector panel.
  • – Click the “XR Settings” option near the bottom of the “Player Settings” dialog.
  • – Check the “Vuforia Augmented Reality” checkbox.
  • – Accept the Vuforia terms of service.

After accepting the terms, the Vuforia Behavior component settings will be enabled.  Hopefully they’ll add the terms acceptance to the module installation process to avoid these steps in the future, but for now this should get you going.  Although, it looks like ARCore will be out of the preview soon, so Vuforia may just disappear in later releases.

 

Monty Hall Problem in Ruby

Just for fun, the monty hall problem in ruby. Runs simulation one million times.


def monty_hall(switch)
  results = {switching: switch, wins: 0, losses: 0, count: 0, win_percentage: 0}
  (10**6).times.each do |n|
    prizes = [0,0,1].shuffle
    initial_selection = (0..2).to_a.sample
    other_doors = (0..2).to_a - [initial_selection]
    goat = other_doors.select{|n| prizes[n]==0}.sample
    available_selections = [initial_selection, (0..2).to_a - [initial_selection, goat]].flatten
    if switch 
      prize = prizes[available_selections[1]]
    else
      prize = prizes[available_selections[0]]
    end
    results[:wins] += 1 if prize == 1
    results[:losses] += 1 if prize == 0
    results[:count] += 1
  end
  results[:win_percentage] = ((results[:wins].to_f / results[:count].to_f) * 100).round(2)
  return results
end

Capistrano, Rbenv, bundle: command not found

After running

cap production deploy:restart

 
Our remote Puma log would show the following:

-su: bundle: command not found

 
However, this was an active production server, so the bundler gem existed. After logging in and attempting to run a simple command, such as:

bundle exec rails console

 
The console would output the following:

The program 'bundle' is currently not installed. You can install it by typing:
sudo apt-get install bundler

 
So, we looked at the PATH var to ensure RBENV was properly configured

printenv PATH

 
And it was.

If this is your problem (there should be rbenv paths specified here), then edit your ~/.bashrc or ~/.profile or whatever you’re using and add the following lines at the bottom:

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"

 
This will most likely solve the problem you’re noticing.

However, in our case, this was not the issue. RBENV was properly configured, the environment variables were set, and bundler was definitely installed. Next, we figured we’d run

rbenv rehash

 
Just in case something went awry on that front, but we encountered this error:

rbenv: cannot rehash: /home/deployer/.rbenv/shims/.rbenv-shim exists


 
So, we're getting somewhere. This file only exists to avoid colliding rehashes, however, I knew no other rehash's were in progress, so this file must have not be cleaned out during the last rehash for some reason, so we ran:

rm ~/.rbenv/shims/.rbenv-shim

 
And re-ran

rbenv rehash

 
And everything went back to normal.