This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flatten(array) | |
return "Input must be an array" if !array.kind_of?(Array) | |
array.reduce([]) do |res, el| | |
Array === el ? res + flatten(el) : res << el | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Customer | |
include Math | |
EARTH_RADIUS = 6371 # Earth Radius in km | |
attr_accessor :id, :name, :latitude, :longitude | |
def initialize(params) | |
@id = params["user_id"] | |
@name = params["name"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Navigating | |
visit('/projects') | |
visit(post_comments_path(post)) | |
expect(page).to have_current_path(post_comments_path(post)) | |
# Clicking links and buttons | |
click_link('id-of-link') | |
click_link('Link Text') | |
click_button('Save') | |
click_on('Link Text') # clicks on either links or buttons |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upload(files) { | |
const config = { | |
onUploadProgress: function(progressEvent) { | |
var percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total) | |
console.log(percentCompleted) | |
} | |
} | |
let data = new FormData() | |
data.append('file', files[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"atomKeymap.promptV3Features": true, | |
"editor.multiCursorModifier": "ctrlCmd", | |
"editor.formatOnPaste": true, | |
"files.insertFinalNewline": true, | |
"files.trimTrailingWhitespace": true, | |
"editor.renderWhitespace": "all", | |
"editor.tabSize": 2, | |
"explorer.confirmDragAndDrop": false, | |
"terminal.external.osxExec": "iTerm.app", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ruby CircleCI 2.0 configuration file | |
# | |
# Check https://circleci.com/docs/2.0/language-ruby/ for more details | |
# | |
version: 2 | |
jobs: | |
build: | |
docker: | |
# specify the version you desire here | |
- image: circleci/ruby:2.4.1-node-browsers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MyApp::Application.configure do | |
# Restrict access with HTTP Basic Auth for staging environment | |
if ENV['STAGING_AUTH'] | |
config.middleware.use Rack::Auth::Basic do |username, password| | |
ENV['STAGING_AUTH'].split(':') == [username, password] | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios' | |
const tokenEl = document.getElementsByName('csrf-token')[0] | |
if (tokenEl) { | |
const token = tokenEl.getAttribute('content') | |
axios.defaults.headers.common['X-CSRF-Token'] = token | |
} | |
axios.defaults.headers.common['Accept'] = 'application/json' | |
axios.defaults.headers.post['Content-Type'] = 'application/json' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/routes.rb | |
resources :documents do | |
scope module: 'documents' do | |
resources :versions do | |
post :restore, on: :member | |
end | |
resource :lock | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActionView::Base.field_error_proc = proc do |html_tag, instance_tag| | |
fragment = Nokogiri::HTML.fragment(html_tag) | |
field = fragment.at("input,select,textarea") | |
html = if field | |
field["class"] = "#{field["class"]} is-invalid" | |
html = <<-HTML | |
#{fragment} | |
<p class="invalid-feedback">#{instance_tag.error_message.to_sentence}</p> | |
HTML |
OlderNewer