From ba240c46f48eea704a45bd2abf0a72f74dcf2a05 Mon Sep 17 00:00:00 2001 From: Daniel Jr Date: Sun, 16 Feb 2025 17:35:58 -0300 Subject: [PATCH] change writings to Medium Signed-off-by: Daniel Jr --- .../posts/2021-05-08-solid-with-examples.md | 211 ------------------ content/posts/2023-11-10-solidity-web3-js.md | 123 ---------- hugo.toml | 4 +- themes/cactus/layouts/index.html | 49 ---- 4 files changed, 1 insertion(+), 386 deletions(-) delete mode 100644 content/posts/2021-05-08-solid-with-examples.md delete mode 100644 content/posts/2023-11-10-solidity-web3-js.md diff --git a/content/posts/2021-05-08-solid-with-examples.md b/content/posts/2021-05-08-solid-with-examples.md deleted file mode 100644 index 21bf7d0..0000000 --- a/content/posts/2021-05-08-solid-with-examples.md +++ /dev/null @@ -1,211 +0,0 @@ ---- -title: S.O.L.I.D. with examples -date: 2021-05-08 16:56:54 -categories: design-pattern -keywords: kotlin ---- - -### S)ingle Responsibility Principle -*A class should have one, and only one, reason to change.* -A class should have a single responsibility within the software. - -Bad Example: -```kotlin -class User { - fun save() { - // Logic to save user to the database - } - - fun sendEmail() { - // Logic to send email to the user - } -} -``` -Good Example: -```kotlin -class User { - fun save() { - // Logic to save user to the database - } -} - -class EmailService { - fun sendEmail(user: User) { - // Logic to send email to the user - } -} -``` - -### O)pen Closed Principle -*You should be able to extend a class's behavior without modifying it.* -Objects should be open for extension but closed for modification. - -Bad Example: -```kotlin -class Rectangle(val width: Double, val height: Double) { - fun area(): Double { - return width * height - } -} - -class Circle(val radius: Double) { - fun area(): Double { - return Math.PI * radius * radius - } -} -``` -Good Example: -```kotlin -interface Shape { - fun area(): Double -} - -class Rectangle(val width: Double, val height: Double) : Shape { - override fun area(): Double { - return width * height - } -} - -class Circle(val radius: Double) : Shape { - override fun area(): Double { - return Math.PI * radius * radius - } -} -``` - -### L)iskov Substitution Principle -*Derived classes should be substitutable for their base classes.* -The Liskov Substitution Principle was introduced by Barbara Liskov in 1987: -"If for every object o1 of type S there is an object o2 of type T such that for all programs P, the behavior of P is unchanged when o1 is substituted by o2, then S is a subtype of T." - -Bad Example: -```kotlin -open class Bird { - open fun fly() { - println("Flying") - } -} - -class Ostrich : Bird() { - override fun fly() { - throw Exception("Ostriches can't fly") - } -} -``` -Good Example: -```kotlin -open class Bird { - open fun makeSound() { - println("Chirp") - } -} - -class Sparrow : Bird() { - override fun makeSound() { - println("Chirp chirp") - } -} - -class Ostrich : Bird() { - override fun makeSound() { - println("Hiss") - } -} -``` - -### I)nterface Segregation Principle -*Make interfaces that are client-specific.* -A class should not be forced to implement interfaces and methods that will not be used. - -Bad Example: -```kotlin -interface Machine { - fun print() - fun scan() - fun fax() -} - -class Printer : Machine { - override fun print() { - // Logic to print - } - - override fun scan() { - throw UnsupportedOperationException("Printer cannot scan") - } - - override fun fax() { - throw UnsupportedOperationException("Printer cannot fax") - } -} -``` -Good Example: -```kotlin -interface Printer { - fun print() -} - -interface Scanner { - fun scan() -} - -class SimplePrinter : Printer { - override fun print() { - // Logic to print - } -} - -class MultiFunctionPrinter : Printer, Scanner { - override fun print() { - // Logic to print - } - - override fun scan() { - // Logic to scan - } -} -``` - -### D)ependency Inversion Principle -*Depend on abstractions, not on concretions.* -A high-level module should not depend on low-level modules; both should depend on abstractions. - -Bad Example: -```kotlin -class EmailService { - fun sendEmail(message: String) { - // Logic to send email - } -} - -class Notification { - private val emailService = EmailService() - - fun notify(message: String) { - emailService.sendEmail(message) - } -} -``` -Good Example: -```kotlin -interface MessageSender { - fun send(message: String) -} - -class EmailService : MessageSender { - override fun send(message: String) { - // Logic to send email - } -} - -class Notification(private val sender: MessageSender) { - fun notify(message: String) { - sender.send(message) - } -} - -// Usage -val emailService = EmailService() -val notification = Notification(emailService) -notification.notify("Hello, World!") -``` diff --git a/content/posts/2023-11-10-solidity-web3-js.md b/content/posts/2023-11-10-solidity-web3-js.md deleted file mode 100644 index aa1da35..0000000 --- a/content/posts/2023-11-10-solidity-web3-js.md +++ /dev/null @@ -1,123 +0,0 @@ ---- -title: Blockchain Basics -date: 2023-11-10 12:21:32 -categories: web3 -keywords: solidity, js ---- - -[From Here](https://github.com/smartcontractkit/full-blockchain-solidity-course-js) - -Smart contracts are an agreement, contract or set of instructions that executes in a decentralized way without the need for a centralized or third party intermediary. - -**Blockchain Oracle**: Any device that interacts with the off-chain world to provide external data or computation to smart contracts. -**Hybrid Smart Contracts**: On-Chain + Off-Chain Agreements. - -Smart Contracts do trust minimized agreements that cannot be broke. - -- Cannot be altered (immutable) -- Automatically executes -- Everyone sees the terms of agreement - -UNBREAKABLE AGREEMENTS -and much more. - -1. Decentralized -2. Transparency -3. Speed -4. Security -5. Remove counterpart risk -6. True trust minimized agreements - -DeFi → Decentralized Finances -DAO → Decentralized Autonomous Organizations -NFT → Not Fungible Token - -### Your First Transaction - -1. Set up a wallet with [Metamask](https://metamask.io) -2. We can see details with the [Etherscan](https://etherscan.io) -- Mnemonic → can access all of your accounts. -- Private Key → can access 1 of your accounts. -- Public Key → can access nothing. -3. Connect and get ETH for test in [Faucets](https://faucets.chain.link) - -### Gas I: Introduction to Gas - -When we make transactions, the miners or validators make a small fee related to the gas. -**Gas**: A unit of computational measurement. The more complex your transaction is the more gas you have to pay. - -Transaction Fee = Gas Price * How much Gas used. - -### How Blockchain Works - -**Block**: A block of data encrypted in some hash (e. g. Sha256) with code (named nonce) to validate the block and hash validated that must start with 4 zeros. -**Blockchain**: Each block has an prev hash that refer to previous block in the chain. -Genesis Block: The first block in a blockchain. - -When a block is edited, broke all the next blocks. Then all the blocks need to be mine again. -After mine all this blocks, this blockchain is different from all the others in the decentralized net so it is discarted. - -**Mining**: The process of finding the solution to the blockchain problem. -In our example, the problem was to find a hash that starts with four zeros. -Nodes get paid for mining blocks. - -**Private Key**: Key used to sign an transaction. -**Public Key**: Key used to validate an signed transaction. - -### Gas II: Block Rewards & EIP 1550 - -**Base Fee**: Minimum gas price to send your transaction. - -**EIP (Etherium Improvement Proposals)**: The comon way of requesting changes to etherium network. - -### High-level blockchain fundamentals. - -**Node**: A single instance in a decentralized network. - -Anybody can run an Etherium node easily. -Blockchain nodes keep lists the transactions that ocur. - -**Consensus** is the mechanism used to agree on the state of a blockchain. And it can be broke in two parts: -1. Chain Selection Algorithm: using Nakamoto Consensus, the longest chain is selected. -2. Sybil Resistance Mechanism: is a blockchain ability to defend against users creating a large number of pseudo anonymous identities to gain a disproportionately advantageous influence over the set system. - - Proof of Work: the problem that need to be solved. It can be more hard and expensive depending to block time need to be. The gas fee is paid to the miner that resolve the transaction. - - Proof of Stake: it randomly choose and validator in the network. the gas fee is paid for validator, not miners. - -**Block Confirmations**: the number of confirmations is the number of blocks added on after our transaction. - -Sharding: sharded blockchain is an blockchain of blockchains. Is a main chain that is going to coordinate everything. Can be an solutions to scalability problem when an chain has to much transactions. -Layer 1: Base layer implementation. -Layer 2: Any application build on top of a layer 1. -Roll Ups: chains in the layer 2 that send (roll up) their transactions to layer 1. - -Attacks: -- **Sybil Attack**: when a user creates a whole bunch of pseudo anonymous account to try to influence the network. -- **51% Attack**: when a user, or a group of users, creates an chain that is longer of all others. - -### Welcome to Remix! Simple Storage - -Solidity is the primary smart contract coding language. - -Contract is an keyword to define the start of an contract in code. - -Coding an contract: -1. Goto [Remix Etherium IDE](remix.etherium.org) -2. Init an project with an Solidity (`.sol`) file. -3. Set solidity version. Ex.: - - `pragma solidity 0.8.7;` to set 0.8.7 version. - - `pragma solidity ^0.8.7;` to set an version above 0.8.7. - - `pragma solidity >=0.8.7 < 0.9.0;` to set an version between 0.8.7 and 0.9. -4. Put spdx licence on top of code. -5. Define an contract with the keyword `contract` in the code. Contract in solidity is similar with -Classes like in any other object-oriented languages. Ex.: - - `contract SimpleStorage {}`. create an contract named SimpleStorage with no one content. - -Solidity Types: - -The concept of “undefined” or “null” values does not exist in Solidity, but newly declared -variables always have a default value dependent on its type. - -> Any time you change something on-chain, including making a new contract, it happens in a -> transaction. - - diff --git a/hugo.toml b/hugo.toml index 70d3112..db93b85 100644 --- a/hugo.toml +++ b/hugo.toml @@ -11,7 +11,7 @@ weight = 1 [[menu.main]] name = "Writings" -url = "/posts" +url = "https://medium.com/@danielmrcl" weight = 2 [markup] @@ -37,8 +37,6 @@ weight = 2 logo = "image.jpg" favicon = "favicon.ico" description = "Since 2021, I've been developing Java web services using Spring and PostgreSQL in a microservices architecture for critical, efficient and scalable systems." - mainSection = "posts" - postsOnHomePage = 5 tagsOverview = true showProjectsList = true show_updated = true diff --git a/themes/cactus/layouts/index.html b/themes/cactus/layouts/index.html index 10c5e28..23dda58 100644 --- a/themes/cactus/layouts/index.html +++ b/themes/cactus/layouts/index.html @@ -37,55 +37,6 @@ {{ partial "optional-about.html" . }} -
- {{ .Site.Params.mainSectionTitle | default "Writings" }} - {{ if (and (and (isset .Site.Params "tagsoverview") (eq .Site.Params.tagsOverview true)) (gt (len .Site.Taxonomies.tags) 0)) }} - Topics - - {{ $AllRegularPagesCount := len .Site.RegularPages }} - {{ range $elem := .Site.Taxonomies.tags.Alphabetical }} - - {{- .Page.Title -}} - - {{ end }} - - Most recent - {{ end }} - - {{ $showAllPostsOnHomePage := false }} - {{ if (isset .Site.Params "showallpostsonhomepage") }} - {{ $showAllPostsOnHomePage = .Site.Params.ShowAllPostsOnHomePage }} - {{ end }} - {{ $dataFormat := .Site.Params.dateFormat | default "2006-01-02" }} - {{ $mainPosts := (sort ( where site.RegularPages "Type" "in" site.Params.mainSections ) "Date" "desc") }} - {{ if $showAllPostsOnHomePage }} - - - {{ partial "pagination.html" . }} - - {{ else }} - - {{ end }} -
- {{ $showProjectsList := false }} {{ if (isset .Site.Params "showprojectslist") }} {{ $showProjectsList = .Site.Params.showProjectsList }} -- 2.47.3