Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am perezpaya on github.
  • I am alejandro (https://keybase.io/alejandro) on keybase.
  • I have a public key ASCUY5zgkveB26KuhKmCuqbrcC628h-8GnXttauiVLnEfwo

To claim this, I am signing this object:

@perezpaya
perezpaya / challenge.md
Last active October 5, 2020 11:46
Allfunds Coding Challenge

Allfunds Coding Challenge

Our financial department is currently overloaded, they have lots of monthly expense reports waiting to be paid.

This reports consists of three different kind of expenses.

  • TRANSPORTATION (km):
    • Every kilometer is paid at 0.12 $/km
    • When an employee exceeds 100km per month, the next kms are paid at 0.08 $/km
echo "Borja maricona"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew tap caskroom/cask
brew cask install iterm2
brew cask install atom
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
import SpriteKit
enum GamepadButton {
case Left
case Right
}
class Gamepad: SKNode {
private var leftButton: SKSpriteNode!
private var rightButton: SKSpriteNode!
import SpriteKit
class Joystick: SKNode {
private let substrate: SKSpriteNode
private let stick: SKSpriteNode
var resetAnimationDuration: NSTimeInterval = 0.3
var velocity: CGPoint = .zero
var angularVelocity: CGFloat = 0
describe CompanyMarketUpdatesService, type: :service do
let(:notification_job) { object_spy(NotificationJob) }
let(:service) { described_class.new(notification_job: notification_job)
let(:apple) { Company.create!(name: 'Apple', stock_symbol: 'APPL', stock_volume: 22000000, stock_price: 100.0, number_of_shares: 100000000) }
it 'modifies company stockage information' do
updated_company = service.update(stock_symbol: apple.stock_symbol, stock_volume: 23000000, stock_price: 105.0)
expect(updated_company.stock_price).to eq(105.0)
expect(updated_company.stock_volume).to eq(23000000)
end
class CompanySerializer < ApplicationSerializer
attributes :name,
:stock_symbol,
:stock_price,
:stock_volume,
:number_of_shares,
:volume_price,
:valuation
has_one :ceo
class CompanyMarketUpdatesJob < ApplicationJob
queue_as :default
def perform(params)
ChoosenDatabase::Transaction.new do
CompanyMarketUpdatesService.new.update(params.deep_symbolize_keys)
end
end
end
class CompanyMarketUpdatesService
def initialize(notification_job: NotificationJob.new)
@notification_job = notification_job
end
def update(params)
Company.find_by_stock_symbol(params[:stock_symbol])&.tap do |company|
should_notify = should_notify_stock_price_reduction?(company.stock_price, params[:stock_price])
company.update(params)
notify_stock_price_reduction(company) if should_notify
class CompanyMarketUpdatesController < ApplicationController
def update
CompanyMarketUpdatesJob.perform_later(update_params)
render json: {sucess: true}, status: 202
end
private
def update_params
params.extract!(:stock_symbol, :stock_volume, :stock_price)