teleren/devto huggingface dataset:
Guide to JSON, YAML and TOML
Published: 2022-06-12 00:37:46

In many frameworks, tools and more you often have to write configuration files that are often in JSON, YAML or TOML format here are some examples.

- package.json (tracks dependencies for node)
- tsconfig.json (typescript configurations)
- cargo.toml (tracks depencies for rust projects)
- database.yaml (database configurations in Ruby of Rails projects)
- serverless.yaml (configure deployments using the serverless framework)

They all essentially do the same thing, denote key/value pair that can then be read by a parser in any programming language to configure what the tool or framework does.

## Seeing them at work

What we'll do is translate the following javascript object in JSON, YAML and TOML

```js
const config = {
  description: {
    name: "Alex Merced",
    age: 36,
    employer: "Dremio",
  },
  onlinePressence: {
    websites: ["devnursery.com", "grokoverflow.com", "alexmercedcoder.com"],
    twitter: ["alexmercedcoder", "amdatalakehouse"],
  },
};
```

## JSON

This will be the simplest since JSON stands for "Javascript Object Notation" it's meant to look a lot like a javascript object. A couple of differences:

- Key require quotations
- No trailing commas

```json
{
  "description": {
    "name": "Alex Merced",
    "age": 36,
    "employer": "Dremio"
  },
  "onlinePressence": {
    "websites": ["devnursery.com", "grokoverflow.com", "alexmercedcoder.com"],
    "twitter": ["alexmercedcoder", "amdatalakehouse"]
  }
}
```

Pretty straightforward, probably why in javascript tooling this is generally the go to format. The only real downside is the inability to inject variables or environmental variables.

## YAML

YAML stands for "Yet Another Markup Language", I would call this the python of markup languages as like Python it relies heavily on indentation.

```yaml
description:
    name: Alex Merced
    age: 36
    employer: Dremio

onlinePressence: 
    websites: 
        - devnursery.com
        - grokoverflow.com
        - alexmercedcoder.com
    twitter: 
        - alexmercedcoder
        - amdatalakehouse

```

YAML also does have access to environmental variables but does allow reuse of properties in several ways.

- `&property` and `<<: *property` to inject all the properties from object to another
- `{{property}}` to inject the value of one property as the value of another key

## TOML

TOML stands for "Toms Obvious Markup Language" and I most often see it used for Netlify configurations and Rust and I would categorize this the Ruby of config files with a simple syntax that doesn't rely on indentation.

```toml
[description]
name: "Alex Merced"
age: 36
employer: "Dremio"

[onlinePressence] 
websites: ["devnursery.com","grokoverflow.com","alexmercedcoder.com"]
twitter: ["alexmercedcoder", "amdatalakehouse"]
```

But yeah, that's all there is to it. Regardless which format we're talking about, these examples convey the same information. What values particular frameworks and languages look for is up to them, so you'll need to read their documentation but hopefully this helps.
Successful Pairs of Spells and Potions
Tags: leetcode, dsa, theabbie
Published: 2022-06-12 00:30:39

You are given two positive integer arrays `spells` and `potions`, of length `n` and `m` respectively, where `spells[i]` represents the strength of the `ith` spell and `potions[j]` represents the strength of the `jth` potion.

You are also given an integer `success`. A spell and potion pair is considered **successful** if the **product** of their strengths is **at least** `success`.

Return _an integer array_ `pairs` _of length_ `n` _where_ `pairs[i]` _is the number of **potions** that will form a successful pair with the_ `ith` _spell._

**Example 1:**

**Input:** spells = \[5,1,3\], potions = \[1,2,3,4,5\], success = 7
**Output:** \[4,0,3\]
**Explanation:**
- 0th spell: 5 \* \[1,2,3,4,5\] = \[5,**10**,**15**,**20**,**25**\]. 4 pairs are successful.
- 1st spell: 1 \* \[1,2,3,4,5\] = \[1,2,3,4,5\]. 0 pairs are successful.
- 2nd spell: 3 \* \[1,2,3,4,5\] = \[3,6,**9**,**12**,**15**\]. 3 pairs are successful.
Thus, \[4,0,3\] is returned.

**Example 2:**

**Input:** spells = \[3,1,2\], potions = \[8,5,8\], success = 16
**Output:** \[2,0,2\]
**Explanation:**
- 0th spell: 3 \* \[8,5,8\] = \[**24**,15,**24**\]. 2 pairs are successful.
- 1st spell: 1 \* \[8,5,8\] = \[8,5,8\]. 0 pairs are successful. 
- 2nd spell: 2 \* \[8,5,8\] = \[**16**,10,**16**\]. 2 pairs are successful. 
Thus, \[2,0,2\] is returned.

**Constraints:**

*   `n == spells.length`
*   `m == potions.length`
*   `1 <= n, m <= 105`
*   `1 <= spells[i], potions[i] <= 105`
*   `1 <= success <= 1010`

**SOLUTION:**

    import bisect
    
    class Solution:
        def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:
            n = len(potions)
            potions.sort()
            return [n - bisect.bisect_left(potions, success / sp) for sp in spells]
The attr_accessor in Ruby?
Published: 2022-06-12 00:22:09

Ruby has object methods by default that are public and also has data that is private. To access and have the able to modify this data, we use the attr_reader and attr_writer. 

attr_accessor is a shorter way to have the ability of both attr_reader and attr_writer because people usually use data for both reading and writing. So the method attr_accessor is really quite useful.

Suppose you want to gain access and modify a variable of a Ruby object. Normally, methods would be define separately for reading and writing the data into a variable:

```ruby
class Person
  def name
    @name
  end

  def name=(str)
    @name = str
  end
end
```

But, all of the data above could be written in one line using attr_accessor:

```ruby
class Person
  attr_accessor :name
end
```

Putting it all together. Let's make a class, lets call it Person, with a variable (name). With attr_accessor, you can gain the ability to read and write to the name variable outside the class scope.

```ruby
class Person
  attr_accessor :name
end

person = Person.new

person.name = "Educative" # you can both modify ...
puts person.name          # ... and read variable
```
ifdefs
Tags: beginners, programming, multivalue, basic
Published: 2022-06-12 00:01:54

This post is specific to using ifdefs in UniVerse BASIC but the logic holds for C and C++ and I imagine any language that has compile time directives.

One of the things I ended up doing for NovaShell was adding in conditional compilation. I wanted to use the same program for both D3 and UniVerse, I also wanted to use the same file to do Windows and Linux specific things like creating directories. This meant I needed to use ifdefs. I would basically set up a few define statements and then based off those defined symbols, the compiler would compile different parts of the program.

This ultimately meant I could have UniVerse specific code in it's own block and D3 specific code in another block. I can't just do this with a simple if statement, because some of the D3 code isn't valid under UniVerse and some of the UniVerse code isn't valid under D3.

I would have loved to have it be a simple if statement as then I could simply pass in the database type in at run time and run the specific code I need, however this doesn't work and I needed to use ifdefs to control which areas get compiled.

```
$DEFINE DATABASE.UV
$DEFINE PLATFORM.LINUX
```

This will add these two variables to the symbol table.

```
            $IFDEF PLATFORM.LINUX
                $IFDEF DATABASE.UV
                    NSH.ENTRY<1> = 'F'
                    NSH.ENTRY<2> = '/tmp/.nsh/'
                    NSH.ENTRY<3> = '/tmp/.nsh/'
                $ENDIF
                $IFDEF DATABASE.D3
                    NSH.ENTRY<1> = 'Q'
                    NSH.ENTRY<3> = 'UNIX:/tmp/.nsh/'
                $ENDIF
            $ENDIF
            $IFDEF PLATFORM.WINDOWS
                $IFDEF DATABASE.UV
                    NSH.ENTRY<1> = 'F'
                    NSH.ENTRY<2> = 'DOS:C:\.nsh\'
                    NSH.ENTRY<3> = 'DOS:C:\.nsh\'
                $ENDIF
                $IFDEF DATABASE.D3
                    NSH.ENTRY<1> = 'Q'
                    NSH.ENTRY<3> = 'DOS:C:\.nsh\'
                $ENDIF
            $ENDIF
```

This chunk of code has both runtime code and compile time code. At compile time, the compiler will use the ifdef to see if it should leave that code block in the file. Ifdef stands for "if defined". For the first case, the compiler is asking if the PLATFORM.LINUX symbol is defined then include the following chunk of code.

As you can see, you can nest the ifdefs. The next ifdef checks to see if the DATABASE.UV symbol exists. If it does, include that chunk of code. In this case, based of the previous define statements, we will ultimately only leave 3 lines of code out of a possible 30 lines of code.

I used this logic in a few different places to get the NovaShell to be cross platform. I could create two programs and remove the ifdefs as the ifdefs definitely add some noise now but so much code is shared between both, that I think this makes more sense.
Shuffle an Array
Tags: leetcode, dsa, theabbie
Published: 2022-06-12 00:00:43

Given an integer array `nums`, design an algorithm to randomly shuffle the array. All permutations of the array should be **equally likely** as a result of the shuffling.

Implement the `Solution` class:

*   `Solution(int[] nums)` Initializes the object with the integer array `nums`.
*   `int[] reset()` Resets the array to its original configuration and returns it.
*   `int[] shuffle()` Returns a random shuffling of the array.

**Example 1:**

**Input**
\["Solution", "shuffle", "reset", "shuffle"\]
\[\[\[1, 2, 3\]\], \[\], \[\], \[\]\]
**Output**
\[null, \[3, 1, 2\], \[1, 2, 3\], \[1, 3, 2\]\]

**Explanation**
Solution solution = new Solution(\[1, 2, 3\]);
solution.shuffle();    // Shuffle the array \[1,2,3\] and return its result.
                       // Any permutation of \[1,2,3\] must be equally likely to be returned.
                       // Example: return \[3, 1, 2\]
solution.reset();      // Resets the array back to its original configuration \[1,2,3\]. Return \[1, 2, 3\]
solution.shuffle();    // Returns the random shuffling of array \[1,2,3\]. Example: return \[1, 3, 2\]

**Constraints:**

*   `1 <= nums.length <= 50`
*   `-106 <= nums[i] <= 106`
*   All the elements of `nums` are **unique**.
*   At most `104` calls **in total** will be made to `reset` and `shuffle`.

**SOLUTION:**

    import random
    
    class Solution:
    
        def __init__(self, nums: List[int]):
            self.nums = nums
    
        def reset(self) -> List[int]:
            return self.nums
    
        def shuffle(self) -> List[int]:
            return sorted(self.nums, key = lambda x: random.random())
    
    
    # Your Solution object will be instantiated and called as such:
    # obj = Solution(nums)
    # param_1 = obj.reset()
    # param_2 = obj.shuffle()
I rarely need Stack Overflow anymore
Tags: general, discuss
Published: 2022-06-25 09:57:56

---
title: I rarely need Stack Overflow anymore
published: true
date: 2022-06-12 00:00:00 UTC
tags: general, discuss
canonical_url: https://lankydan.dev/i-rarely-need-stack-overflow-anymore
---

I noticed recently that my dependence on Stack Overflow and similar platforms has wained as I have progressed in my career. The challenges I face and the questions arising from them have changed, becoming more abstract, handy-wavy, or super-specific to my company’s business logic. The likelihood that someone has already answered these sorts of questions becomes unlikely. Maybe, I could _try_ to ask these questions myself (I’m more of a reader of Stack Overflow rather than a contributing member), but where would I even begin. These questions aren’t asked because of the amount of context and background knowledge required to comprehend the question.

Now, don’t get me wrong. I’m not bashing Stack Overflow at all here. There are plenty of questions that can be asked or are already answered, primarily revolving around using language features, libraries and frameworks. This is where it shines, which is why “rarely” instead of “do not” is included in the title. When I’m working on my own code outside of work, it is invaluable to me. But, that’s because my questions shift into insight about language features, libraries and frameworks like I mentioned a second ago.

At this point, you are probably wondering what point I’m trying to make, and believe me, I am also trying to figure that out right now. So here I go…

If, like me, you are trying to find answers to challenges you face at work, varying from writing better code, to solving architectural issues, to even the most abstract questions of “are we solving the correct problems”; point yourself in the direction of your colleagues. They (most of the time) have the context and foundational knowledge to correctly answer questions in a way that no one else can. I can’t even begin to quantify the amount I’ve learnt from turning to my teammates for help. They may have solved similar problems in the past and can share that experience with you, all based on their ability to actually understand the nuance in what you’re asking.

For more senior engineers reading this, do not underestimate the impact sharing your knowledge has on your teammates. Every time I hear the phrase, “At my old place”, I know we’re about to for a trip through their experiences, and I also know that without these conversations, I would not have progressed at the rate I have in my own career. You cannot rely on Stack Overflow and similar platforms to level up your team, it may help, but it will not produce well-rounded engineers.

For everyone else, you cannot rely on Stack Overflow and similar platforms for everything. Read longer-form content, such as blogs, books or podcasts, focusing more on the why than the how. However, having a back and forth between other engineers will be one of the most efficient ways to improve. If you fail to do this, you will never progress to the point where you rarely need Stack Overflow anymore.
4Sum II
Tags: leetcode, dsa, theabbie
Published: 2022-06-11 23:30:36

Given four integer arrays `nums1`, `nums2`, `nums3`, and `nums4` all of length `n`, return the number of tuples `(i, j, k, l)` such that:

*   `0 <= i, j, k, l < n`
*   `nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0`

**Example 1:**

**Input:** nums1 = \[1,2\], nums2 = \[-2,-1\], nums3 = \[-1,2\], nums4 = \[0,2\]
**Output:** 2
**Explanation:**
The two tuples are:
1. (0, 0, 0, 1) -> nums1\[0\] + nums2\[0\] + nums3\[0\] + nums4\[1\] = 1 + (-2) + (-1) + 2 = 0
2. (1, 1, 0, 0) -> nums1\[1\] + nums2\[1\] + nums3\[0\] + nums4\[0\] = 2 + (-1) + (-1) + 0 = 0

**Example 2:**

**Input:** nums1 = \[0\], nums2 = \[0\], nums3 = \[0\], nums4 = \[0\]
**Output:** 1

**Constraints:**

*   `n == nums1.length`
*   `n == nums2.length`
*   `n == nums3.length`
*   `n == nums4.length`
*   `1 <= n <= 200`
*   `-228 <= nums1[i], nums2[i], nums3[i], nums4[i] <= 228`

**SOLUTION:**

    class Solution:
        def numTuples(self, k, i, n):
            if (i, k) in self.cache:
                return self.cache[(i, k)]
            if i == n - 1:
                ctr = self.nums[i].count(k)
                self.cache[(i, k)] = ctr
                return ctr
            else:
                ctr = 0
                for num in self.nums[i]:
                    ctr += self.numTuples(k - num, i + 1, n)
                self.cache[(i, k)] = ctr
                return ctr
        
        def fourSumCount(self, nums1: List[int], nums2: List[int], nums3: List[int], nums4: List[int]) -> int:
            self.cache = {}
            self.nums = [nums1, nums2, nums3, nums4]
            return self.numTuples(0, 0, len(self.nums))
Scramble String
Tags: leetcode, dsa, theabbie
Published: 2022-06-09 19:00:42

We can scramble a string s to get a string t using the following algorithm:

1.  If the length of the string is 1, stop.
2.  If the length of the string is > 1, do the following:
    *   Split the string into two non-empty substrings at a random index, i.e., if the string is `s`, divide it to `x` and `y` where `s = x + y`.
    *   **Randomly** decide to swap the two substrings or to keep them in the same order. i.e., after this step, `s` may become `s = x + y` or `s = y + x`.
    *   Apply step 1 recursively on each of the two substrings `x` and `y`.

Given two strings `s1` and `s2` of **the same length**, return `true` if `s2` is a scrambled string of `s1`, otherwise, return `false`.

**Example 1:**

**Input:** s1 = "great", s2 = "rgeat"
**Output:** true
**Explanation:** One possible scenario applied on s1 is:
"great" --> "gr/eat" // divide at random index.
"gr/eat" --> "gr/eat" // random decision is not to swap the two substrings and keep them in order.
"gr/eat" --> "g/r / e/at" // apply the same algorithm recursively on both substrings. divide at random index each of them.
"g/r / e/at" --> "r/g / e/at" // random decision was to swap the first substring and to keep the second substring in the same order.
"r/g / e/at" --> "r/g / e/ a/t" // again apply the algorithm recursively, divide "at" to "a/t".
"r/g / e/ a/t" --> "r/g / e/ a/t" // random decision is to keep both substrings in the same order.
The algorithm stops now, and the result string is "rgeat" which is s2.
As one possible scenario led s1 to be scrambled to s2, we return true.

**Example 2:**

**Input:** s1 = "abcde", s2 = "caebd"
**Output:** false

**Example 3:**

**Input:** s1 = "a", s2 = "a"
**Output:** true

**Constraints:**

*   `s1.length == s2.length`
*   `1 <= s1.length <= 30`
*   `s1` and `s2` consist of lowercase English letters.

**SOLUTION:**

    class Solution:
        def isPos(self, s1, s2, a, b, c, d):
            n = b - a
            if n == 1:
                if s1[a] == s2[c]:
                    return True
                else:
                    return False
            key = (a, b, c, d)
            if key in self.cache:
                return self.cache[key]
            for l in range(1, n):
                r = n - l
                if self.isPos(s1, s2, a, a + l, c, c + l) and self.isPos(s1, s2, a + l, b, d - r, d):
                    self.cache[key] = True
                    return True
                if self.isPos(s1, s2, a, a + l, d - l, d) and self.isPos(s1, s2, a + l, b, c, c + r):
                    self.cache[key] = True
                    return True
            self.cache[key] = False
            return False
        
        def isScramble(self, s1: str, s2: str) -> bool:
            n = len(s1)
            self.cache = {}
            return self.isPos(s1, s2, 0, n, 0, n)
🙊 What do the Developer Advocates do? - Dev Advocate Journal (#DAJ) Day 1
Tags: advocate, develop, devjournal
Published: 2022-06-11 22:54:54

It's important to me to do this. Start this new season in my life.

Grandma, I want to be a developer advocate!

I want to share my weird experience telling you what I am doing to be a developer advocate. Maybe I can have great success or a funny failure, but I need to try this.
For today's chapter, I will define what a developer advocate does, and I will tell you about the first step I will take to become one.


## 🤷 What do the developer advocates do?

Well, we promote the use of technology, and we help other developers to use the company's products designed for them; this can be with good documentation, making demos, tutorials, and anything that makes sense for the company to be in contact with the developers. Another task that seemed super important to me in this role is that we have to be active listeners, and in the end, we try to communicate our products better.


## 🤯 My first step to being a dev advocate

Seriously committed to improving my professional English speaking and writing skills. I can't cancel that again.

![Grinch - I can't cancel that again](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s1eczlevbkzpmxj52yhc.gif)

And that's it for today 🙌 🎉


**You can follow this journal to know what happens with my new path or if you are curious about precisely what I will do to exponentially improve my English.**


_Thanks for reading, see you later_ 💜
Binary Gap
Tags: leetcode, dsa, theabbie
Published: 2022-06-11 22:30:36

Given a positive integer `n`, find and return _the **longest distance** between any two **adjacent**_ `1`_'s in the binary representation of_ `n`_. If there are no two adjacent_ `1`_'s, return_ `0`_._

Two `1`'s are **adjacent** if there are only `0`'s separating them (possibly no `0`'s). The **distance** between two `1`'s is the absolute difference between their bit positions. For example, the two `1`'s in `"1001"` have a distance of 3.

**Example 1:**

**Input:** n = 22
**Output:** 2
**Explanation:** 22 in binary is "10110".
The first adjacent pair of 1's is "10110" with a distance of 2.
The second adjacent pair of 1's is "10110" with a distance of 1.
The answer is the largest of these two distances, which is 2.
Note that "10110" is not a valid pair since there is a 1 separating the two 1's underlined.

**Example 2:**

**Input:** n = 8
**Output:** 0
**Explanation:** 8 in binary is "1000".
There are not any adjacent pairs of 1's in the binary representation of 8, so we return 0.

**Example 3:**

**Input:** n = 5
**Output:** 2
**Explanation:** 5 in binary is "101".

**Constraints:**

*   `1 <= n <= 109`

**SOLUTION:**

    class Solution:
        def binaryGap(self, n: int) -> int:
            curr = "{:b}".format(n)
            n = len(curr)
            mdist = 0
            prev = -1
            for i in range(n):
                if curr[i] == "1":
                    if prev >= 0:
                        mdist = max(mdist, i - prev)
                    prev = i
            return mdist
Key challenges that MLOps addresses
Tags: machinelearning, ai, beginners
Published: 2022-06-11 22:12:37

An engineering discipline aiming to unify [Machine Learning ](bpbonline.com/collections/machine-learning)systems development (dev) and ML systems deployment (ops) to standardize and streamline the continuous delivery of high-performing models in production is MLOps.

In a wide range of applications today, we are embedding decision automation, which generates a lot of technical challenges that come from building and deploying ML-based systems.

The ML systems lifecycle involves different teams of a data-driven organization.

From start to bottom, the following teams are involved:
- Business development or product team—defining business objectives with KPIs
- Data engineering — data acquisition and preparation
- [Data science](bpbonline.com/collections/data-science) — architecting ML solutions and developing models
- IT or [DevOps](bpbonline.com/search?q=DevOps&type=product)—complete deployment setup, monitoring alongside scientists

There are several bottlenecks to be taken care of, and it is not an easy task to manage such systems at scale. The following are the key challenges that the teams have come up with:
- There is a shortage of Data Scientists who are good at developing and deploying scalable web apps. The profile of ML Engineers aims to serve this need. It is at the intersection of Data Science and DevOps.
- Reflecting changing business objectives in the model—with the data continuously changing, maintaining performance standards of the model, and ensuring AI governance, there are many dependencies. It is hard to keep up with the continuous model training and evolving business objectives.
- The communication gaps between technical and business teams with a hard-to-find common language to collaborate. This gap is the reason for the failure of several projects, most often.
- Risk assessment—a lot of debate is doing rounds concerning the black-box nature of ML systems. Often models tend to drift away from what they were initially intended to do. Assessing the risk/cost of such failures is a very important and meticulous step.

Hope this was helpful.