Skip to content

Instantly share code, notes, and snippets.

Avatar
👯‍♂️
Be water my friend

Carlos Donderis CaDs

👯‍♂️
Be water my friend
View GitHub Profile
View controller.rb
class PostsController < ApplicationController
before_action :auth_user
def index
@posts = @user.fetch_feed
end
end
class User < ApplicationRecord
def fetch_feed
View connections.rb
class Connection < ApplicationRecord
belongs_to :follower, class_name: 'User', foreign_key: :follower_id
belongs_to :following, class_name: 'User', foreign_key: :following_id
end
View post.rb
class Post < ApplicationRecord
belongs_to :user
after_create_commit :enqueue_delivery
class << self
def cache_key_for(id:)
"cached_post/#{id}"
end
View user.rb
class User < ApplicationRecord
has_many :posts, dependent: :destroy
has_many :connections, dependent: :destroy
has_many :follower_connections, foreign_key: :following_id, class_name: 'Connection'
has_many :followers, through: :follower_connections, source: :follower
has_many :following_connections, foreign_key: :follower_id, class_name: 'Connection'
has_many :following, through: :following_connections, source: :following
@CaDs
CaDs / partitions.cr
Created Apr 14, 2018
john_lynch_scrtip
View partitions.cr
def get_partition_original(ss)
return (ss.size == 0 ? [[[] of Int32]] : [[ss]]) if ss.size <= 1
out = [[Array(Int32).new, Array(Int32).new]].clear
(0...2**ss.size / 2).each { |i|
parts = [Array(Int32).new, Array(Int32).new]
ss.each { |item|
parts[i&1] << item
i >>= 1
}
get_partition_original(parts[1]).each { |b|