Lerp is the acronym for linear interpolation. The idea is very simple, you have 2 values, and you want to “walk” between those values by a factor.
func lerp = (start, end, factor) =>
start * (1-factor) + end * factor;
module FastJsonapi | |
module ErrorSerializer | |
extend ActiveSupport::Concern | |
included do | |
include FastJsonapi::ObjectSerializer | |
attr_accessor :with_root_key | |
set_id :title |
# 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 |
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 |
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 |
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') | |
# ) |
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) { |
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] |
require 'csv' | |
require 'activerecord-import' | |
module ActsAsCsv | |
extend ActiveSupport::Concern | |
class_methods do | |
def filename | |
if const_defined? :CSV_FILENAME | |
self::CSV_FILENAME |
RSpec.describe Api::ClientBase do | |
subject(:api) { described_class.new(config) } | |
let(:scheme) { 'https' } | |
let(:host) { Faker::Internet.domain_name } | |
let(:port) { 3000 } | |
let(:config) do | |
{ | |
'scheme' => scheme, |