vince

Override update_counters from counter_cache: true

```ruby class Post < ApplicationRecord belongsto :author, countercache: true end class Author < ApplicationRecord has_many :posts def self.updatecounters(id, counters) Author.find(id).dos...

  • Updated 8 months ago by vince
Remove folder and all files inside it in Terminal

using rm can be very dangerous if you're not careful -- get in the habit of using mv instead do this mv .git ~/.Trash instead of rm -rf .git the first command is safer on many levels

  • Updated 8 months ago by vince
Branch from a previous commit on master as though the branch was made before ...

remove the commits from master as though you had made the branch before those commits were made git checkout master git branch branch-name git reset --hard <sha1>

  • Updated 8 months ago by vince
Create alias to stash untracked files with a message

git config --global alias.stush 'stash push -u -m' then instead of git stash push -u -m "helpful message" you can just do git stush 'helpful message'

Change (Amend) commit message

if you just made a commit and want to change the message git commit --amend -m "better commit message"

  • Updated 8 months ago by vince
Git stash

takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them git stash -u git checkout master git checkout crazy-experiment git stash pop stash ...

Serialized Hash in Rails form

review of what a hash is ```ruby schedule = {mon: true, tue: false, wed: true} schedule[:mon] => true schedule[:tue] => false schedule[:wed] => true schedule[:thu] => nil schedule.class => Hash ```...

  • Updated 8 months ago by vince
Rebase experimental branches

Fake everyone (including yourself) by squashing stupid commits on your experimental branch and then merging a pristine commit to master git checkout -b crazy-experiment do lots of stupid commits ...

Squash experimental branch

git rebase -i [SHA] "squash" melds the commit into the previous one (the one in the line before) https://thoughtbot.com/blog/git-interactive-rebase-squash-amend-rewriting-history https://dev.to/e...

  • Updated 8 months ago by vince
Jonas

rails console ``` Running via Spring preloader in process 61215 Loading development environment (Rails 6.0.3.2) irb(main):001:0> a = Availability.first Availability Load (0.8ms) SELECT "availabi...

  • Updated 8 months ago by vince
Find and kill a process

% ps aux | grep puma 52480 0.0 0.0 4268176 508 s000 R+ 10:10AM 0:00.00 grep puma 52050 0.0 0.8 4517160 142512 s000 T 9:52AM 0:27.34 puma 4.3.5 (tcp://localhost:3000) [crazya...

  • Updated 8 months ago by vince
Using the Postgres interval data type

rails generate model Availability ```ruby class CreateAvailabilities < ActiveRecord::Migration[6.0] def change reversible do |dir| dir.up do execute "ALTER DATABASE \"#{connecti...

Use PostgreSQL's interval type as ActiveRecord::Duration

I couldn't bring myself to use an integer as a db column with the amazing interval available. Unfortunately Rails just sees it as a string, but here's how you can get it to work ruby class CreateAv...

  • Updated 8 months ago by vince
Recurring Events in Rails using recurrence gem

https://github.com/fnando/recurrence

  • Updated 9 months ago by vince
Recurring Events in Rails

Recurring Events in Rails using Montrose

https://rossta.net/blog/recurring-events-in-ruby.html https://speakerdeck.com/rossta/recurring-events-with-montrose?slide=4

  • Updated 9 months ago by vince
Copy just one file from one branch to another

git checkout master # switch to master branch git checkout experiment -- db/schema.xmi # copy file from experiment branch

Recurring Events in Rails using ice_cube

Get this gem https://github.com/seejohnrun/ice_cube Go Rails videos https://www.youtube.com/watch?v=0tczntjIrKc https://www.youtube.com/watch?v=-nZedbdrTd8 Drifting Ruby videos https://www.youtube....

Create Amazon IAM user

Step 1: https://docs.aws.amazon.com/IAM/latest/UserGuide/getting-startedcreate-admin-group.html Step 2: https://console.aws.amazon.com/iam/home?#/securitycredentials

  • Updated 9 months ago by vince
SendGrid on Heroku

Not sure why everything I looked online makes it look complicated but this worked. And you don't even need to add the SendGrid gem. /config/environments/production.rb ruby config.action_mailer.de...

  • Updated 9 months ago by vince