Marcelo Alves
user

Marcelo Alves

Notes and musings from a web developer in Central California


Featured

notes ios pwa safari

Prevent Links From Escaping Full Screen App

Posted on .

After adding a site to your homescreen in iOS, Safari does this weird thing where links will end up opening up a new browser window. This snippet of javascript prevents that:

$(document).ready(function(){
  if(window.navigator.standalone == true) {
    $('a').click(function(e) {
      window.location = $(this).attr('href');
      return false;
    });
  }
});

However when using Bootstrap, dropdown links stop working. Adding something like this seems to solve the issue:

if($(e.target).hasClass('dropdown-toggle')) {
  return;
}
Featured

notes bootstrap responsive

Disable Zoom on Field Selection

Posted on .

Update the viewport meta tag to keep mobile browsers from zooming in when selecting a field:

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">

Featured

notes ruby

JSON.parse with object_class

Posted on .

You can pass an object_class to JSON.parse which will use that class to create an object. Can pass OpenStruct to create a simple object or something like an ActiveRecord class.

json_data = '{"id": 1,"name": "A green door","price": 12.50,"tags": ["home", "green"]}'

parsed_json = JSON.parse(json_data, object_class: OpenStruct)

p parsed_json.name
# "A green door"
Featured

tutorials lambda

Create Images from PDF's Using Lambda

Posted on .

Easily create thumbnails from uploaded PDF’s

Featured

notes ruby

find_by vs find_by!

Posted on .

.find_by will return a nil when record isn’t found. .find_by! will return ActiveRecord::RecordNotFound.