Skip to content

Instantly share code, notes, and snippets.

View rjurado01's full-sized avatar

Rafael Jurado González rjurado01

  • NoSoloSoftware Network
  • Spain
View GitHub Profile
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"});
}
}
@rjurado01
rjurado01 / Gemfile
Created January 17, 2017 19:59 — forked from jgwhite/Gemfile
Testing Static HTML with RSpec & Capybara
source :rubygems
gem 'capybara'
gem 'rack'
gem 'rspec'
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'},
# 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}")
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)
/*
* 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);
@rjurado01
rjurado01 / vue_template.rb
Created January 7, 2016 22:49
rails vue templates preprocesor
# config/initializers/vue_template.rb
module Sprockets
class Vue
def self.instance
@instance ||= new
end
def self.call(input)
instance.call(input)
@rjurado01
rjurado01 / sum.rb
Created June 4, 2015 21:28
Solve float point error
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