Skip to content

Instantly share code, notes, and snippets.

View Joseworks's full-sized avatar

Jose C Fernandez Joseworks

View GitHub Profile
@Joseworks
Joseworks / rebase.sh
Created June 12, 2024 14:06 — forked from darronz/rebase.sh
Bash script to rebase your current branch on master
#!/bin/bash
# store name of current branch
BRANCH=$(git branch | grep \* | cut -d ' ' -f2)
# checkout master
git checkout master
# pull the latest changes
git pull
@Joseworks
Joseworks / spec.rb
Created April 22, 2024 16:56 — forked from antillas21/spec.rb
Stubbing an ActiveRecord::Relation object
# first we create an empty ActiveRecord::Relation object
relation = Model.where(attribute: value)
# then we make the relation stub the :[] method
# and return whatever values we need
relation.stub(:[]).and_return( Model.new({attrs: values})] )
# of course, we can make this too
# instead of the step above
record = double("Model", :foo => 'bar', :bar => 'baz')
@Joseworks
Joseworks / README.md
Created February 12, 2024 14:53 — forked from jherax/README.md
Git Alias and Rebase

Git Alias and Git Rebase

WHEN TO DO REBASE

After each commit in our branch, in order to be up-to-date with the integration branch.

This is a tool to find association paths between different models in a rails app.

Example output - the paths from Job to Invoice:

[3] pry(main)> G.from(Job).to(Invoice)
Job.active_fleet_managed_invoice_from_swoop -- Invoice

Job.invoice >- Invoice

Job.owning_company >- Company.fleet_managed_clients -- FleetCompany.end_user_invoices -< Invoice
@Joseworks
Joseworks / .gitattributes
Created October 5, 2023 16:19 — forked from phil-blain/.gitattributes
Git pickaxe : show only relevant hunks (filter displayed hunks using the given search string)
*.md diff=markdown
@Joseworks
Joseworks / rspec-be-within-matcher.rb
Created September 13, 2023 20:27 — forked from equivalent/rspec-be-within-matcher.rb
Several examples how to use Ruby RSpec 3 `be_within` matcher for delta compare
require 'rspec'
require 'time'
require 'active_support/time'
class Foo
def float_range_example
33 * 5 * Math::PI
end
def time_range
@Joseworks
Joseworks / gist:29fe3336955174e0fc97249d3cf4202c
Created February 25, 2021 14:27 — forked from JFernandezWM/gist:d2e0e31afe8f9681612f05c578d94e01
Update to factory bot shell scripts for Mac that actually work...
find . -type f -name '*.rb' -exec sed -i '' s/FactoryGirl/FactoryBot/ {} +
find . -type f -name '*.rb' -exec sed -i '' s/factory_girl/factory_bot/ {} +
This:
from https://github.com/thoughtbot/factory_bot_rails/issues/247
grep -rl 'FactoryGirl' ./ | xargs sed -i '' 's/FactoryGirl/FactoryBot/g'
@Joseworks
Joseworks / ruby_on_rails_deployment.md
Created February 25, 2021 14:27 — forked from zentetsukenz/ruby_on_rails_deployment.md
Deploy Ruby on Rails application with Docker Compose and Capistrano with ease

Docker

Files and Folders.

|
|\_ app
|...
|\_ docker
| |
@Joseworks
Joseworks / GitCommitEmoji.md
Created February 25, 2021 14:26 — forked from parmentf/GitCommitEmoji.md
Git Commit message Emoji
@Joseworks
Joseworks / time_vs_datatime.md
Created February 25, 2021 14:25 — forked from pixeltrix/time_vs_datatime.md
When should you use DateTime and when should you use Time?

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000