Skip to content

Instantly share code, notes, and snippets.

@dasibre
Created January 25, 2019 22:47
Show Gist options
  • Save dasibre/8be8aa7c3700098609b3562db19c9286 to your computer and use it in GitHub Desktop.
Save dasibre/8be8aa7c3700098609b3562db19c9286 to your computer and use it in GitHub Desktop.
Eval
#Palindrome a word phrase that reads the same backwards
# write code that will return true for the following palindrome
# "A man, a plan, a canal: Panama"
module Palindrome
def self.is_palindrome(word)
end
end
# Palindrome.is_palindrome("A man, a plan, a canal: Panama") => true
##############################################################################################################################
#What would you say is wrong with this code
class CommentsController < ApplicationController
def users_comments
posts = Post.all
comments = posts.map(&:comments).flatten
@user_comments = comments.select do |comment|
comment.author.username == params[:username]
end
end
end
##############################################################################################################################
files = {
'Input.txt' => 'Randy',
'Code.py' => 'Stan',
'Output.txt' => 'Randy'
}
module FileOwners
def self.group_by_owners(files)
return nil
end
end
puts FileOwners.group_by_owners(files)
#returns hash containing array of file names
# for each owner
# {randy => [Input.text, Output.txt], stand => [Code.py]}
#
##############################################################################################################################
# How would you define a Person model so that any Person can be
# assigned as a parent of another Person.
# What columns would you need to define in the migration creating the table for person
# so you could do the following
# john = Person.create(name: "John")
# jim = Person.create(name: "Jim", parent: john)
# bob = Person.create(name: "Bob", parent: john)
# john.children.map(&:name)
# => ["Jim", "Bob"]
#
class Person < ActiveRecord::Base
end
##############################################################################################################################
#config/routes.rb
# what routes, http verbs will the following snippet generate
resources :posts do
member do
get 'comments'
end
collection do
post 'bulk_upload'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment