teleren/devto huggingface dataset:
ReUsable UseFetch Utility in C#
Tags: csharp, dotnet
Published: 2022-06-14 10:33:25

This ReUsable UseFetch Utility used for API data fetching, it can serialize and deserialize objects on the fly.

## Headers
```c#
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json;
```

## Class
```c#
public static class UseFetch
    {
        public static TResponse Get<TResponse>(string url,
            Dictionary<string, string> headers = null)
            where TResponse : class
        {
            try
            {
                var client = new HttpClient();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                if (headers != null)
                {
                    foreach (var header in headers)
                    {
                        client.DefaultRequestHeaders.Add(header.Key, header.Value);
                    }
                }

                var response = client.GetAsync(url).Result;

                var responseString = response.Content.ReadAsStringAsync().Result;

                var deserializedResponse = JsonConvert.DeserializeObject<TResponse>(responseString);

                return deserializedResponse;
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
        }

        public static TResponse Post<TResponse, TRequest>(string url, TRequest request,
            Dictionary<string, string> headers = null)
            where TRequest : class, new()
            where TResponse : class
        {
            try
            {
                var serializeRequest = JsonConvert.SerializeObject(request);

                var content = new StringContent(serializeRequest);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                var client = new HttpClient();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                if (headers != null)
                {
                    foreach (var header in headers)
                    {
                        client.DefaultRequestHeaders.Add(header.Key, header.Value);
                    }
                }

                var response = client.PostAsync(url, content).Result;

                var responseString = response.Content.ReadAsStringAsync().Result;

                var deserializedResponse = JsonConvert.DeserializeObject<TResponse>(responseString);

                return deserializedResponse;
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
        }
    }
```
enjoy 🚀
Merge Nodes in Between Zeros
Tags: leetcode, dsa, theabbie
Published: 2022-06-14 10:30:39

You are given the `head` of a linked list, which contains a series of integers **separated** by `0`'s. The **beginning** and **end** of the linked list will have `Node.val == 0`.

For **every** two consecutive `0`'s, **merge** all the nodes lying in between them into a single node whose value is the **sum** of all the merged nodes. The modified list should not contain any `0`'s.

Return _the_ `head` _of the modified linked list_.

**Example 1:**

![](https://assets.leetcode.com/uploads/2022/02/02/ex1-1.png)

**Input:** head = \[0,3,1,0,4,5,2,0\]
**Output:** \[4,11\]
**Explanation:** 
The above figure represents the given linked list. The modified list contains
- The sum of the nodes marked in green: 3 + 1 = 4.
- The sum of the nodes marked in red: 4 + 5 + 2 = 11.

**Example 2:**

![](https://assets.leetcode.com/uploads/2022/02/02/ex2-1.png)

**Input:** head = \[0,1,0,3,0,2,2,0\]
**Output:** \[1,3,4\]
**Explanation:** 
The above figure represents the given linked list. The modified list contains
- The sum of the nodes marked in green: 1 = 1.
- The sum of the nodes marked in red: 3 = 3.
- The sum of the nodes marked in yellow: 2 + 2 = 4.

**Constraints:**

*   The number of nodes in the list is in the range `[3, 2 * 105]`.
*   `0 <= Node.val <= 1000`
*   There are **no** two consecutive nodes with `Node.val == 0`.
*   The **beginning** and **end** of the linked list have `Node.val == 0`.

**SOLUTION:**

    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, val=0, next=None):
    #         self.val = val
    #         self.next = next
    class Solution:
        def mergeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]:
            if not head:
                return head
            head = head.next
            curr = head
            total = 0
            while curr:
                total += curr.val
                if curr.val == 0:
                    head = ListNode(val = total)
                    head.next = self.mergeNodes(curr)
                    return head
                curr = curr.next
How to growth as a developer faster?
Published: 2022-06-14 10:17:51

Hello, I am Roman I've been working for years as a software engineer in small startups and big outsourcing companies, and the biggest challenge for developers after you get the job understand what is next?

Life is divided between before and after you get a job. Before you know exactly what to do and the goal is to be prepared for a future tech interview stage. 
The most important stage to getting a job as a developer is your technical skills, understanding Software Development Life Cycle(SDLC)
The traditional way is:
- take courses in web-development (Udemy)
- Find a job propositions (LinkedIn)
- Prepare resume
- Prepare for an interview (LeetCode)
- Pass the technical interview

OK, what is wrong?

I think communication is missing there! When you go through your learning path, share with others your failures and progress.
**StackOverflow** - ask questions, join the Intelligent community and ask more and publicly. 
StackOverflow trick! If nobody answers your questions, try to "start bounty"

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

**Instagram** - not only for fun pics but to follow like-minded people, either those who just started the journey in IT or experienced gurus.

**Twitter** - the most powerful tool ever! Because code is just a text, and programming languages are syntax rules to write the texts. The developer's job is to learn to read, write and improve this text before the compiler transforms text into machine byte-code. And you've never found a better writer than developers because they read & write a ton of words every day. That is why microblog Twitter is the best place to share your thoughts and communicate your progress with like-minded people.
Here some realy motivated people who you can follow:
[Sumit | Javascript 🤝 React](https://twitter.com/sumitsaurabh927),
[Stas Klymenko | Full-stack Web Developer](https://twitter.com/StasKlymenko),
[Francesco Ciulla](https://twitter.com/FrancescoCiull4), [Abel](https://twitter.com/abeltxor),
[Pratham](https://twitter.com/Prathkum),
[Priya_garg](https://twitter.com/priya_garg2)

Communication is the best way to grow as a developer because your attitude to your job is changing and you can not just earn money but brings value to others who follow you and you can learn from experienced guys as well! 

The number of followers doesn't matter, just think that if they can then you can as well! No difference whether you have some  fans or you just started, communicate with others, react to tweets, support those who need it, and post value content frequently! 

Follow me on 🐦 [Twitter](https://twitter.com/DevMoroh) if you want to see more content.
1339. leetcode solution in cpp
Tags: cpp
Published: 2022-06-14 10:12:10

```
class Solution {
 public:
  int maxProduct(TreeNode* root) {
    constexpr int kMod = 1e9 + 7;
    long ans = 0;
    vector<int> allSums;
    const long totalSum = treeSum(root, allSums);

    for (const long sum : allSums)
      ans = max(ans, sum * (totalSum - sum));

    return ans % kMod;
  }

 private:
  int treeSum(TreeNode* root, vector<int>& allSums) {
    if (!root)
      return 0;

    const int leftSum = treeSum(root->left, allSums);
    const int rightSum = treeSum(root->right, allSums);
    const int sum = root->val + leftSum + rightSum;
    allSums.push_back(sum);
    return sum;
  }
};
```
Longest Word in Dictionary
Tags: leetcode, dsa, theabbie
Published: 2022-06-14 01:30:37

Given an array of strings `words` representing an English Dictionary, return _the longest word in_ `words` _that can be built one character at a time by other words in_ `words`.

If there is more than one possible answer, return the longest word with the smallest lexicographical order. If there is no answer, return the empty string.

**Example 1:**

**Input:** words = \["w","wo","wor","worl","world"\]
**Output:** "world"
**Explanation:** The word "world" can be built one character at a time by "w", "wo", "wor", and "worl".

**Example 2:**

**Input:** words = \["a","banana","app","appl","ap","apply","apple"\]
**Output:** "apple"
**Explanation:** Both "apply" and "apple" can be built from other words in the dictionary. However, "apple" is lexicographically smaller than "apply".

**Constraints:**

*   `1 <= words.length <= 1000`
*   `1 <= words[i].length <= 30`
*   `words[i]` consists of lowercase English letters.

**SOLUTION:**

    class Solution:
        def longestWord(self, words: List[str]) -> str:
            words = set(words)
            mword = ""
            for word in words:
                n = len(word)
                valid = True
                for i in range(1, n):
                    if word[:i] not in words:
                        valid = False
                        break
                if valid:
                    if len(word) > len(mword):
                        mword = word
                    elif len(word) == len(mword) and word < mword:
                        mword = word
            return mword
1423. leetcode solution in javascript
Tags: javascript
Published: 2022-06-14 10:10:08

```
var maxScore = function(C, K) {
    let total = 0
    for (let i = 0; i < K; i++) total += C[i]
    let best = total
    for (let i = K - 1, j = C.length - 1; ~i; i--, j--)
        total += C[j] - C[i], best = Math.max(best, total)
    return best
};
```
1448. leetcode solution in cpp
Tags: cpp
Published: 2022-06-14 10:08:20

```

class Solution {
 public:
  int goodNodes(TreeNode* root, int maxi = INT_MIN) {
    if (!root)
      return 0;

    const int newMax = max(maxi, root->val);
    return (root->val >= maxi) +
           goodNodes(root->left, newMax) +
           goodNodes(root->right, newMax);
  }
};
```
Internet Explorer retires👴👵
Tags: webdev
Published: 2022-06-14 10:07:57

IE is retiring, after many years of cursing, I have seen less and less support tickets for IE and I'm glad to say that things have become a lot better. I'm not having a party like I had promised myself, IE died with a whimper not a roar.

For details of exact dates, please consult your hand held Google manual.

😁
Partitioning Into Minimum Number Of Deci-Binary Numbers
Tags: leetcode, dsa, theabbie
Published: 2022-06-14 10:00:48

A decimal number is called **deci-binary** if each of its digits is either `0` or `1` without any leading zeros. For example, `101` and `1100` are **deci-binary**, while `112` and `3001` are not.

Given a string `n` that represents a positive decimal integer, return _the **minimum** number of positive **deci-binary** numbers needed so that they sum up to_ `n`_._

**Example 1:**

**Input:** n = "32"
**Output:** 3
**Explanation:** 10 + 11 + 11 = 32

**Example 2:**

**Input:** n = "82734"
**Output:** 8

**Example 3:**

**Input:** n = "27346209830709182346"
**Output:** 9

**Constraints:**

*   `1 <= n.length <= 105`
*   `n` consists of only digits.
*   `n` does not contain any leading zeros and represents a positive integer.

**SOLUTION:**

    class Solution:
        def minPartitions(self, n: str) -> int:
            return max([int(d) for d in n])
1457. leetcode solution in cpp
Tags: cpp
Published: 2022-06-14 10:07:24

```
class Solution {
 public:
  int pseudoPalindromicPaths(TreeNode* root) {
    int ans = 0;
    dfs(root, 0, ans);
    return ans;
  }

 private:
  void dfs(TreeNode* root, int path, int& ans) {
    if (!root)
      return;
    if (!root->left && !root->right) {
      path ^= 1 << root->val;
      if ((path & (path - 1)) == 0)
        ++ans;
      return;
    }

    dfs(root->left, path ^ 1 << root->val, ans);
    dfs(root->right, path ^ 1 << root->val, ans);
  }
};
```
957. leetcode Solution in cpp
Tags: cpp
Published: 2022-06-14 10:02:51

```
class Solution {
 public:
  vector<int> prisonAfterNDays(vector<int>& cells, int N) {
    vector<int> firstDayCells;
    vector<int> nextDayCells(cells.size());

    for (int day = 0; N-- > 0; cells = nextDayCells, ++day) {
      for (int i = 1; i + 1 < cells.size(); ++i)
        nextDayCells[i] = cells[i - 1] == cells[i + 1];
      if (day == 0)
        firstDayCells = nextDayCells;
      else if (nextDayCells == firstDayCells)
        N %= day;
    }

    return cells;
  }
};
```
932. leetcode solution in CPP
Tags: cpp
Published: 2022-06-14 10:01:22


```

class Solution {
 public:
  vector<int> beautifulArray(int n) {
    vector<int> A(n);
    iota(begin(A), end(A), 1);
    divide(A, 0, n - 1, 1);
    return A;
  }

 private:
  void divide(vector<int>& A, int l, int r, int mask) {
    if (l >= r)
      return;
    const int m = partition(A, l, r, mask);
    divide(A, l, m, mask << 1);
    divide(A, m + 1, r, mask << 1);
  }

  int partition(vector<int>& A, int l, int r, int mask) {
    int nextSwapped = l;
    for (int i = l; i <= r; ++i)
      if (A[i] & mask)
        swap(A[i], A[nextSwapped++]);
    return nextSwapped - 1;
  }
};
```
926. Leetcode solution in JAVA
Tags: java
Published: 2022-06-14 10:00:00

```
class Solution {
  public int minFlipsMonoIncr(String S) {
    int[] dp = new int[2];

    for (int i = 0; i < S.length(); ++i) {
      int temp = dp[0] + (S.charAt(i) == '1' ? 1 : 0);
      dp[1] = Math.min(dp[0], dp[1]) + (S.charAt(i) == '0' ? 1 : 0);
      dp[0] = temp;
    }

    return Math.min(dp[0], dp[1]);
  }
}
```
5 Tips to conduct yourself in an interview
Published: 2022-06-14 09:57:19

An interview often starts with the interviewer asking the interviewee, “Tell me about yourself.” It is one of those make or break impressions in the interview kind of a question. A well-framed answer can impress the interviewer. However, if you do not prepare your solution well in advance, your entire interview can go south. So, this question plays a crucial role in your interview.

https://www.hirect.in/blog/how-to-introduce-yourself-in-an-interview/
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pmrrrn9x3ausjbwus8q5.png)
Power of Four
Tags: leetcode, dsa, theabbie
Published: 2022-06-14 09:30:39

Given an integer `n`, return _`true` if it is a power of four. Otherwise, return `false`_.

An integer `n` is a power of four, if there exists an integer `x` such that `n == 4x`.

**Example 1:**

**Input:** n = 16
**Output:** true

**Example 2:**

**Input:** n = 5
**Output:** false

**Example 3:**

**Input:** n = 1
**Output:** true

**Constraints:**

*   `-231 <= n <= 231 - 1`

**Follow up:** Could you solve it without loops/recursion?**SOLUTION:**

    class Solution:
        def isPowerOfFour(self, n: int) -> bool:
            bi = "{:b}".format(n)
            return n > 0 and bi.count("1") == 1 and bi[::-1].index("1") % 2 == 0
Elixir tip for beginners !
Tags: webdev, elixir, beginners, programming
Published: 2022-06-14 09:30:04

**Beginner Tip #1 !**


{% embed https://youtube.com/shorts/9PWEsWlK3ok %}

**Beginner Tip #2**
Did you know that you don’t have to re-run iex -S mix to reload iex with your changes ?
You can simply use the IEx.Helpers.recompile/0 function

{% embed https://youtube.com/shorts/-sw4_0hYQNg %}
QL to query convert chrome time stamp to epoch milliseconds
Tags: sql, beginners, sqlite, chrome
Published: 2022-06-14 09:05:45

I am trying query the Chrome history database and return the chromium timestamp as human readable. for example 14/06/2022 10:05:30.25

SELECT u.url AS URL, u.title AS Title, u.visit_count As "Visit Count", datetime(u.last_visit_time / 1000000 + (strftime('%s', '1601-01-01')), 'unixepoch', 'localtime') As "Last Visited Date Time", datetime(v.visit_time / 1000000 + (strftime('%s', '1601-01-01')), 'unixepoch', 'localtime') AS "Visited Date Time" FROM urls u, visits v WHERE u.id = v.url
Explicit receiver parameter(this) in Java 8
Published: 2022-06-14 09:00:20

Explicit receiver parameter เป็นฟีเจอร์ที่มาใหม่ตั้งแต่ Java 8 ไม่ค่อยได้ใช้ บางครั้งก็ลืมกันไปเลยว่ามี วันนี้เรามา Note ไว้ซะหน่อย

ปกติแล้วเวลาเราเรียกเมธอดที่เป็น instance method (ที่ไม่ใช่ static) จาวาคอมไพล์เลอร์จะใส่ implicit receive parameter ที่ตำแหน่ง 0 ที่หมายถึง instance ของ object(แทนด้วย this)

เช่น ถ้ามีเมธอด `int getAge()` เวลาคอมไพล์ออกมาจะได้ `getAge(Person p)` เพื่อที่จะได้เรียกเมธอด getAge() ใน context ของ object ใดๆโดยคอมไพเลอร์จัดการให้และไม่ยอมให้เราใส่เอง
```java
class Person{
int getAge(){..}

\\คอมไพล์แล้วจะได้แบบนี้นะ(ใน bytecode อยู่ลำดับแรกของพารามิเตอร์)
int getAge(Person p){...}
}
```

แต่ว่า Java 8 เพิ่มฟีเจอร์ใหม่มาทำให้เราสามารถประกาศเมธอดที่มี receive parameter ได้ (แต่ตอน call method จะระบุไม่ได้เหมือนเดิม)
สาเหตที่เพิ่มมาเพราะเพื่อให้เราเพิ่ม annotation เข้าไปตรง receiver parameter ได้

โดยเราสามารถ reflection เอา annotaion ได้จาก `Method.getAnnotatedReceiverType()`

```java
class Person {
    int age;

    public int getAge(@MyAnnotation Person this) {
        return this.age;
    }

    public void setAge(Person this, int age) {
        this.age = age;
    }
}

public class App {
    public static void main(String[] args) {
        Person p = new Person();
        p.setAge(10);
        p.getAge();
    }
}

```

ถ้าใครเขียน Python คงนึกออก เพราะเราต้องเวลาประกาศเมธอดก็ต้องมี explicit receiver( self ) เช่นกัน 

ref:: https://blog.joda.org/2015/12/explicit-receiver-parameters.html
Hello devcomm
Tags: greeting, hello, quantumreality, geopolitics
Published: 2022-06-14 08:52:18

Hello dev community. Greetings from South Florida. Looking for points of convergence.
My interests: jazz (Miles), sailing, great books, Picasso, quantum mechanics, quantum reality, geopolitics,US politics, cyber security,constitutional law. Pique your interest? Drop me a line.
Today's Fun Joke For Developers - Daily Developer Jokes
Tags: jokes, dailydeveloperjokes
Published: 2022-06-14 08:00:26

---
title: "Today's Fun Joke For Developers - Daily Developer Jokes"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
published: true
tags: #jokes, #dailydeveloperjokes
---

Hi there! Here's today's Daily Developer Joke. We hope you enjoy it; it's a good one.

![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1258d16351b.png)

---

For more jokes, and to submit your own joke to get featured, check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/). We're also open sourced, so feel free to view [our GitHub Profile](https://github.com/dailydeveloperjokes).

### Leave this post a ❤️ if you liked today's joke, and stay tuned for tomorrow's joke too!

_This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit._

<!--
Joke text:
___Q:___ What do you get when you cross a computer and a life guard?

___A:___ A screensaver!
 -->
Count and Say
Tags: leetcode, dsa, theabbie
Published: 2022-06-14 08:30:38

The **count-and-say** sequence is a sequence of digit strings defined by the recursive formula:

*   `countAndSay(1) = "1"`
*   `countAndSay(n)` is the way you would "say" the digit string from `countAndSay(n-1)`, which is then converted into a different digit string.

To determine how you "say" a digit string, split it into the **minimal** number of substrings such that each substring contains exactly **one** unique digit. Then for each substring, say the number of digits, then say the digit. Finally, concatenate every said digit.

For example, the saying and conversion for digit string `"3322251"`:

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

Given a positive integer `n`, return _the_ `nth` _term of the **count-and-say** sequence_.

**Example 1:**

**Input:** n = 1
**Output:** "1"
**Explanation:** This is the base case.

**Example 2:**

**Input:** n = 4
**Output:** "1211"
**Explanation:**
countAndSay(1) = "1"
countAndSay(2) = say "1" = one 1 = "11"
countAndSay(3) = say "11" = two 1's = "21"
countAndSay(4) = say "21" = one 2 + one 1 = "12" + "11" = "1211"

**Constraints:**

*   `1 <= n <= 30`

**SOLUTION:**

    class Solution:
        def countAndSay(self, n: int) -> str:
            if n == 1:
                return "1"
            prev = self.countAndSay(n - 1)
            n = len(prev)
            op = ""
            i = 0
            while i < n:
                ctr = 1
                while i < n - 1 and prev[i] == prev[i + 1]:
                    ctr += 1
                    i += 1
                i += 1
                op += str(ctr) + prev[i - 1]
            return op
Is Ethereum going to die like $Luna?
Tags: blockchain, discuss, news, productivity
Published: 2022-06-14 08:07:02

You guys may be thinking that after Luna, Ethereum is going to be RIP soon, right?
Since April 4 the price is come down from $3500 to $1200 as of today, and its a huge drop that cause chaos in the crypto market.

**What Exactly Happened?**

Ethereum is currently into process of transitioning from proof-of-work to proof-of-stake consensus mechanism. The actual transition is expected to take place in august the process is named as merge. Last week the eth developers did a dry on on one of the longest running Testnet called Ropston, the merge was successful but eths price started declined by that time. There were many bugs in the merge process, and the merge did not went as smooth as planned by many investors, this presumably led to fear that the actual merge be delayed.

When eth developers agreed that it will take more 2- 3 months before the actual process, suggesting there is more work to happen before actual merge can happen.

Due to these difficulties in merge and time delays all the leverage traders who were looking to go long on back of the Ropsten merge liquidated causing eths price to decline.

The price of Lido Staked Ethereum (stETH) has diverged sharply from the price of Ethereum (ETH) in the last 48 hours. Theoretically, however, the stETH token in supposed to trade at a 1:1 peg to ETH. 

While st eth is facing liquidity risk in short term it is inherently different from terra's ust, it does not face same death spiral risks, because each st eth is redeemable for 1 eth as soon as merge is completed and unstaking is enabled.
Pow(x, n)
Tags: leetcode, dsa, theabbie
Published: 2022-06-14 07:30:38

Implement [pow(x, n)](http://www.cplusplus.com/reference/valarray/pow/), which calculates `x` raised to the power `n` (i.e., `xn`).

**Example 1:**

**Input:** x = 2.00000, n = 10
**Output:** 1024.00000

**Example 2:**

**Input:** x = 2.10000, n = 3
**Output:** 9.26100

**Example 3:**

**Input:** x = 2.00000, n = -2
**Output:** 0.25000
**Explanation:** 2\-2 = 1/22 = 1/4 = 0.25

**Constraints:**

*   `-100.0 < x < 100.0`
*   `-231 <= n <= 231-1`
*   `-104 <= xn <= 104`

**SOLUTION:**

    class Solution:
        def myPow(self, x: float, n: int) -> float:
            if n < 0:
                return 1 / self.myPow(x, -n)
            if n == 0:
                return 1
            if n % 2 == 0:
                curr = self.myPow(x, n // 2)
                return curr * curr
            else:
                curr = self.myPow(x, (n - 1) // 2)
                return x * curr * curr