This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddFollowCountersToUsers < ActiveRecord::Migration[6.0] | |
def change | |
add_column :users, :followers_count, :integer, null: false, default: 0 | |
add_column :users, :followings_count, :integer, null: false, default: 0 | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Users::FollowsController < ApplicationController | |
before_action :set_user | |
def create | |
if current_user.follow(@user.id) | |
respond_to do |format| | |
format.html { redirect_to @user } | |
format.js | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Followable | |
extend ActiveSupport::Concern | |
included do | |
has_many :follower_relationships, foreign_key: | |
:following_id, | |
class_name: 'Follow' | |
has_many :followers, through: :follower_relationships, source: :follower | |
has_many :following_relationships, foreign_key: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Authenticable | |
extend ActiveSupport::Concern | |
included do | |
attr_accessor :login | |
devise :database_authenticatable, :registerable, | |
:recoverable, :rememberable, :validatable | |
validates :username, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'mapbox-gl/dist/mapbox-gl.css'; | |
import mapboxgl from 'mapbox-gl'; | |
const fitMapToMarkers = (map, features) => { | |
const bounds = new mapboxgl.LngLatBounds(); | |
features.forEach(({ geometry }) => bounds.extend(geometry.coordinates)); | |
map.fitBounds(bounds, { padding: 70, maxZoom: 15 }); | |
}; | |
const initMapbox = () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PATTERN1 = /^(?<first_name>\w+)\.(?<last_name>\w+)@(?<provider>.+)\.(.+)$/ | |
PATTERN2 = /^(\w+)\.(\w+)@(.+)\.(.+)$/ | |
email = "[email protected]" | |
match = email.match(PATTERN1) # same as PATTERN.match(email) | |
p match |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Hello world" # String | |
1 # Integer | |
3.14 # Float | |
true # Boolean | |
nil # Nil | |
[1, 3, 6, "Hello"] # Array | |
# boxes/container to store stuff/data | |
first_name = "rui" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1, 2, 3, "hello"] # Array | |
"hello" # String | |
5 # Integer | |
1.356 # Float | |
(1..10) # Range | |
true # boolean | |
nil # Nil | |
# box/container to store stuff/data | |
# so it can be used again |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# split the sentence into words | |
# ignore punctuation // filter words | |
# ignore one letter words | |
# shift initial consonant group to the end of each word | |
# add random suffix to the end | |
# pre-pend l to te beginning of each word | |
SUFFIXES = %w[em é ji oc ic uche ès].freeze | |
VOWELS = %w[a e i o u].freeze |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# split the sentence into words | |
# ignore punctuation // filter words | |
# ignore one letter words | |
# shift initial consonant group to the end of each word | |
# add random suffix to the end | |
# pre-pend l to te beginning of each word | |
SUFFIXES = %w[em é ji oc ic uche ès].freeze | |
VOWELS = %w[a e i o u].freeze |