Skip to content

Instantly share code, notes, and snippets.

@masciugo
masciugo / quotidie_rename
Last active August 29, 2015 14:21
Renaming file in directory
#!/usr/bin/env ruby
# vedi gist at https://gist.github.com/masciugo/9319a809efb6fdff5307
require 'rubygems'
require 'byebug'
require 'logger'
require 'fileutils'
target_dir = case ARGV.size
when 0
@masciugo
masciugo / .sublime-project
Created October 9, 2014 09:33
.sublime-project file example
{
"folders":
[
{
"path": ".",
"folder_exclude_patterns":
[
".bundle",
"log"
],
@masciugo
masciugo / multi-database_pattern.md
Created September 26, 2014 16:54
Rails multi-database pattern

Rails multi-database pattern

The parent class for models that are persisted on a different database app/models/public_database_model.rb:

# Public: Provide a base class for accessing the public database.
# All models inheriting from this class will use by default the data store DB.
class PublicDatabaseModel < ActiveRecord::Base

Tell Active Record (AR) to not look up for a table called like this class,

@masciugo
masciugo / secrets_management.md
Created September 26, 2014 16:48
secrets management in Rails

Rails secrets management with Figaro and Capistrano

Use of figaro gem (or something like dotenv) in all environments.

The Figaro config/application.yml file with all the secrets will be git-ignored. So on every deployment server I had to manually add the file shared/config/application.yml and then linked automatically on each deployment to the current version of the app by adding in config/deploy.rb:

set :linked_files, %w{config/application.yml}

For development config/application.yml is something like the following:

@masciugo
masciugo / test_activerecord.rb
Last active August 29, 2015 14:05
setup activerecord and db to test in irb (outside rails box)
require "rubygems"
require 'active_record'
require "sqlite3"
require "factory_girl"
require 'database_cleaner'
SQLite3::Database.new "test.sqlite3"
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => "test.sqlite3"
@masciugo
masciugo / failing_callbacks_example.rb
Last active August 29, 2015 14:05
Associated objects creation failing in a callback
require "rubygems"
require 'active_record'
require "sqlite3"
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => "test.sqlite3"
)
ActiveRecord::Migration.class_eval do