Skip to content

Instantly share code, notes, and snippets.

View cpjk's full-sized avatar
๐ŸŒฎ
๐ŸŒฎ ๐ŸŒฎ ๐ŸŒฎ ๐ŸŒฎ ๐ŸŒฎ ๐ŸŒฎ ๐ŸŒฎ ๐ŸŒฎ ๐ŸŒฎ

Chris Kelly cpjk

๐ŸŒฎ
๐ŸŒฎ ๐ŸŒฎ ๐ŸŒฎ ๐ŸŒฎ ๐ŸŒฎ ๐ŸŒฎ ๐ŸŒฎ ๐ŸŒฎ ๐ŸŒฎ
View GitHub Profile
@cpjk
cpjk / s.ex
Created September 15, 2015 16:07
require Abilities
defmodule User do
defstruct id: 1, dude_id: 1
end
defmodule M do
use Abilities
@cpjk
cpjk / abilities.ex
Last active November 25, 2015 04:34
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
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
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
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
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
@cpjk
cpjk / np.py
Last active February 12, 2016 01:21
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)
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"
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"
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"