Skip to content

Instantly share code, notes, and snippets.

👯‍♂
Be water my friend

Carlos Donderis CaDs

👯‍♂
Be water my friend
Block or report user

Report or block CaDs

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View lucky_error
6:15:04 PM web.1 | Error in src/server.cr:7: instantiating 'App#listen()'
6:15:04 PM web.1 | app.listen
6:15:04 PM web.1 | ^~~~~~
6:15:04 PM web.1 | in src/app.cr:49: instantiating 'HTTP::Server#listen()'
6:15:04 PM web.1 | server.listen
6:15:04 PM web.1 | ^~~~~~
6:15:04 PM web.1 | in /usr/local/Cellar/crystal/0.26.1/src/http/server.cr:355: instantiating 'Array(Socket::Server)+#each()'
6:15:04 PM web.1 | @sockets.each do |socket|
6:15:04 PM web.1 | ^~~~
6:15:04 PM web.1 | in /usr/local/Cellar/crystal/0.26.1/src/indexable.cr:148: instantiating 'each_index()'
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|
You can’t perform that action at this time.