- Install Docker for Mac
- https://store.docker.com/editions/community/docker-ce-desktop-mac
- once installed enable kubernetes from preferences and select kubernetes as the default orchestrator
- on the advanced section, increase your cpu and memory to about 2 CPU and 2gb of RAM, for now.
This file contains 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 ApplicationRecord < ActiveRecord::Base | |
self.abstract_class = true | |
def self.human_enum_name(enum_name, enum_value) | |
I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{enum_name.to_s.pluralize}.#{enum_value}") | |
end | |
def self.human_enum_collection(enum_name) | |
send(enum_name.to_s.pluralize).keys.map do |val| | |
[human_enum_name(enum_name, val), val] |
This file contains 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
package main | |
import ( | |
"code.google.com/p/go-tour/tree" | |
"fmt" | |
) | |
// Walk walks the tree t sending all values | |
// from the tree to the channel ch. | |
func Walk(t *tree.Tree, ch chan int) { |
This file contains 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 Order < ActiveRecord::Base | |
scope :paid, -> { where(id: Payment.paid.select(:order_id)) } | |
end | |
# SELECT "orders".* FROM "orders" WHERE "orders"."id" IN ( | |
# SELECT "payments"."order_id" | |
# FROM "payments" | |
# WHERE "payments"."state" IN ('charged', 'authorized') | |
# ) |
This file contains 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 String | |
def encrypt(k) | |
lower_alphabet = [*'a'..'z'] | |
lower_translation_map = lower_alphabet.zip(lower_alphabet.rotate(k%26)).to_h | |
upper_alphabet = [*'A'..'Z'] | |
upper_translation_map = upper_alphabet.zip(upper_alphabet.rotate(k%26)).to_h | |
translation_map = lower_translation_map.merge(upper_translation_map) | |
chars.map { |char| translation_map[char] || char }.join | |
end |
This file contains 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 String | |
def balanced? | |
pairs = { '{' => '}', '[' => ']', '(' => ')' } | |
brackets = chars.each_with_object([]) do |char, stack| | |
if bracket = pairs[char] | |
stack << bracket | |
elsif pairs.values.include?(char) | |
next if stack.pop == char |
This file contains 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
# Return a boolean indicating whether the number is a palindrome. Raises a | |
# TypeError if the argument is not an integer | |
# | |
# Caveat: Try to accomplish this without converting the number to a string. | |
# The goal is to understand your approach to a problem with constraints | |
# rather than seeing how quickly you can jump to an easy solution. | |
# | |
# Example | |
# palindrome?(1001) => true | |
# palindrome?(1234) => false |
This file contains 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
module FastJsonapi | |
module ErrorSerializer | |
extend ActiveSupport::Concern | |
included do | |
include FastJsonapi::ObjectSerializer | |
attr_accessor :with_root_key | |
set_id :title |
This file contains 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
# Pundit | |
# Friendly ID | |
# FastJSON | |
module ActsAsResource | |
extend ActiveSupport::Concern | |
included do | |
include Pundit |
This file contains 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 ApiConstraint | |
def initialize(options) | |
@version = options[:version] | |
@default = options[:default] | |
end | |
def matches?(request) | |
@default || request.headers.fetch(:accept).include?("version=#{version}") | |
end | |
end |