Skip to content

Instantly share code, notes, and snippets.

View alexcalaca's full-sized avatar

Alexandre Calaça alexcalaca

View GitHub Profile
@alexcalaca
alexcalaca / Immediate versus non-immediate objects benchmark.rb
Created July 18, 2024 04:19
Immediate versus non-immediate objects benchmark
require 'benchmark'
num1 = 42
num2 = 43
immediate_time = Benchmark.realtime do
9_000_000.times do
num1 + num2
end
end
@alexcalaca
alexcalaca / Github cheatsheet-ac.md
Created April 4, 2022 03:38
Github cheatsheet-ac

Github cheatsheet-ac

git log : View commit history git log --stat : View commit history with more details

Gem commands cheatsheet.md

gem list - List all gems installed

gem list -i <gem_name> - It shows if a gem exists or not. The output is true or false

gem list <gem_name> - It shows the gem version Example: gem list zlib

gem which - It shows the gem path

@alexcalaca
alexcalaca / PostgreSQL command line cheatsheet-ac.md
Last active March 26, 2022 17:14
PostgreSQL command line cheatsheet-ac

PostgreSQL command line cheatsheet-ac.md

sudo -u postgres psql : Enter the console \password postgres : E

\du : List all users \l : List of databases \q : Disconnect

@alexcalaca
alexcalaca / Relationships in Rails.md
Created May 29, 2018 22:56
Relationships in Rails_

Visit my website: www.alexandrecalaca.com.br

In our example, there are2 models: Blog and Topic. Think about a single topic blog.

So, A blog can belong to only one topic. A topic has many different blogs.

Blog (N) X (1) topic The foreign key needs to be in the blog model.

@alexcalaca
alexcalaca / How to use enums in Rails.md
Last active May 29, 2018 22:58
How to use enums in Rails

Check my website: www.alexandrecalaca.com.br

  1. First of all, let's generate a migration that it is going to add a status attribute to the table.
rails generate migration add_post_status_to_blogs status:integer
  1. Open the migration you have just created. Your code needs to be something like this:
def change
    add_column :blogs, :status, :integer, default: 0
@alexcalaca
alexcalaca / How to create permalinks in Rails with the friendly_id gem.md
Created May 29, 2018 01:57
How to create permalinks in Rails with the friendly_id gem
@alexcalaca
alexcalaca / How to install rbenv on Cloud9.md
Last active May 17, 2018 12:48
How to install rbenv on Cloud9
@alexcalaca
alexcalaca / How to remove RVM from cloud9.md
Last active April 13, 2024 15:40
How to remove RVM from cloud9