Skip to content

Instantly share code, notes, and snippets.

@danielsousaio
danielsousaio / models.rb
Last active October 27, 2017 22:18
Voting Overview
class Item < ApplicationRecord
has_many :groupings
has_many :lists, through: :groupings
end
class List < ApplicationRecord
has_many :groupings
has_many :items, through: :groupings
end
@danielsousaio
danielsousaio / human.rb
Last active November 7, 2017 22:19
PORO with ActiveModel::Naming
en:
activerecord:
models:
something:
one: Something
other: Somethings
class Something
extend ActiveModel::Naming
end
@danielsousaio
danielsousaio / sample.rb
Created November 8, 2017 01:50
Ethnicity and Users
# models/concerns/ethnicitable.rb
require 'active_support/concern'
module Ethnicitable
extend ActiveSupport::Concern
included do
has_and_belongs_to_many :ethnicities
end
@danielsousaio
danielsousaio / grouping.rb
Created November 18, 2017 11:07
Filtering from Scratch
# This can be improved by Ruby Mixins in the long run, but this is the basics overview
class Grouping < ActiveRecord::Base
# Takes a gender and queries based on it
scope :gender, -> (gender) { where: ... }
end
class GroupingsController < ApplicationController
def index
@groupings = Grouping.all
@danielsousaio
danielsousaio / properties.rb
Last active September 19, 2018 16:08
Filtering with Filterrific and PgSearch
# index.js.haml
- js = escape_javascript(page_entries_info @properties)
$("#results_page_entries_info").html("#{ js }");
- js = escape_javascript(paginate @properties)
$("#results_paginate").html("#{ js }");
- js = escape_javascript(render @properties)
$("#results_properties").html("#{ js }");
# properties_controller.rb
class PropertiesController < ApplicationController

Keybase proof

I hereby claim:

  • I am danielsousaio on github.
  • I am danielsousaio (https://keybase.io/danielsousaio) on keybase.
  • I have a public key ASBSHdY_PHVEAlxi2loFuBj51dYy30Ms-eQAb6Wxgoq0EAo

To claim this, I am signing this object:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC7B11bHkQacEp+jJFTv7zahqaEnDPTcvqLzDs2YiT7p2UaNbmi5Z8JB2E9ML4Ny910UHfWIZJVrZVBddHdToQUgQsFqtZLuzWoqUMXWgZ7GQOET+cBgAiyTPgP5nUr1QNG+vUHfIABJWESRZJw1T8gZMpPxtQ4gRr6Elia1lbjSLNx8dEewVO0bWdoDbhgMkAfTVVlmZohwPH5mTVJo7q4sx/TdKKyfVWtyib3f59cjhn3A6VLeAXDuqlDKeid7/hAmrk+x6egEkdjLrD0QNXeFMjfv5jmQQEvteSNc098w1zoIOpYahcDNULkj39yrytQFZDSW0EAcr2Gg+BEOSoNybPhzmvfzxrRsU+JuhrCQ2AzhzJc+wANOrxd8QRd1t5XqDJC//cQF+BOfIf4V6FyG5TAbUKxld/CkriojDKZ3oVze+crUmM1dGLzey8zaMtybOBdE65ItarmCsSc0OgRlJhxiof4zN6JJHLyzSVqc4xsUpie/xWs/LezGxodPEz8OJsn+tWjyxP/Vo+Y+g69NTqwMUmCzeWtIujSajoNS7vh348AR1NUN6LgsBzrRMyYwgYU5qOjY8cAdfwHhAAG7VNZOGToOYz3yRrnVqqAQrbILNa3H/VtKVf8zfwC5DtcLRoUQ969JpxihlZ06qBeHkLZXCgNvjgs3MHqClixPQ== mail@danielsousa.io
@danielsousaio
danielsousaio / autodetector.md
Last active September 27, 2019 19:57
sys.exit(3) on background job that runs makemigrations - infinite loop

Introduction

Issue: sys.exit(3) on background job that runs makemigrations - infinite loop

PR: https://github.com/crowdbotics/crowdbotics-slack-app/pull/1003

This gist proposes a solution to this issue by doing the same checks Django uses to either ask further questions during migrations creation or not. Currently our background job stays in a loop because we don't provide a valid answer to this questioner. Using the flag --no-input isn't enough as there is still 3 scenarios that raise the questioner.

Calling makemigrations can call either InteractiveMigrationQuestioner or NonInteractiveMigrationQuestioner.

{
"openapi": [
{
"openapi": "3.0.2",
"info": {
"title": "My componentlayout1_dev_6277 API",
"version": "",
"description": "API documentation for componentlayout1_dev_6277 App"
},
"paths": {
let cards = {
Q: { colorCards: "lol", equity: 42 },
A: { colorCards: "lol", equity: 42 }
};
let defaultHand = {
colorCards: "AAA",
equity: 40
};