Skip to content

Instantly share code, notes, and snippets.

View tonyfg's full-sized avatar

Tony Gonçalves tonyfg

View GitHub Profile
@tonyfg
tonyfg / frontend-stuff.txt
Created July 7, 2022 22:04
Frontend stuff
https://daisyui.com - Premade Tailwind CSS components. Looks great and needs way less classes on your HTML
@tonyfg
tonyfg / docker-compose.yml
Created November 18, 2020 11:27
Docker compose file for home assistant + domoticz + mosquitto + zigbee2mqtt
version: "3"
services:
domoticz:
image: linuxserver/domoticz:latest
container_name: domoticz
environment:
- PUID=19000
- PGID=19000
- TZ=Europe/Lisbon
volumes:
https://learnui.design/tools/data-color-picker.html
https://design-system-playground.netlify.com
@tonyfg
tonyfg / Gems.txt
Last active February 9, 2022 18:56
Gems
Code quality:
rubocop - linter
https://github.com/prettier/plugin-ruby - (NOT A GEM!) Prettier for ruby
overcommit - git hooks to run linting before commits, etc
bundler-audit - check your gemfile for outdated gems with security issues
bundler-leak - check your gemfile for gems with known memory leaks
brakeman - rails static code analyzer with a focus on security
sqlint - linter for SQL code (I know, not ruby, but useful for a lot of ruby apps)
Background jobs:
@tonyfg
tonyfg / oj.rb
Created September 14, 2018 12:52
Rails OJ initializer
# config/initializers/oj.rb
Oj.optimize_rails
@tonyfg
tonyfg / select_joins.rb
Created September 14, 2018 12:43
Org list #index optimized with .select and .joins
#
# app/controllers/organizations_controller.rb
#
# old action
def index
@organizations = Organization.all
end
# new action
@tonyfg
tonyfg / organizations_controller.rb
Created September 14, 2018 10:54
Org list #index optimized with .includes
# old action
def index
@organizations = Organization.all
end
# new action
def index
@organizations = if request.format.html?
Organization.includes(hqs: :country).all
else
@tonyfg
tonyfg / index.json.jbuilder
Created September 14, 2018 09:50
Org list JSON views
# app/views/organizations/index.json.jbuilder
json.array! @organizations, partial: 'organizations/organization', as: :organization
# app/views/organizations/_organization.json.jbuilder
json.extract! organization, :id, :name, :address, :contact_name, :contact_phone, :created_at, :updated_at
json.url organization_url(organization, format: :json)
json.hqs organization.hqs do |hq|
json.extract! hq, :id, :name
@tonyfg
tonyfg / index.html.erb
Created September 14, 2018 09:48
Org list HTML views
# app/views/organizations/index.html.erb
<table>
<tbody>
<% @organizations.each do |organization| %>
<tr>
<td><%= organization.name % ></td>
<td><%= organization.address %></td>
<td><%= organization.contact_name %></td>
<td><%= organization.contact_phone %></td>
@tonyfg
tonyfg / organizations_controller.rb
Created September 14, 2018 09:43
Org list unoptimized #index action
# app/controllers/organizations_controller.rb
class OrganizationsController < ApplicationController
def index
@organizations = Organization.all
end
end