Skip to content

Instantly share code, notes, and snippets.

View adimircolen's full-sized avatar

Adimir Colen adimircolen

View GitHub Profile
@hiasinho
hiasinho / factory_girl_strategy_find_or_create.rb
Last active May 27, 2020 18:31
FactoryGirl strategy for adding find & find_or_create
## http://stackoverflow.com/questions/7145256
module FactoryGirl
module Strategy
class Find
def association(runner)
runner.run
end
def result(evaluation)
build_class(evaluation).where(get_overrides(evaluation)).first
@pauloschiavon
pauloschiavon / 2015-06-08-post-01.md
Last active August 29, 2015 14:22
Alternativa para criação de modelos/tabelas de domínio

Motivação

Sempre torci o nariz para criação de modelos de domínios (status.rb, genero.rb, tipo.rb, ...), principalmente quando o usuário não terá acesso para adicionar ou editar estes dados. Uma alternativa para isto é criar um modulo onde os domínios serão hashs:

# app/utilities/data_base.rb
module DataBase
  def self.gender
    { "Male"    => 1, 
      "Female"  => 2
 }
@jgillman
jgillman / restore.sh
Last active February 6, 2025 02:39
pg_restore a local db dump into Docker
# Assumes the database container is named 'db'
DOCKER_DB_NAME="$(docker-compose ps -q db)"
DB_HOSTNAME=db
DB_USER=postgres
LOCAL_DUMP_PATH="path/to/local.dump"
docker-compose up -d db
docker exec -i "${DOCKER_DB_NAME}" pg_restore -C --clean --no-acl --no-owner -U "${DB_USER}" -d "${DB_HOSTNAME}" < "${LOCAL_DUMP_PATH}"
docker-compose stop db
@jcberthon
jcberthon / update-docker-compose.sh
Last active December 20, 2021 02:56
Downloading and installing/updating latest Docker Compose (command line)
#!/bin/bash
# Copyright 2017-2018 Jean-Christophe Berthon
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software