Skip to content

Instantly share code, notes, and snippets.

View amos-kibet's full-sized avatar
💭
Nyiganet

Amos Kibet amos-kibet

💭
Nyiganet
View GitHub Profile
@amos-kibet
amos-kibet / Ecto.Changeset.md
Last active October 16, 2022 14:10
Elixir Ecto Changeset Quick Overview

Ecto Changesets Crash Course

  • In order to insert, update or delete data from the database, Ecto.Repo.insert/2, update/2 and delete/2 require a changeset as their first parameter
  • Changesets validate data before being inserted to the database by checking for potential errors, asserting that required fields are passed, asserting that non-empty fields have data, keeping track of changes in the data (think of it as a version control for database transactions), etc

Empty Changeset

iex> %Ecto.Changeset{}
%Ecto.Changeset<action: nil, changes: %{}, errors: [], data: nil, valid?: false>
@amos-kibet
amos-kibet / Playground.hs
Created May 8, 2022 07:14
Plutus Playground Smart Contract
-- A game with two players. Player 1 thinks of a secret word
-- and uses its hash, and the game validator script, to lock
-- some funds (the prize) in a pay-to-script transaction output.
-- Player 2 guesses the word by attempting to spend the transaction
-- output. If the guess is correct, the validator script releases the funds.
-- If it isn't, the funds stay locked.
import Control.Monad (void)
import Data.ByteString.Char8 qualified as C
import Data.Map (Map)
import Data.Map qualified as Map