Skip to content

Instantly share code, notes, and snippets.

View bernardobarreto's full-sized avatar
🚴‍♂️

Bernardo bernardobarreto

🚴‍♂️
  • 18:21 (UTC -03:00)
View GitHub Profile
@bernardobarreto
bernardobarreto / indexeddb-problems.md
Created May 25, 2023 14:35 — forked from pesterhazy/indexeddb-problems.md
The pain and anguish of using IndexedDB: problems, bugs and oddities

This gist lists challenges you run into when building offline-first applications based on IndexedDB, including open-source libraries like Firebase, pouchdb and AWS amplify (more).

Note that some of the following issues affect only Safari. Out of the major browsers, Chrome's IndexedDB implementation is the best.

Backing file on disk (WAL file) keeps growing (Safari)

When this bug occurs, every time you use the indexeddb, the WAL file grows. Garbage collection doesn't seem to be working, so after a while, you end up with gigabytes of data.

Random exceptions when working with a large number of indexeddb databases (Safari)

@bernardobarreto
bernardobarreto / rubocop.rb
Created June 10, 2022 02:47 — forked from skanev/rubocop.rb
A Rubocop wrapper that checks only added/modified code
#!/usr/bin/env ruby
# A sneaky wrapper around Rubocop that allows you to run it only against
# the recent changes, as opposed to the whole project. It lets you
# enforce the style guide for new/modified code only, as opposed to
# having to restyle everything or adding cops incrementally. It relies
# on git to figure out which files to check.
#
# Here are some options you can pass in addition to the ones in rubocop:
#
# frozen_string_literal: true
# specify a directory to install
cask_args appdir: '/Applications'
brew 'bash'
brew 'bash-completion'
brew 'git'
brew 'hub'
brew 'rvm'
@bernardobarreto
bernardobarreto / gist:4d62adf9aa21d7558d8ca3dc73e77f44
Last active June 27, 2019 09:29
ruby array flatten example
def flatten(array)
result = []
array.each do |element|
if element.class == Array
flatten(element).each do |sub|
result << sub
end
else
result << element
end
require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
describe "GET #index" do
#describe "POST #create" do
#describe "GET #show" do
#describe "PATCH #update" do (or PUT #update)
#describe "DELETE #destroy" do
#describe "GET #new" do
@bernardobarreto
bernardobarreto / users_controller.rb
Created May 4, 2019 06:14
Rails standard controller example
class UsersController < ActionController::Base
before_action :set_user, only: [:show, :edit, :update, :destroy]
def index
@users = User.all
end
def show
end
@bernardobarreto
bernardobarreto / mongoid_nested_embeds_many.rb
Created October 8, 2018 21:38 — forked from sporkd/mongoid_nested_embeds_many.rb
Explains how mongoid embeds_many is breaking when nesting more than 1 level deep
class Author
include Mongoid::Document
field :name, :type => String
embeds_many :posts
end
class Post
include Mongoid::Document
field :title, :type => String
embedded_in :author
# From bcrypt-ruby gem
require 'bcrypt'
class User
include DataMapper::Resource
attr_accessor :password, :password_confirmation
property :id, Serial
property :username, String, :required => true, :length => (2..32), :unique => true
property :password_hash, String, :length => 60
@bernardobarreto
bernardobarreto / gist:d90f63cac9c6b6c2afa6bd18f5fee4c8
Created September 9, 2018 00:10 — forked from victorwhy/gist:45bb5637cd3e7e879ace
How Sinatra routes PUT/PATCH and DELETE

HTML and Sinatra really only support the GET and the POST methods. In order to be able to use the PUT and DELETE methods in Sinatra, you kind of have to "trick" the form to go to the right place. Then you can name the routes the proper way - otherwise you can only really work with GET and POST.

I used the Craiglist Jr challenge for some examples. Let's look at a quick example of a POST form/method/route- in this case, we're creating a new Craigslist article:

POST form and corresponding route:

<form action="/article/new" method="post">
  --------------------------------
  YOUR FORM FIELDS HERE
@bernardobarreto
bernardobarreto / browser_testing_on_wsl.md
Created August 22, 2018 20:19 — forked from danwhitston/browser_testing_on_wsl.md
Browser testing for Ruby from within Windows Subsystem for Linux

This is a rough guide to setting up browser testing through Selenium on Windows Subsystem for Linux (WSL), aka Bash on Ubuntu on Windows. It assumes the following environment:

  • Windows 10, running WSL
  • A Ruby dev environment, running inside WSL
  • Code that we want to test using a web driver, in this case Selenium, with a Capybara and RSpec test framework

The coding project folders are stored in the main Windows filing hierarchy and accessed via dev/mnt, but that makes no real difference to development and testing other than making it possible to edit the code using a GUI based editor within Windows.

The problem with browser testing in WSL is that it relies on opening and controlling a web browser, and browsers don’t work on WSL at present as it deliberately doesn’t include X Windows or some other GUI manager - it’s meant to be command line after all. So while you can apt-get firefox, trying to actually run it isn’t going to work.