Skip to content

Instantly share code, notes, and snippets.

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

Bernardo bernardobarreto

🚴‍♂️
  • 07:49 (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 / github_followers.html
Created September 13, 2014 00:56
Get followers from GitHub's user using AngularJs
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>GitHub Followers</title>
</head>
<body data-ng-app data-ng-controller='followersController'>
Username:
<input data-ng-model='username' placeholder='username'></input>
<a href='#' ng-click='getFollowers()'> Get Followers </a>
<br/>
@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:
#
@bernardobarreto
bernardobarreto / incrementable_visits.rb
Created November 20, 2017 10:32
rails controller concern example
module IncrementableVisits
extend ActiveSupport::Concern
included do
before_action :increment_visits, only: [:index, :show, :new, :edit]
end
def increment_visits
current_user.inc(visits: 1) # Mongoid ODM example
end
# 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 / bfire_after_format.sh
Last active March 3, 2019 01:08
My UBUNTU after format install script
# Ubuntu
# basic stuff
sudo apt-get install curl git vim chromium-browser terminator zsh vlc unzip --yes
# SSH key
mkdir ~/.ssh
mv chavessh.zip ~/.ssh
cd ~/.ssh
unzip chavessh.zip
@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