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
| require Abilities | |
| defmodule User do | |
| defstruct id: 1, dude_id: 1 | |
| end | |
| defmodule M do | |
| use Abilities | |
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
| defmodule Blog.Abilities do | |
| defimpl Canada.Can, for: Blog.User do | |
| def can?(%Blog.User{}, :index, Blog.User), do: true | |
| def can?(%Blog.User{}, _, _), do: true | |
| def can?(nil, _, _), do: false |
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
| defmodule Abilities1 do | |
| defimpl Canada.Can, for: User do | |
| def can?(%User{id: user_id}, action, %Testimonial{id: testimonial_id}) | |
| when action in [:create], do: true | |
| def can?(%User{id: user_id}, action, %Testimonial{id: testimonial_id}) | |
| when action in [:edit], do: true | |
| end | |
| end | |
| defmodule BetterAbilities do |
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
| require 'net/http' | |
| require 'json' | |
| HOST = 'shopicruit.myshopify.com' | |
| PRODUCT_PATH = '/products.json' | |
| def get_computer_and_keyboard_cost() | |
| json_str = Net::HTTP.get HOST, PRODUCT_PATH | |
| json_dict = JSON.parse json_str |
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
| def palindrome?(s) | |
| s = s.downcase.split(/[^a-zA-Z0-9]+/).join.split "" | |
| s.zip(s.reverse).each do |letters| | |
| return false if letters[0] != letters[1] | |
| end | |
| return true | |
| 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 Node | |
| attr_accessor :next, :left_child, :right_child | |
| end | |
| def add_next_right_ptrs(node, right_sib) | |
| node.next = right_sib || nil | |
| if node.left_child | |
| add_next_right_ptrs(node.left_child, right_sib=node.right_child) | |
| end | |
| if node.right_child |
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 Solution: | |
| def connect(self, root): | |
| self.do_connect(root, None) | |
| def do_connect(self, node, right_sib): | |
| if not node: | |
| return | |
| node.next = right_sib if right_sib else None | |
| if node.left: | |
| self.do_connect(node.left, right_sib=node.right) |
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
| def find_itinerary(pairs=[]) | |
| nodes = {} # hash with name as key and node as val | |
| start_node = nil | |
| pairs.each do |pair| | |
| source_node = nodes[pair[0]] || Node.new(pair[0]) | |
| dest_node = nodes[pair[1]] || Node.new(pair[1]) | |
| source_node.add_dest(dest_node) | |
| nodes[pair[0]] = source_node | |
| nodes[pair[1]] = dest_node | |
| start_node = source_node if source_node.val == "JFK" |
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
| def find_itinerary(pairs=[]) | |
| nodes = {} # hash with name as key and node as val | |
| start_node = nil | |
| pairs.each do |pair| | |
| source_node = nodes[pair[0]] || Node.new(pair[0]) | |
| dest_node = nodes[pair[1]] || Node.new(pair[1]) | |
| source_node.add_dest(dest_node) | |
| nodes[pair[0]] = source_node | |
| nodes[pair[1]] = dest_node | |
| start_node = source_node if source_node.val == "JFK" |
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
| def find_itinerary(pairs=[]) | |
| nodes = {} # hash with name as key and node as val | |
| start_node = nil | |
| pairs.each do |pair| | |
| source_node = nodes[pair[0]] || Node.new(pair[0]) | |
| dest_node = nodes[pair[1]] || Node.new(pair[1]) | |
| source_node.add_dest(dest_node) | |
| nodes[pair[0]] = source_node | |
| nodes[pair[1]] = dest_node | |
| start_node = source_node if source_node.val == "JFK" |