This file contains hidden or 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
| const fixScrollToInput = () => { | |
| // resize is not finished (body height must be smaller because keyboard) | |
| if (document.body.offsetHeight == window.bodyHeight) { | |
| setTimeout(fixScrollToInput, 100); | |
| } | |
| // check if element is hidden by keyboard | |
| else if (document.activeElement.getBoundingClientRect().top > document.body.offsetHeight) { | |
| document.activeElement.scrollIntoView({behavior: 'smooth', lock: "center"}); | |
| } | |
| } |
This file contains hidden or 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
| source :rubygems | |
| gem 'capybara' | |
| gem 'rack' | |
| gem 'rspec' |
This file contains hidden or 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 SpainRegions | |
| def self.states | |
| return [{'code'=>'AN', 'name'=>'Andalucía'}, | |
| {'code'=>'AR', 'name'=>'Aragón'}, | |
| {'code'=>'AS', 'name'=>'Asturias, Principado de'}, | |
| {'code'=>'CN', 'name'=>'Canarias'}, | |
| {'code'=>'CB', 'name'=>'Cantabria'}, | |
| {'code'=>'CM', 'name'=>'Castilla-La Mancha'}, | |
| {'code'=>'CL', 'name'=>'Castilla y León'}, | |
| {'code'=>'CT', 'name'=>'Catalunña'}, |
This file contains hidden or 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
| # test drag and drop of jquery-ui-sortable with capybara | |
| # based on: http://heywill.com/blog/2012/12/15/using-capybara-to-drag-a-jquery-ui-sortable-onto-a-jquery-ui-droppable | |
| offset = page.evaluate_script("$('#sortable').offset()") | |
| top = offset['top'] + 20 | |
| left = offset['left'] | |
| page.execute_script("$('body').append('<div id=\"test\" style=\"position: fixed; top: #{top}px; left: #{left}px; width: 10px; height: 10px;\"></div>');") | |
| element = page.find("#item_#{item.id}") |
This file contains hidden or 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 Spot | |
| field :location, type: Array | |
| index({ location: '2d' }, { min: -180, max: 180 }) | |
| end | |
| Spot.create_indexes | |
| Spot.create(location: [1,0]) | |
| Spot.create(location: [3,0]) | |
| Spot.where(location: {"$near" => {lng: 0, lat: 0}, "$maxDistance" => 2}).all.map(&:location) |
This file contains hidden or 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
| /* | |
| * Serialize value | |
| */ | |
| function serializeValue(key, value, formData) { | |
| if(value) { | |
| if($.type(value) == "string" || $.type(value) == 'number' || value.constructor == File) { | |
| formData.append(key, value); | |
| } | |
| else if($.type(value) == "array") { | |
| serializeArray(key, value, formData); |
This file contains hidden or 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/initializers/vue_template.rb | |
| module Sprockets | |
| class Vue | |
| def self.instance | |
| @instance ||= new | |
| end | |
| def self.call(input) | |
| instance.call(input) |
This file contains hidden or 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 sum(a, b) | |
| a_dec = a.to_s.split('.')[1] | |
| b_dec = b.to_s.split('.')[1] | |
| len1 = a_dec ? a_dec.size : 0 | |
| len2 = b_dec ? b_dec.size : 0 | |
| max_len = len1 > len2 ? len1 : len2 | |
| factor = 10 ** max_len | |
| if max_len > 0 |