teleren/devto huggingface dataset:
Procedural Vs Functional way of solving a JS interview problem
Tags: javascript, programming, interview
Published: 2023-08-05 06:12:28

Are you also stuck clearing the UI interviews 😕, don’t worry i have a problem for you to practise and learn 😎

## 💡Problem

Write a method called readKey that can access nested properties of an object using a given path.

Some use case for better understanding the problem

```
const obj = {
  a: 1,
  b: {
    c: 2,
    d: {
      e: 3
    }
  }
}
console.log(readKey(obj, 'a')); // Output: 1
console.log(readKey(obj, 'b.c')); // Output: 2
console.log(readKey(obj, 'b.d.e')); // Output: 3
console.log(readKey(obj, 'x.y.z')); // Output: undefined (Property not found)
```

Here’s how i thought of implementing the same using two approaches:

## Procedural code 😕

```
function readKey(obj, path) {
  const keys = path.split('.');
  let result = obj;
  for (const key of keys) {
    if (typeof result === 'object' && result !== null) {
      result = result[key];
    } else {
      return undefined; // Property not found
    }
  }
  return result;
}
```

## Functional code 😎

```
function readKey(obj, path) {
  return path
    .split('.')
    .reduce((acc, key) => {
      if (acc !== null && typeof acc === 'object') {
        return acc[key]
      }
    }, obj)
}
```

✋ Ignoring some edge cases in code for the sake of simplicity only.

Now, comparing both the approaches pros and cons 🤷‍♂️

To me functional approach is clean, short, abstract and more descriptive. Also shorter the code, less is the surface area for bugs 😁

On the other side, one can argue that procedural code is more optimized as we cannot break from reduce method when we are sure of not finding the key path in object 🤔 but still i trade that off with code readability 😎

What is your opinion on this 🤔 ? Please comment.

If you found this post relevant and worth read, follow me for more …
Closure
Tags: ai
Published: 2023-08-05 06:08:34

After a pause, this series comes to a conclusion, mostly because of the rapid developments in the area of large language models.

## Original intention

At the beginning I intended to create a language model, that would have gotten a prompt "Geschirrabwaschgesetz" (a law about washing dishes) and write me a corresponding law text in German.

I was discouraged from training the original [char RNN](http://karpathy.github.io/2015/05/21/rnn-effectiveness/) because of the scary amount of training time with a 110 M training data. Therefore I went with fine-tuning a [German GPT-2](https://huggingface.co/dbmdz/german-gpt2) (and later [the better one](https://huggingface.co/benjamin/gerpt2); thanks Jo!). The fine-tuning process of such a model is described [here](https://www.philschmid.de/fine-tune-a-non-english-gpt-2-model-with-huggingface) or [here](https://blog.oliverflasch.de/german-gpt2/), for example.

## (Un-)expected discovery

I happened to discover that my intended case is covered perfectly by the [LLAMA 2 Chat German](https://huggingface.co/jphme/Llama-2-13b-chat-german) model (almost, because of a few grammatical errors). This is very likely because of being fine-tuned with the [German legal SQuAD](https://huggingface.co/datasets/Christoph911/German-legal-SQuAD) dataset, among others.

I do not want to withhold the result from you (produced in [LM Studio](https://lmstudio.ai)): ![Output to "Geschirrabwaschgesetz"](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h36f7kb1t0h0j03a4h1r.png)

Just look at this beauty! It even defined "Hygiene" in the last subparagraph! And hence this series is concluded.
The Chilling Fun in Haunted Dorm Mod Apk
Tags: haunteddormmodapk, techtodown
Published: 2023-08-05 01:38:15

Horror game enthusiasts, the wait is finally over! **[Haunted Dorm Mod Apk](https://techtodown.com/haunted-dorm-mod-apk/)** is here to let you experience a game that will give you goosebumps and an adrenaline rush. Developed by WHWL, this game has unique stigmatic themes and effects that will keep you on edge. This modded version of the Haunted Dorm is filled with several advanced modes, perfect for tower defense and puzzle game lovers. With unlimited money and premium slots, this game is the ultimate hub for all horror game lovers.

First and foremost, let's talk about the advanced mod features. The Haunted Dorm Mod Apk has several advanced mod features that give it an edge over its traditional version. From enhanced graphics to a well-structured storyline, the game has everything you ever wanted. Advanced security settings ensure maximum protection of your data, while energy hood slots give you an unlimited power reserve. The well-researched horror themes of the game have the potential to create an immersive as well as a terrifying atmosphere.

The Haunted Dorm Mod Apk also caters to tower defense and puzzle game lovers. The mounted playing stations for these games are accompanied by various other stimulating gaming stats. The game has several levels that will challenge your strategic and logical skills. As you climb through the levels, you will come across several surprises that will leave you astounded.

Moreover, the Haunted Dorm Mod Apk has unlimited money and premium slots. Whether it's purchasing upgrades or unlocking new levels, you no longer have to worry about running out of resources. The premium slots allow you to explore the game to its fullest extent, as it offers several features not available in the traditional version.

The Haunted Dorm Mod Apk can be downloaded from the Google Play Store or from our website. To download it from our website, allow unknown resources in your android. You can also check out the reviews of other gamers who have downloaded and played the game. The game has received several positive reviews from horror game enthusiasts who claim that this game has exceeded their expectations.

In conclusion, the Haunted Dorm Mod Apk is the ultimate go-to game for all horror game lovers. With its advanced mod features, mounted playing stations, unlimited money, and premium slots, the game is sure to keep you entertained for hours. Download it today and experience the spine-tingling atmosphere that this game offers.
🚀 Embracing the Beauty of Functional-Style Programming! 🌟
Tags: javascript, python, java, programming
Published: 2023-08-05 04:51:38

let's explore the wonderful world of functional-style programming, a paradigm that's all about elegance and clarity. 🌈

**Functional-Style Programming: What's the Buzz About?**

In functional-style programming, we treat computation as the evaluation of mathematical functions. 🧮 The focus shifts from 'how' to 'what', making the code more declarative and expressive. Let's dive into some characteristics that define this paradigm:

1. **Immutability 🛡️**: Say goodbye to mutable data! In functional programming, data is immutable once created. Functions create new data with desired changes, preserving the original state.

2. **Higher-Order Functions 🔄**: Flexibility is key! Functions can accept other functions as arguments and return functions as results. This enables powerful code composition and reusability.

3. **First-Class Functions 🌟**: Treat functions like VIPs! They can be assigned to variables, passed as arguments, and returned as values.

4. **No Side Effects 🚫**: Keep it clean! Functions avoid side effects, meaning they don't mess with external state. Predictable, right?

5. **Recursion 🔄**: Looping? Nah, let's embrace recursion! Functional programming often opts for recursive approaches for iteration.

6. **Lazy Evaluation ⏯️**: Don't hurry! Some functional languages use lazy evaluation, delaying expression evaluation until needed.

**Identifying Functional-Style Programming 🕵️‍♂️**

To spot functional-style programming in action, keep an eye out for these telltale signs:

1. **Immutability 🗝️**: Immutable data? Bingo! It aligns with functional programming.

2. **Higher-Order Functions 🔄**: Functions taking functions? Functions returning functions? You've got yourself a functional approach!

3. **First-Class Functions 🎩**: Treating functions like superstars? You're on the right track!

4. **No Side Effects 🚀**: No external interference? Functional programming vibes, indeed!

5. **Recursion 🔄**: Looping with recursion? A nod to functional-style programming.

6. **Declarative Style 📝**: If the code emphasizes 'what' over 'how', you're heading in the functional direction.

7. **Immutable Data Structures 🏗️**: Immutable data structures and functional transformations? Welcome to the functional world!

Remember, many modern languages support functional-style features, even if they're not strictly functional. You can blend this paradigm with other approaches for cleaner, expressive, and maintainable code. 🤝

So, let's embrace the elegance of functional-style programming and make our code sing with beauty and clarity! 🎵💡

---

Let's keep the conversation going! Share your thoughts and experiences with functional-style programming in the comments below. Happy coding! 😊🚀

[LinkedIn](https://www.linkedin.com/in/kaushit/)
[More Posts](https://dev.to/kaushit)
Understanding Stream API - Embrace the Declarative Paradigm
Tags: java, programming, community, career
Published: 2023-08-05 04:32:18

I want to share my insights on how we can leverage the Stream API in Java to adopt a more declarative programming style, abstracting away the implementation details. Let's dive into what this paradigm shift means and how it can make our code more elegant and maintainable.

**Imperative Paradigm (The 'What' and 'How')**:
In the imperative paradigm, we tend to focus on 'what' we want to achieve and explicitly specify 'how' to achieve it through step-by-step instructions. This often involves using loops, conditions, and mutable state. While this approach works, it can lead to verbose code that is harder to read and maintain over time.

```java
// Example: Sum of even numbers in a list
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
int sum = 0;

for (int number : numbers) {
    if (number % 2 == 0) {
        sum += number;
    }
}
System.out.println("Sum of even numbers: " + sum);
```

**Declarative Paradigm (The 'What' and Abstracted 'How')**:
The Stream API allows us to embrace a more declarative approach. We focus on 'what' we want to achieve and let the API abstract away the 'how'. This results in concise and expressive code.

```java
// Example: Sum of even numbers in a list using Stream API
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
int sum = numbers.stream()
                .filter(number -> number % 2 == 0)
                .mapToInt(Integer::intValue)
                .sum();

System.out.println("Sum of even numbers: " + sum);
```

By leveraging the Stream API, we avoid the need for explicit loops and conditions. Instead, we chain functional operations to filter, transform, and process data declaratively. The code becomes more concise, expressive, and easier to comprehend.

**Advantages of Stream API**:
1. **Readability**: Stream API promotes a more descriptive and clear code style.
2. **Maintainability**: With a declarative approach, it's easier to understand and modify the code in the future.
3. **Parallelism**: Stream API enables easy parallelization for improved performance.

Let's strive to write code that expresses 'what' we want to achieve rather than 'how' to achieve it. Embrace the Stream API and enjoy coding with a more elegant and maintainable approach!

---

Feel free to share your thoughts and experiences with the Stream API in the comments. Happy coding! 😊🚀
400% productivity: Chat with your documents
Tags: webdev, beginners, programming, productivity
Published: 2023-08-05 03:30:00

## Cogniflow: Boost Productivity with AI-Powered Automation

**Introduction:**

[Cogniflow](https://www.aiforme.wiki/ai/tools/cogniflow) empowers you to harness the power of AI to boost productivity effortlessly. 

Chat with your documents, automate information extraction, or analyze images with no coding required. Save hours every week with our user-friendly platform and unleash the potential of AI for your business.

**Easy to Use:**

No AI or coding experience is needed. Simply follow a few easy steps to train custom models or utilize our pre-trained AI models, ready for immediate use.

**Auto Deploy for All AI Models:**

Connect any app or program to your AI models using our API-ready service. Alternatively, utilize our convenient add-ons for Excel or Google Sheets for seamless integration.

**Any Type of Data:**

Train and predict from text, image/video, or audio. Enjoy full native support for Spanish, Portuguese, and English languages.

**Use Cases:**

**Resume Parsing API:** Extract specific parts like education, experience, and certifications from CV documents, reducing processing time or creating standardized CV formats automatically.

**Chat with Your Docs:** Upload and process multiple documents to build a chatbot capable of answering any question. Easily embed it into any website or share a link.

**Speech to Text:** Transcribe client calls, check for compliance, identify sentiment, and highlight key parts of conversations with ease.

**Intention Classification API:** Perform sentiment analysis and classify customer reviews using your custom categories.

**Offensive Language Slack Bot:** Identify offensive language in channels, improving working environments and enhancing retention.

**Customer Support API:** Efficiently handle customer support with AI-driven automation.

**Powered by Latest GPT OpenAI Models:**

[Cogniflow](https://www.aiforme.wiki/ai/tools/cogniflow) leverages the latest GPT OpenAI models, ensuring accurate and powerful AI capabilities.

Run the Models from Excel Using Our Add-In:

Integrate AI capabilities into Excel, making data processing and analysis even more convenient.

**Conclusion:**

[Cogniflow](https://www.aiforme.wiki/ai/tools/cogniflow) is your go-to solution for AI-powered automation, simplifying tasks, and saving time. Benefit from easy-to-use AI models, auto-deployment features, and full support for various data types and languages. 

Unleash the potential of AI in your business without the need for technical expertise or coding. Transform productivity with [Cogniflow](https://www.aiforme.wiki/ai/tools/cogniflow) and revolutionize the way you work.
Nhà cái Dafabet - Điểm đến cá cược trực tuyến lý tưởng tại 1gombio.
Published: 2023-08-05 03:02:32

Dafabet, ngôi nhà cái giải trí trực tuyến dẫn đầu tại Châu Á, nổi danh với việc cung cấp đa dạng dịch vụ hấp dẫn như cược thể thao, casino trực tuyến, keno, xổ số và nhiều trò chơi khác.
Ra mắt từ năm 2004, Dafabet đã thu hút gần nửa triệu người chơi mỗi năm và ghi dấu ấn mạnh mẽ trong lĩnh vực cá cược Châu Á - Thái Bình Dương. Tận dụng sự quản lý của Tập đoàn AsianBGE và sự bảo hộ từ Chính phủ Curacao, Dafabet hoạt động hoàn toàn hợp pháp, đem đến môi trường cược trực tuyến an toàn và bảo mật.
Đặc biệt, Dafabet không chỉ nổi tiếng với việc thu hút lượng người chơi đăng ký mới hàng tháng, mà còn được biết đến với việc tài trợ các câu lạc bộ bóng đá quốc tế danh tiếng và hợp tác cùng các nhân vật nổi bật trong lĩnh vực thể thao như Jimmy White và Danny Morrison.

Xem chi tiết tại: https://1gom.bio/nha-cai-dafabet/ 

Trang liên quan: https://www.facebook.com/1gombioo/

#nhacaidafabet #1gom #1gombio
Tổ chức sự kiện khai trương Hải Phòng
Tags: tochuckhaitruonghp, tochucsukienkhaitruonghp, tochucsukien, haiphong
Published: 2023-08-05 02:23:46

Tổ chức sự kiện khai trương Hải Phòng - Với kinh nghiệm tổ chức sự kiện khai trương tại Hải Phòngcho các công ty tập đoàn và công ty lớn và miền khu vực miền Bắc, KhaiTruongHaiPhong sẽ mang lại cho quý công ty một sự kiện hoành tráng và trọn vẹn nhất.
Website: https://khaitruonghaiphong.vn/to-chuc-su-kien-khai-truong-cho-doanh-nghiep-hai-phong/
Trụ sở chính: BH 01 – 28 Vinhome Thượng Lý, Hồng Bàng, Hải Phòng
Chi Nhánh Quảng Ninh: Căn B162, Khu phố cổ Sunworld, Tp.Hạ Long, Quảng Ninh
Hotline:  +84 93 688 85 84
Hastag : #tochucsukien #tochucsukienkhaitruong #haiphong #tochuc #tochucteambuilding #teambuilding #teambuildinghaiphong #tochucsukienhaiphong #khaitruong #sankhaubongbay #tochucledongtho #tochuclekhanhthanh #chotheunhabat #chothuenhakhung #chotheumanhinhleg #cungcapmauPG #chotheuconghoi #chothueroihoi #tochucsukiengiare
Swap two variables without using third variable (Bitwise XOR)
Tags: javascript, programming
Published: 2023-08-05 00:34:21

There are multiple ways of swapping two variables without using third variable in programming. Using Bitwise XOR(^) is one of them. Suppose you have two variables a and b which values are respectively 50 and 100. And if you perform Bitwise XOR operation three times and assign the value respectively to a, b and a - you will find the swapped values which are a = 100 & b = 50.

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

Things will be more clear if you notice the truth table of Bitwise XOR(^):
<table>
  <thead>
    <tr>
      <th>X</th>
      <th>Y</th>
      <th>X ^ Y</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>0</td>
      <td>0</td>
      <td>0</td>
    </tr>
    <tr>
      <td>0</td>
      <td>1</td>
      <td>1</td>
    </tr>
    <tr>
      <td>1</td>
      <td>0</td>
      <td>1</td>
    </tr>
    <tr>
      <td>1</td>
      <td>1</td>
      <td>0</td>
    </tr>
  </tbody>
</table>

Let's do the operations in binary since machine understand only machine code/binary.

```
a = 50  (base 10) -> 0110010 (base 2)
b = 100 (base 10) -> 1100100 (base 2)

a =  a ^ b
     0110010 
     1100100
-------------
(XOR)1010110

b =  a ^ b
     1010110
     1100100
-------------
(XOR)0110010 [Equivalent to 50(base 10)]

a =  a ^ b
     1010110
     0110010
-------------
(XOR)1100100 [Equivalent to 100(base 10)]

Finally a = 100 and b = 50
```
To know more about Bitwise XOR, you can visit [the official documentation of MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_XOR)
NetDevOps in a nutshell
Tags: automation, devops, cloud, networking
Published: 2023-08-05 00:33:34

#
NetDevOps is a methodology that combines networking and software development practices to improve the efficiency and reliability of network infrastructure. It involves the use of automation tools and programming languages to manage and configure network devices and services.
NetDevOps aims to streamline network operations, reduce manual errors, and increase agility by treating network infrastructure as code. This means that network engineers can use programming languages to write scripts and automate routine tasks, such as device configuration and provisioning.
The key principles of NetDevOps include:
- Collaboration between network engineers and software developers
- Automation of network infrastructure using programming languages and tools
- Continuous integration and continuous delivery (CI/CD) of network changes
- Testing and validation of network changes before deployment.
By adopting NetDevOps practices, organizations can improve the speed and reliability of their network infrastructure, reduce costs, and increase overall efficiency.
NetDevOps useful learning resource 🔻

📶 NetDevOps: [https://lnkd.in/ejkKMQsi](https://lnkd.in/ejkKMQsi)
📶Python Network Automation: [https://lnkd.in/eMvsKriW](https://lnkd.in/eMvsKriW)
Python Programming for Network Engineers: [https://lnkd.in/evKVrHju](https://lnkd.in/evKVrHju)
📶 Cisco : [https://lnkd.in/ewZsHKvF](https://lnkd.in/ewZsHKvF)
📶 Python for NetDevOps : [https://lnkd.in/e5s3EDGN](https://lnkd.in/e5s3EDGN)
📶 Ansible for network automation : [https://lnkd.in/er4MU3Tw](https://lnkd.in/er4MU3Tw)
📶 Ansible network : [https://lnkd.in/em8aRPFj](https://lnkd.in/em8aRPFj)
📶 NetDevops on AWS cloud : [https://lnkd.in/erqFgNcH](https://lnkd.in/erqFgNcH)
📶 NetDevOps on Azure : [https://lnkd.in/eGzeFxd2](https://lnkd.in/eGzeFxd2)

#java #azure #azurecloud #azuredevop‍s‍‍ ‍ #DevOps #networkengineer #azure #aws ‍‍‍‍‍
#DevOpsCulture
#ContinuousIntegration
#ContinuousDelivery
#ContinuousDeployment
#InfrastructureAsCode
#Automation
#Containerization
#Kubernetes
#CloudNative
#Microservices
#Agile #DevSecOps #SiteReliabilityEngineering #GitOps
How to debug RDS database from a Kubernetes cluster
Tags: aws, kubernetes
Published: 2023-11-08 21:39:19

---
title: How to debug RDS database from a Kubernetes cluster
published: true
date: 2023-08-05 00:00:00 UTC
tags: ['AWS', 'Kubernetes']
canonical_url: https://blog.lepape.me/how-to-debug-rds-databases-from-a-kubernetes-cluster
---

When running Kubernetes workflows, most people tend to keep the stateless applications like applications on the cluster, and the stateful applications like databases outside of the cluster, on the same VPC. This is a good practice, but it makes debugging a bit more complicated.

> Note: I use AWS as an example, but this can be applied to any cloud provider with managed database & K8s using private networks

I assume your database is __private__ and only accessible from a VPC. Maybe for some obscure reasons, you still need to access this database to debug something (Staging database of course *cough cough*). Well, it might be a bit annoying. 

One way would be to spawn an EC2 instance inside the same VPC, install a bunch of tools like `netcat`, `mysql`, `postgres` and debug from the VM. Not very convenient, you might left resources running and it's not very reproducible.

What I would advise, is to use a "reverse-proxy" container inside your cluster. Being on the same VPC as your managed database, you will be able to access it, and this container port can be port-forwarded to your machine. Of course, all the following expect you to have enough privileges to create a pod inside your cluster.

```markdown
----------        -------        ------------
| Laptop |  <-->  | Pod |  <-->  | Database |
----------        -------        ------------
```

You will need 2 terminal windows:

- One to create the pod opening the connection to the database
- One to port-forward the pod port to your local machine

```bash
DB_PORT=5432
DB_HOST=64eddd8e4b61-postgresql.993191f72591.eu-central-1.rds.amazonaws.com

kubectl run psql-tunnel -it --image=alpine/socat --tty --rm --expose=true --port=$DB_PORT tcp-listen:$DB_PORT,fork,reuseaddr tcp-connect:$DB_HOST:$DB_PORT
```

Here is an explanation of each argument that might be useful to understand what is happening:

- `socat`: This image allows to establish two bidirectional byte streams and transfers data between them, perfect for our use case!
-  `--rm`: Removes the container automatically once it exits. (It helps in cleanup and avoids leaving unused containers.)
-  `tcp-listen:$DB_PORT,fork,reuseaddr`: Configures `socat` to listen on TCP port `5432` inside the container. The `fork` option allows handling multiple connections, and `reuseaddr` allows reusing the address.
-  `tcp-connect:$DB_HOST:$DB_PORT`: Specifies the destination address and port where the incoming connections to `5432` inside the container will be forwarded. It connects to the host `64eddd8e4b61-postgresql.993191f72591.eu-central-1.rds.amazonaws.com` on port `5432`.

and the second command to port-forward the container port to localhost:

```bash
kubectl port-forward psql-tunnel 54323:5432
```

You can now use any GUI to connect to the DB and visualize what is happening (TablePlus, DBeaver, PhpMyAdmin, etc)!