Skip to content

Instantly share code, notes, and snippets.

View goncalvesjoao's full-sized avatar

Joao Goncalves goncalvesjoao

View GitHub Profile
@goncalvesjoao
goncalvesjoao / _form.html.erb
Created March 24, 2020 18:49
CarrierWave: add and remove individual images using multiple file upload, without loosing the previously selected one.
<!-- Requires bootstrap css for style -->
<%= form_with(model: @post, local: true, html: { multipart: true }) do |f| %>
<label class="control-label">Images</label>
<div id="file-list" class="mb-2 flex">
<% @post.images.each do |image| %>
<div class="position-relative mr-3 text-center file-preview" style="width: min-content;">
<div class="img-thumbnail">
<%= image_tag(image.thumb.url || 'https://icons.iconarchive.com/icons/zhoolego/material/512/Filetype-Docs-icon.png', height: 100) %>
@goncalvesjoao
goncalvesjoao / health_check.rb
Last active May 20, 2019 09:40
Rack App to return your Rails app health status
# Your Ruby Rack App that returns your Rails App's Health
# Create the file
# "lib/rack/health_check.rb"
module Rack
class HealthCheck
def call(env)
status = {
redis: {
connected: redis_connected
@goncalvesjoao
goncalvesjoao / bash command: copy a Heroku database to another
Last active February 28, 2018 08:34
copy a Heroku database to another
$> heroku pg:copy app_name_to_copy_from::DATABASE_URL DATABASE_URL --app app_name_to_copy_to
@goncalvesjoao
goncalvesjoao / bash command: restoring Heroku postgres snapshot
Created January 18, 2018 03:26
Restoring Heroku postgres snapshot
$> pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d <database name> <heroku snapshot file>
@goncalvesjoao
goncalvesjoao / bash command to export heroku config vars
Last active January 18, 2018 02:29
export heroku config vars to an .env file
$> heroku config -s -a <heroku app> >> .env
@goncalvesjoao
goncalvesjoao / database.yml
Created December 1, 2017 00:57
rails postgres database.yml example
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: app_name_development
username: postgres
password:
@goncalvesjoao
goncalvesjoao / wysiwyg.css
Last active February 21, 2018 06:33
[VanillaJs] Trix v0.11.1 Toolbar attachment file button
.trix-button--icon-attach-files::before {
background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA%2FPjxzdmcgaGVpZ2h0PSIxNnB4IiB2ZXJzaW9uPSIxLjEiIHZpZXdCb3g9IjAgMCAyNCAxNiIgd2lkdGg9IjI0cHgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6c2tldGNoPSJodHRwOi8vd3d3LmJvaGVtaWFuY29kaW5nLmNvbS9za2V0Y2gvbnMiIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIj48dGl0bGUvPjxkZXNjLz48ZGVmcy8%2BPGcgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIiBpZD0iUGFnZS0xIiBzdHJva2U9Im5vbmUiIHN0cm9rZS13aWR0aD0iMSI%2BPGcgZmlsbD0iIzAwMDAwMCIgaWQ9IkNvcmUiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0xMjYuMDAwMDAwLCAtNDYuMDAwMDAwKSI%2BPGcgaWQ9ImJhY2t1cCIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMTI2LjAwMDAwMCwgNDYuMDAwMDAwKSI%2BPHBhdGggZD0iTTE5LjQsNiBDMTguNywyLjYgMTUuNywwIDEyLDAgQzkuMSwwIDYuNiwxLjYgNS40LDQgQzIuMyw0LjQgMCw2LjkgMCwxMCBDMCwxMy4zIDIuNywxNiA2LDE2IEwxOSwxNiBDMjEuOCwxNiAyNCwxMy44IDI0LDExIEMyNCw4LjQgMjEuOSw2LjIgMTkuNCw2IEwxOS40LDYgWiBNMTQsOSBMMTQsMTMgTDEwLDEzIEwxMCw5IEw3LDkgTDEyLDQgTDE3LDkgTDE0LDkgTDE0LDkgWiIgaWQ9IlNoYXBlIi8%2B
@goncalvesjoao
goncalvesjoao / d_t.rb
Created June 20, 2016 12:34
date time abstraction that enables tests to manipulate the current date
module DT
extend self
DEFAULT_TIME_ZONE = 'Lisbon'
def now
(mock_data(:now) || DateTime.now).utc
end
@goncalvesjoao
goncalvesjoao / Gemfile
Last active November 13, 2020 01:52
Changes you need to make in order to make Devise use JWT Header Authentication
# Add the "https://github.com/jwt/ruby-jwt" gem to your "Gemfile"
gem 'jwt'
@goncalvesjoao
goncalvesjoao / inactive_support_helper_methods.rb
Last active March 4, 2016 17:07
Some helper methods to avoid simple ruby gems to include active_support
module Helpers
extend self
def super_method(object, method_name, *args)
return nil unless object.superclass.respond_to? method_name
object.superclass.send method_name, *args
end