I hereby claim:
- I am vitaly-pushkar on github.
- I am pshk4r (https://keybase.io/pshk4r) on keybase.
- I have a public key ASA2hL6yQsXIZKVTrWaRn1Htv26UwrFThgrbrZIrwkkzdgo
To claim this, I am signing this object:
| # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc. | |
| # Initialization code that may require console input (password prompts, [y/n] | |
| # confirmations, etc.) must go above this block; everything else may go below. | |
| if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then | |
| source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" | |
| fi | |
| source "${HOME}/.zgen/zgen.zsh" | |
| #if the init script doesn't exist |
| patch '/users/:id/' do | |
| result = UserUpdater.new(User, config.mailer).call(params).to_result | |
| # a simple, "unambitious" version | |
| if result.success? | |
| result.sucess.to_json | |
| else | |
| {error: result.failure}.to_json | |
| end | |
| end |
| def find_user(id) | |
| Try { user_model.find_by(id: id) } | |
| end | |
| def update_user(user, data) | |
| Try do | |
| user.update(data) | |
| user.reload | |
| end | |
| end |
| def call(fields) | |
| fields = yield validate_fields(fields) | |
| email = yield validate_email(fields['email']) | |
| user = yield find_user(fields['id']) | |
| user = yield update_user(user, {name: fields['name'], email: fields['email']}) | |
| sent = yield send_email(user, :profile_updated) | |
| Success(user) | |
| end |
| ActiveRecord::Base.establish_connection( adapter: 'sqlite3', database: ":memory:" ) | |
| ActiveRecord::Schema.define(version: 1) { create_table(:users) { |t| t.string :name; t.string :email } } | |
| class User < ActiveRecord::Base; end | |
| User.create(name: 'Vitaly', email: 'vitaly.pushkar@gmail.com') |
| class UserUpdater | |
| include Dry::Monads[:result] | |
| attr_reader :user_model, :mailer | |
| def initialize(user_model, mailer) | |
| @user_model = user_model | |
| @mailer = mailer | |
| end |
| import scala.annotation.tailrec | |
| object ChangingMoney extends App { | |
| val money = scala.io.StdIn.readInt() | |
| // canonical coin system; this algorithm will not work optimally for arbitrary coin systems | |
| val coins = List(10, 5, 1) | |
| println(changeMoney(money)) |
I hereby claim:
To claim this, I am signing this object:
| // implement isSorted, which checks whether an Array[A] is sorted according to a given comparison function: | |
| // def isSorted[A] (as: Array[A], ordered: (A, A) => Boolean): Boolean | |
| object Test { | |
| def isSorted[A](as: Array[A], ordered: (A, A) => Boolean): Boolean = { | |
| def loop(n: Int): Boolean = | |
| if (n+1 >= as.length) true | |
| else if (!ordered(as(n), as(n+1))) false | |
| else loop(n+1) |
I hereby claim:
To claim this, I am signing this object: