teleren/devto huggingface dataset:
How to resolve python command not found error in Linux
Tags: python, linux
Published: 2022-06-17 19:03:13

I had both python3.8 and python2.7 installed on a Linux system (Ubuntu in this case, but this solution should work for other flavours of Linux too), however running `python --version` gave a `python: command not found` response.
![Screenshot of an Ubuntu terminal. Shows the output of python --version command. The Output is Command 'python' not found.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wy4n41zdn7qjqyc2hu41.png)
 
Steps to resolve:

1. Verify if any version of python was installed on the system
    * I wanted to be sure that the system had some version of python installed. Using `whereis python3` or `whereis python2` command shows the versions and paths of python installed on the system.
The output should look something like this
![Screenshot of Ubuntu terminal that shows the output of whereis python3 command. The output shows paths we can find python3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ozkkwrw2bhbcp293kv3m.png) 
 
2. If there is no version of python installed, install it using `sudo apt-get install python3.8` or `sudo apt-get install python<version>` (use `yum` instead of `apt-get` for RHEL)

3. cd to /usr/bin folder and create a symlink to the version of python you want to be invoked using the python command.
Example:
`cd /usr/bin
 ln -s /usr/bin/python3.8 python
`
Verify the if the symlink is created using `ls -l python` and verify if the python command works and is pointing to the right version of python using `python --version`.
![Screenshot of Ubuntu terminal that shows the output of python command. The output is Python 3.8.10](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vk23ga1i4ermwtzc6fet.png)
Last Stone Weight
Tags: leetcode, dsa, theabbie
Published: 2022-06-17 19:00:52

You are given an array of integers `stones` where `stones[i]` is the weight of the `ith` stone.

We are playing a game with the stones. On each turn, we choose the **heaviest two stones** and smash them together. Suppose the heaviest two stones have weights `x` and `y` with `x <= y`. The result of this smash is:

*   If `x == y`, both stones are destroyed, and
*   If `x != y`, the stone of weight `x` is destroyed, and the stone of weight `y` has new weight `y - x`.

At the end of the game, there is **at most one** stone left.

Return _the weight of the last remaining stone_. If there are no stones left, return `0`.

**Example 1:**

**Input:** stones = \[2,7,4,1,8,1\]
**Output:** 1
**Explanation:** 
We combine 7 and 8 to get 1 so the array converts to \[2,4,1,1,1\] then,
we combine 2 and 4 to get 2 so the array converts to \[2,1,1,1\] then,
we combine 2 and 1 to get 1 so the array converts to \[1,1,1\] then,
we combine 1 and 1 to get 0 so the array converts to \[1\] then that's the value of the last stone.

**Example 2:**

**Input:** stones = \[1\]
**Output:** 1

**Constraints:**

*   `1 <= stones.length <= 30`
*   `1 <= stones[i] <= 1000`

**SOLUTION:**

    import heapq
    
    class Solution:
        def lastStoneWeight(self, stones: List[int]) -> int:
            heap = []
            for s in stones:
                heapq.heappush(heap, -s)
            while len(heap) > 1:
                y = -heapq.heappop(heap)
                x = -heapq.heappop(heap)
                if x != y:
                    heapq.heappush(heap, x - y)
            if len(heap) == 1:
                return -heap[0]
            return 0
Cloud Resume Challenge, Days 6-7 - Code, Code, AWS
Tags: cloudresumechallenge, aws, showdev
Published: 2022-06-17 19:00:37

Hello there. (If you don't get the reference, I'm not sure we can be friends...)

A short follow up to my last post, got my resume page mostly ready. Still not 100% done, have the visitor counter to complete (this post starts the tale of that journey), but complete enough to release it to be free.  You can find it here: [Resume](https://cfresume.curtisfarley.net/)

So this part of the project had me: write Python code to write a value to a DynamoDB table, setup a Lambda function to then use that code, and configure IAM permissions so that Lambda could interact with DynamoDB. And this is just the first half of the back-end.. sheesh....

As an infrastructure guy, this is now starting to get into my wheelhouse. But not particularly easy for me - all new stuff this is. A lot to learn, mostly by trial and error. But I can report that I was successful in getting it done and working even!

While I had been trying to learn Python prior to this, that fell to the wayside due to a slight shift in priority (studying for AWS Networking exam). I knew I wouldn't be writing code from scratch, there's no need to reinvent the wheel here. But I'd still need to figure out the how/what/why of the specific code snippet that I chose to model from. So that's what I did.

**Time for the fun to start:**
After some Googling, I found some code that I thought would work and would be simple enough that I could reverse engineer, modify, & test to fit my environment. Not unexpectedly, just changing variables and names to match my environment didn't work. At all. Time to hit the documentation, for Python, for VS Code, & for AWS. I learned I needed to do more setup and config for VS Code to get it to work with AWS and Python. 
I learned (by doing this time, previously just theory for the Solutions Architect exam) how to create and apply IAM policies and roles to Lambda. 
I learned syntax for Python to interact with DynamoDB. 
And I learned a little bit about Lambda, specifically that you (apparently) need to deploy your function before you can actually test it. Frustrating when the AWS documentation I read and the 3 or 4 videos I watched, none of them ever said to deploy to test - they just hit the 'test' button and whoomp, there it is....

After getting my code to write a value into my table, I tackled the change to update/increment the value rather than just write one. Wasn't too bad honestly, just a simple keyword change from 'set' to 'add'. There's probably a hundred other little things that I could/should say, but I'm trying to not get too long winded and I feel I'm close to that limit.

I will share this photo of how I'm 'blueprinting' the current goal/task at hand. I do find this to be quite helpful.
![Goal 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/72pdfcgrl4erg1e5cqov.jpg)

In summary, all tasks for this goal are complete. My next goal is setup & test an API Gateway to talk to Lambda, starting on that soon.

As always, turn around, don't drown & keep it between the white lines....
Blockchain Development
Tags: javascript, php, programming, webdev
Published: 2022-06-17 18:50:26

Hello Guys, my name is Victor, I've been a developer for over 20 years. I specialize in Software Development, Native and Hybrid Apps and Blockchain Development.
I recently finished a big project, with several contracts, and a protocol, all created by me. You can see through the link below. 
I have a lot of experience in technologies such as:

• Python
• C,
• C++ 
• PHP
• Flutter / Dart
• C# 
• Javascript
• Typescript
• Kotlin
• Esx Js
• Java
• Laravel (Todas as versões) 
• CakePHP
• Nodejs/ExpressJs
• Angular (Todas as Versões)
• VueJS (Todas as versões)
• ReactJs
• Ionic
• JQuery
• Selenium
• SocketIO
• MySQL
• PostgreSQL
• Azure
• Sass
• Bootstrap
• Bulma
• CSS/CSS3

Blockchain Development
• Blockchain deployment and development with web3, solidity, cakeshop and truffle, Moralis.
• Smart contracts and custom dapp frameworks like OpenZeppelin.
• Application and data science engineering using Python.
• Enterprise native mobile apps with Swift, Objective-C and Flutter/Dart.
• Web platforms using Phoneix / Elixir and serverless architecture.

If anyone is in need, please get in touch, I can build your project for a good cost.
I have hundreds of projects completed, call me on whatsapp and I can send you several references of mine

**My latest project**
https://test.desu.tv

https://www.youtube.com/watch?v=0xIqkkuQFQA
https://www.youtube.com/watch?v=UcSUPWKYWc0
https://www.youtube.com/watch?v=BOF9FEp71GA

WHATSAPP
+55 (11) 975520431
Tired of cleaning data?
Tags: datascience, opensource, machinelearning
Published: 2022-06-17 18:48:25

If so, we open-sourced a data cleaning tool (https://github.com/mage-ai/mage-ai) that will help you easily identify issues, quickly improve data quality, and repeat the process in any environment.

Would love to get some feedback and hop on Zoom call if you have any questions/ help setting up.

Feel free to join our slack: https://www.mage.ai/chat
Computing power
Tags: computerscience, codenewbie, programming
Published: 2022-06-17 18:33:44

Ok so your interviewer asks you write a function to find the power of a number. We have all used Math.pow() in JAVA, pow() function in C/C++, but have you wondered how to compute the power without using these????

Let's find out.

Example: 
x = 2
y = 3
Output = 8 ( 2 to the power 3 = 2 *2 *2)

Naive Solution: Time Complexity = O(n)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v41ua28ztrz5et1oufpb.png)

Output:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jx9eo04v9um8oerjisbo.png)

Recursive Solution: 
Time Complexity = θ(logn)
Space Complexity = θ(logn)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z6ilhzi24p9civ08dttj.png)
 
Output:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ac5plordw2wfkmitu71d.png)

It has recursive function calls which will take space in function call stack. It also has overhead for function call in return. 
 
Can you think of a better solution?
How about an Iterative solution?
Do share your views in the comments.
Maximum Product of the Length of Two Palindromic Subsequences
Tags: leetcode, dsa, theabbie
Published: 2022-06-17 18:00:42

Given a string `s`, find two **disjoint palindromic subsequences** of `s` such that the **product** of their lengths is **maximized**. The two subsequences are **disjoint** if they do not both pick a character at the same index.

Return _the **maximum** possible **product** of the lengths of the two palindromic subsequences_.

A **subsequence** is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters. A string is **palindromic** if it reads the same forward and backward.

**Example 1:**

![example-1](https://assets.leetcode.com/uploads/2021/08/24/two-palindromic-subsequences.png)

**Input:** s = "leetcodecom"
**Output:** 9
**Explanation**: An optimal solution is to choose "ete" for the 1st subsequence and "cdc" for the 2nd subsequence.
The product of their lengths is: 3 \* 3 = 9.

**Example 2:**

**Input:** s = "bb"
**Output:** 1
**Explanation**: An optimal solution is to choose "b" (the first character) for the 1st subsequence and "b" (the second character) for the 2nd subsequence.
The product of their lengths is: 1 \* 1 = 1.

**Example 3:**

**Input:** s = "accbcaxxcxx"
**Output:** 25
**Explanation**: An optimal solution is to choose "accca" for the 1st subsequence and "xxcxx" for the 2nd subsequence.
The product of their lengths is: 5 \* 5 = 25.

**Constraints:**

*   `2 <= s.length <= 12`
*   `s` consists of lowercase English letters only.

**SOLUTION:**

    class Solution:
        def maxPalindrome(self, s, i, j, cache):
            key = 1100 * i + j
            if key in cache:
                return cache[key]
            if i == j:
                cache[key] = 1
            elif s[i] == s[j] and i + 1 == j:
                cache[key] = 2
            elif s[i] == s[j]:
                cache[key] = self.maxPalindrome(s, i + 1, j - 1, cache) + 2
            else:
                cache[key] = max(self.maxPalindrome(s, i, j - 1, cache), self.maxPalindrome(s, i + 1, j, cache))
            return cache[key]
        
        def maxProduct(self, s: str) -> int:
            self.cache = {}
            maxP = float('-inf')
            n = len(s)
            for mask in range(1 << n):
                sub = ""
                rest = ""
                for j in range(n):
                    if mask & (1 << j):
                        sub += s[j]
                    else:
                        rest += s[j]
                if len(sub) > 0 and len(rest) > 0:
                    maxP = max(maxP, self.maxPalindrome(sub, 0, len(sub) - 1, {}) * self.maxPalindrome(rest, 0, len(rest) - 1, {}))
            return maxP
This Week in Python
Tags: python, discuss
Published: 2022-06-17 16:42:51


**Fri, June 17, 2022**


This Week in Python is a concise reading list about what happened in the past week in the Python universe. 


## Python Articles

- [Handling Concurrency Without Locks](https://hakibenita.com/django-concurrency) – Concurrency is not very intuitive. You need to train your brain to consider what happens when multiple processes execute a certain code block at the same time.
- [The strange relationship between objects, functions, generators and coroutines](https://www.packt.com/bizarre-python/)
- [Python logging: do’s and don’ts](https://www.palkeo.com/en/blog/python-logging.html)
- [Bundling binary tools in Python wheels](https://simonwillison.net/2022/May/23/bundling-binary-tools-in-python-wheels/)
- [C vs Golang Python extension performance](https://ipdata.co/blog/c-vs-golang-python-extensions/)




## Projects

- [pathfinding](https://github.com/xorz57/pathfinding) – Pathfinding Algorithm Visualization Tool written in Python
- [streamlit](https://github.com/streamlit/streamlit) – Streamlit — The fastest way to build data apps in Python
- [django-pgpubsub](https://github.com/Opus10/django-pgpubsub) – A distributed task processing framework for Django built on top of the Postgres NOTIFY/LISTEN protocol
- [pikepdf](https://github.com/pikepdf/pikepdf) – A Python library for reading and writing PDF, powered by qpdf
- [PyWebIO](https://github.com/pywebio/PyWebIO) – Write interactive web app in script way
ใช้ node module 2 version ใน project เดียวกัน
Tags: typescript, lerna
Published: 2022-06-17 17:43:42

วันนี้เล่านิดหน่อย เรื่องทำยังไงถึงจะใช้ node module อันเดียวกัน แต่ 2 version ได้ ภายใน project เดียว

ไปเจอว่าถ้าใช้ `lerna` จะทำให้ node module ของแต่ละ sub packages ใช้ version แยกกันได้ ตามภาพเลยเด้อ (จะเห็นว่า ซ้ายใช้ `spl-token@0.1.8` แต่อีกด้านใช้ `spl-token@0.2.0`


![2 packages](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aa9lr7l44z7oqo04jcj4.png)
 
 
พอใช้งานรันจริงก็จะเห็นว่า มันเรียกใช้ node module ของใครของมัน ถึงแม้ว่าจะ link deps เข้าหากันก็ตาม

![2 deps version calling](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ifiry5sj4pnn8w3v1yx.png)

วิธีใช้ก็แค่
```
lerna add @solana/spl-token@0.1.8 --scope=module-a
lerna add @solana/spl-token@0.2.0 --scope=module-b
lerna link
lerna add module-a --scope=module-b
```

### Reference
https://github.com/lerna/lerna
 
😎 😎 😎 😎
Three Divisors
Tags: leetcode, dsa, theabbie
Published: 2022-06-17 17:30:40

Given an integer `n`, return `true` _if_ `n` _has **exactly three positive divisors**. Otherwise, return_ `false`.

An integer `m` is a **divisor** of `n` if there exists an integer `k` such that `n = k * m`.

**Example 1:**

**Input:** n = 2
**Output:** false
**Explantion:** 2 has only two divisors: 1 and 2.

**Example 2:**

**Input:** n = 4
**Output:** true
**Explantion:** 4 has three divisors: 1, 2, and 4.

**Constraints:**

*   `1 <= n <= 104`

**SOLUTION:**

    class Solution:
        def isThree(self, n: int) -> bool:
            ctr = 0
            for i in range(1, n + 1):
                if n % i == 0:
                    ctr += 1
            return ctr == 3
Day 20 - Constructors
Tags: 100daysofcode, solidity, web3, blockchain
Published: 2022-06-17 17:26:00

{% embed https://github.com/Envoy-VC/30-Days-of-Solidity noreadme %}

This is Day `20` of `30` in Solidity Series
Today I Learned About Constructors in Solidity.

A constructor is a special method in any object-oriented programming language which gets called whenever an object of a class is initialized. It is totally different in case of Solidity, Solidity provides a constructor declaration inside the smart contract and it invokes only once when the contract is deployed and is used to initialize the contract state. A default constructor is created by the compiler if there is no explicitly defined constructor

## Creating a constructor

A Constructor is defined using a constructor keyword without any function name followed by an access modifier. It’s an optional function which initializes state variables of the contract. A constructor can be either internal or public, an internal constructor marks contract as abstract. 

Syntax:
```solidity
constructor() <Access Modifier> {          
} 
```

Following are the key characteristics of a constructor.

- A contract can have only one constructor.

- A constructor code is executed once when a contract is created and it is used to initialize contract state.

- After a constructor code executed, the final code is deployed to blockchain. This code include public functions and code reachable through public functions. Constructor code or any internal method used only by constructor are not included in final code.
- A constructor can be either public or internal.

- A internal constructor marks the contract as abstract.

Example:
```solidity
pragma solidity ^0.8.7;

contract constructorExample {
    string str;

    // Creating a constructor to set value of 'str'
    constructor() public {
        str = "Example Constructor";
    }

    // Defining function to return the value of 'str'
    function getValue() public view returns (string memory) {
        return str;
    }
}
```

---
Design Restful WebServices — Part 1
Tags: softwareengineering, frontend, backend, softwaredevelopment
Published: 2022-07-11 01:31:21

---
title: Design Restful WebServices — Part 1
published: true
date: 2022-06-17 17:05:37 UTC
tags: softwareengineering,frontenddevelopment,backend,softwaredevelopment
canonical_url: https://rajdeep-das.medium.com/design-restful-webservices-part-1-bca4436646b5
---

### Design Restful WebServices — Part 1

Design API like end user will consume It

![](https://cdn-images-1.medium.com/max/1024/0*UEaVVvSg8sjHrNdP)
_Photo by Fahim Muntashir on Unsplash_

HTTP is an application-level protocol that defines the operation between client and server. There is a difference between designing Restful API & Designing API, which also uses HTTP protocols and JSON/XML for data transfer.

REST is an acronym for **R** epresentational **S** tate **T** ransfer, an architectural style for distributed hypermedia systems.

In this protocol, methods such as **GET** , **POST** , **PUT** , and **DELETE** operations that act on resources.

This protocol eliminates the need for you to invent application-specific operations such as **createOrder** , **getStatus** , **updateStatus** , **getUserInfoById,** etc.

A Web API or Web Service that follows this type of architecture is known as a RESTful API

**Problem 1:**

You want to know how to apply those protocols GET, POST, PUT, PATCH, and DELETE on resources to achieve Restful Architecture Style.

**Solution:**

When you define the resource like Customer, Order, User, etc, use **GET** to get a resource representation, **PUT** to update a resource, **DELETE** to delete a resource, and **POST** to create a resource.

#### Role of Idempotent & Safe HTTP Methods in Restful Web Services & Implementation

What is idempotent in the HTTP Method?

We call an HTTP method idempotent if that method does not create any side effects or alter the state of the server even if we send the same request many times.

**GET**  — if we call get request on a resource many times it will not change the state of the resource, it will return the result of how many times we call it without doing any side effects

**POST**  — If we call a post request multiple times it will create a new resource every time. For Example, if we send create customer resource multiple times it will every time generate a new customer and save to DB.

If we Implement correctly, the GET, HEAD, PUT, and DELETE methods should be idempotent in Restful API Design. If we violate that rule then we can’t call it RESTful Standard API Design.

In an idempotent check, only Backend Server State is considered. Not the Status Code.

For Example

The first Call of DELETE Return **200** but the Second call will return  **404**.

![](https://cdn-images-1.medium.com/max/572/0*jG-KHZmfIB_NHyvX)
_HTTP Method Table_

Happy reading… 😁😃 [Rajdeep Das | LinkedIn](https://www.linkedin.com/in/rajdeep-das-india/)
Second Minimum Node In a Binary Tree
Tags: leetcode, dsa, theabbie
Published: 2022-06-17 17:00:41

Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly `two` or `zero` sub-node. If the node has two sub-nodes, then this node's value is the smaller value among its two sub-nodes. More formally, the property `root.val = min(root.left.val, root.right.val)` always holds.

Given such a binary tree, you need to output the **second minimum** value in the set made of all the nodes' value in the whole tree.

If no such second minimum value exists, output -1 instead.

**Example 1:**

![](https://assets.leetcode.com/uploads/2020/10/15/smbt1.jpg)

**Input:** root = \[2,2,5,null,null,5,7\]
**Output:** 5
**Explanation:** The smallest value is 2, the second smallest value is 5.

**Example 2:**

![](https://assets.leetcode.com/uploads/2020/10/15/smbt2.jpg)

**Input:** root = \[2,2,2\]
**Output:** -1
**Explanation:** The smallest value is 2, but there isn't any second smallest value.

**Constraints:**

*   The number of nodes in the tree is in the range `[1, 25]`.
*   `1 <= Node.val <= 231 - 1`
*   `root.val == min(root.left.val, root.right.val)` for each internal node of the tree.

**SOLUTION:**

    import heapq
    
    # Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, val=0, left=None, right=None):
    #         self.val = val
    #         self.left = left
    #         self.right = right
    class Solution:
        def inorder(self, root):
            if root:
                self.inorder(root.left)
                if root.val not in self.dup:
                    heapq.heappush(self.heap, root.val)
                    self.dup.add(root.val)
                self.inorder(root.right)
        
        def findSecondMinimumValue(self, root: Optional[TreeNode]) -> int:
            self.heap = []
            self.dup = set()
            self.inorder(root)
            first = heapq.heappop(self.heap)
            if len(self.heap) > 0:
                second = heapq.heappop(self.heap)
                return second
            return -1