teleren/devto huggingface dataset:
Python print with line number and variable name
Tags: python, django, debugging, flask
Published: 2022-12-15 12:01:28

Sometimes you want to print something to the console (without breakpoints setup).

```
hello = "world"
print(hello)
>>> world
```

While the program is small, there are no problems with this. Let's assume that you have started working with some class with ~ 3000 lines (legacy code) and you need to quickly look at any values. The number of "prints" increases, and it becomes not easy to understand from the first time which "print" refers to which variable. You can of course write like this.

```
print('hello=', hello)
```

Yes, that's better. But I would still like to see both the line number and the type of variable. And in some cases, the path to the file.

For such cases, I have written a small (and very useful) utility that will make your life easier. Let's try to install it.

```
pip install simple-print
```

And print something.

```
from simple_print, import sprint

master = "yoda"

# Print the variable name with the line number
sprint(master) 

# Add blue paint
sprint(master, c="blue") 

# Add a white background
sprint(master, c="blue", b="on_white") 

# Add underline
sprint(master, c="blue", b="on_white", a="underline") 

# ADD the path to
sprint(master, c="blue", b="on_white", a="underline", p=True)

# Return as a string
s = sprint(master, s=True)
```


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

And of course you can use indents for debugging in forloops:

```
def test_indent():

    fruits = ["lemon", "orange", "banana"]
    sprint(fruits, c="green")
    
    for fruit in fruits:
        sprint(fruit, c="yellow", i=4)

```

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

The source code can be viewed here https://github.com/Sobolev5/simple-print

Productive development for you. Thanks for reading.
How to Debug Code (Without Crying)
Tags: beginners, programming, webdev, codenewbie
Published: 2022-12-15 11:56:20


![Debugging code is harder than writing it](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8romvxx8zq4yf21uxxmp.png)

Debugging code is an essential developer skill.

Use these 5 effective techniques to level up your debugging game.

Let’s go! 🚀

## TL;DR

- [Narrow down bug scope 🎯](#narrow-down-bug-scope)
- [Use debugging tools ⚒️](#use-debugging-tools)
- [Write test for the bug 🧪](#write-test-for-the-bug)
- [Use rubber duck strategy 🦆](#use-rubber-duck-strategy)
- [Take a walk 🚶](#take-a-walk)

## Narrow down bug scope 🎯

First, identify cases for which the issue occurs.

Then, you can analyze corresponding defective code.

Navigating whole code base for fixing a bug is:
- ineffective
- tiring
- time consuming

Localize the bug *before* fixing it.

## Use debugging tools ⚒️

Spend some time learning about:
- Debugger
- Chrome Devtools
- API verification tools
- Analyzing heap dumps
- Packet sniffing tools

You don’t need to learn all of them.

Only the ones that are useful for your stack.

Find what works. Use them often.

## Write test for the bug 🧪

Every bug is a failing test case. 

Use tests to:
- reproduce the issue
- verify the fix

Remember: 
Test >> Bug documentation

They prevent future appearance of the bug.

## Use rubber duck strategy 🦆

It’s a fancy term for “Thinking out loud”.

Idea is to explain your code line by line to a rubber duck.

It forces you to come out of the perspective that introduced bugs in the first place.

Also, the tip works with pets too :)

## Take a walk 🚶

While debugging you will get stuck.

A lot!

So limit the time spent in a session.

After that, take a break.

Let your mind wander.

Clear your head and come back later.

This tip works best for me.

## Wrapping up 📝

That’s it. 

Hope these tips will help you in debugging your code.

Share in comments your best debugging tip.

If you liked this post, follow me for more of these 🙂
How to build a piano with only HTML, CSS, Javascript ?
Tags: javascript, webdev, beginners, tutorial
Published: 2022-12-15 11:54:36

In this post, we’ll learn how to build [this piano](https://javascript-piano-lotfijb.netlify.app) from scratch using simple HTML, CSS, and JavaScript.

Firstly, we’ll structure our web app using HTML. We’ll use the main tag to make a wrapper structure for the piano.

We will create classes to show white and black keys, and classes will be further used in CSS for designing.

I added a class empty to some black keys because we don't need the same amount of white keys and I tried to do it the simple way.

In script.js, I grabbed all keys with className to make an array of all keys and created an array of sounds.

I, then, iterated through every single element of array keys and added a click event to play a random sound.

I, also, created a play() function to play a random sound on every keyboard button press on body element (I don't recommend that but I wanted to make it simple).

I created a sounds folder where I stored 21 different sounds of piano keys.

## index.html
![HTML](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x8qju1wrknh426chh6en.png)

## style.css ( click to zoom )
![CSS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9196a4jg6rna5c89r9e8.png)

## script.js
![JS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ptfpfqkuaiamqrsjukb6.png)

NOTE : 
There is room for improvement and this is only for beginners who just started as it covers simple concepts.
Switching between multiple versions of various tools
Tags: terraform, jdk, node
Published: 2022-12-15 11:48:55

I'm sure you've worked on different projects that used different versions of tools despite having the same technology stack. Whether you work as a frontend dev, backend dev, or DevOps, this problem can happen anywhere. Switching between versions of various tools can be tricky and painful. In this article, I decided to put together tools that will help reduce this pain.
I googled how to do it whenever I needed to switch between versions. This article I'll treat as a private cheat sheet. If you use the following tools on a daily basis, I encourage you to save this post and treat it as I do.

---

### Switching Terraform version - [tfenv](https://github.com/tfutils/tfenv)

#### Installation

```bash
# Mac OS
brew install tfenv
```

#### Basic commands

```bash
# list all installed terraform versions
tfenv list

# list all available terraform versions for installation
tfenv list-remote

# install selected terraform version
tfenv install 1.3.6

# switch to installed terraform version
tfenv use 1.3.6

# print currently set terraform version
tfenv version-name

# uninstall selected terraform version
tfenv uninstall 1.0.11
```

---


### Switching Java, Maven, and Gradle version  - [sdkman](https://github.com/sdkman/sdkman-cli)

#### Installation

```bash
curl -s https://get.sdkman.io | bash
source ~/.bash_profile
```

#### Basic commands

```bash
# list all installed and installable versions
sdk list java
sdk list maven
sdk list gradle

# install selected version
sdk install java 17.0.5-zulu
sdk install maven 3.8.6
sdk install gradle 7.6

# switch to installed version
sdk use java 17.0.5-zulu
sdk use maven 3.8.6
sdk use gradle 7.6

# print currently set version
sdk current java
sdk current maven
sdk current gradle

# uninstall selected version
sdk uninstall java 8.0.352-zulu
sdk uninstall maven 3.6.0
sdk uninstall gradle 7.4

# list all tools whose versions sdkman can manage
sdk list
```
---

### Switching Node & npm version - [nvm](https://github.com/nvm-sh/nvm)

#### Installation

```bash
# Mac OS
brew install nvm
mkdir ~/.nvm

# support for Oh My ZSH
echo "export NVM_DIR=~/.nvm\nsource \$(brew --prefix nvm)/nvm.sh" >> ~/.zshrc
source ~/.zshrc
```

#### Basic commands

```bash
# list all installed node versions
nvm ls

# list all available node versions for installation
nvm ls-remote

# install selected node version and switch to them
nvm install v19.2.0

# install latest LTS node version
nvm install --lts

# switch to installed node version
nvm use v19.2.0

# print currently set node version
nvm current

# uninstall selected node version
nvm uninstall v10.15.3
```

---


I will expand this article when I discover other tools this type. If you use any other version management tools, please let me know in the comment, I'd be happy to take a look.
Is there a way in Argocd to set shelf-life for application
Tags: argocd, kubernetes
Published: 2022-12-15 11:48:52

Is there a way in argocd using which I can set a shelf life for my applications. Such that when shelf life has expired the application will automatically gets removed from the cluster.

I need this use-case for the dev/test environments where I want to provide my developers a way to directly deploy using their PR's so that they all can have their isolated deployments over Kubernetes. But at the same time I also want to optimise on costing side such that these deployments from feature branches get automatically pruned after some time(lets say 7 days).

The manual way of doing it will be write a python script which will delete all application which are older than 7 days. but here I will have to handle multiple things out of the box. I am looking for some argocd native solution.
What to Monitor in a Website
Tags: webdev, monitoring, devops, cloud
Published: 2022-12-15 11:30:42


## The Conundrum of Monitoring 

So you put up your website in the cloud, and your hosting company, cloud providers, and all sorts of people offer you to monitor your website. 

## Launching A Platform

Now that I am approaching the launch of my platform for auction events for creators, I am putting it up in the cloud. So I need to create a server where the platform will run. Having done that, I encountered so many options to monitor it.

Despite having twenty-five years of industrial experience, I still found my head swirling from all these offers. In all the IT companies I worked for, we had a DevOps or infrastructure team to monitor whatever we needed.

So I had to make some order in my thoughts. For this purpose, I created the drawing you see at the top of this article. 

## The Web Application and the Scheduler

We have a web application, a website with screens, and a database. For any platform, there are some jobs that we need to do every day, every week, or every month. Such jobs include sending monthly invoices. Thus, we need a scheduler to run these jobs at the required frequency.

## What Should We Monitor

### Uptime

We want to know that the website is up and running. This is called **uptime**. The uptime monitor has to run outside the server and the platform. Because otherwise, you would not know that your server is down. 

### Resources 

Websites and servers can get overloaded, either temporarily or permanently. Temporary spikes can be due to particular days of the year, like the holiday shopping season. Permanent overload points to the need to increase the resources available. 

Resource monitors require some agent to be attached to your website to report the CPU, memory, or disk load. The resource monitor can reside inside or outside the server. In many cases, you will use both. An internal monitor is cheaper but can be clogged down in overload. 

### Periodic Jobs

Did the jobs run on time? Were they successfully executed?

You can record somewhere on the server whether the job is finished. But you must monitor outside the server to see if a job was successfully executed. The reason is that if the job did not run, no one inside could tell you that. Maybe the scheduler is dead.

So each regular job has to report to an outside monitor on its execution. And the monitor that has a list of jobs and frequencies can compare these reports to what happened and alert you for any malfunction.

## An External Scheduler

Due to all the complications of scheduling and monitoring, numerous companies offer to schedule jobs for you by calling some endpoint (function) in your platform. Such offers are often named **cron** something - reminiscent of the Linux *cron* scheduler. 

## Conclusion

I hope that now you can better sort all the different options for monitoring and make a cost-effective choice.
Day #14: My 3 simple side hustles ideas to get some passive income
Tags: passiveincome, startup, webdev, product
Published: 2022-12-15 11:28:54

[I’m a tech leader engineer that got laid off recently and so I decided to initiate some small sources of income while I’m looking for a new job.
Here is my current list of passive income (but I will create more in the coming months).](https://medium.com/@journeypreneur/day-14-my-3-simple-side-hustles-ideas-to-get-some-passive-income-6bf375b2d998)
Learning to code for beginners
Published: 2022-12-15 11:24:45

Learning to code can be a rewarding and challenging experience. With the right resources and mindset, anyone can learn how to program and create their own software, websites, and applications.

If you are new to coding, the first step is to choose a programming language to learn. There are many popular languages to choose from, each with their own strengths and uses. Some popular options for beginners include Python, JavaScript, and Java.

Once you have chosen a language, it's time to start learning the basics. There are many online resources, tutorials, and courses that can help you get started. Some popular options include Codecademy, Khan Academy, and Coursera.

In addition to online resources, there are also many books and guides that can help you learn to code. These can be a great way to supplement your online learning and help you understand the concepts in more depth. Some popular books for beginners include "Learn Python the Hard Way" and "JavaScript for Beginners".

As you learn the basics of your chosen language, it's important to practice and apply what you have learned. This can help you develop your skills and build your confidence. One way to do this is by completing coding challenges and exercises on sites like HackerRank and Code Wars.

Another way to practice and learn is by working on small projects. This can be anything from a simple program that prints "Hello, World!" to a more complex application or website. As you work on your projects, you will learn new concepts and techniques, and you can also share your work with others to get feedback and help.

Learning to code can be a rewarding and challenging journey. With the right resources and mindset, you can learn the skills you need to create your own software and applications. Whether you want to build your own website, create a new app, or just learn more about how computers work, learning to code can open up new opportunities and possibilities.
How to Deploy a React App
Tags: react, netlify, beginners
Published: 2022-12-15 10:47:45

If you are a beginner in react and watched a couple of tutorials on the internet then you probably built some projects to showcase. So what will be the next step? Yeah, absolutely, you are right! We need to deploy it on the internet so that everyone can have a look at your project. 

Before deploying, I just want to give you some advice: try adding some additional features or tweaking the UI of your project, don't just deploy it as-is. If you're feeling adventurous, try building the same project without watching the tutorial. Although, You can refer to some parts for guidance.

Okay now, let’s deploy it to a hosting provider. I am using Netlify here. There is also another hosting provider to deploy your react app. let’s focus on Netlify here. 

Create an account in Netlify using GitHub and create a team. Click Add new site and select ‘Import an existing project’. Then you should select the repository to import.  after that, you can see some settings for your project. below like this:

![netlify react app deploy page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/emejyydtrx463mgavppj.png)

You don’t need to do anything here. Just click “**Deploy site**”.

Ta-da! Your react app will be deployed soon and you can see the link in your project overview.
How NullPointerException can be avoided in Java
Tags: java, null, exception, beginners
Published: 2022-12-15 10:30:00

A NullPointerException is a common runtime error in Java that occurs when an application attempts to use a null object reference. This can happen when a variable that is supposed to reference an object is not initialized or is set to null, and the code attempts to call a method or access a field on the uninitialized object.

To avoid NullPointerExceptions in your Java code, you can follow these tips:

- 
Always initialize your object references to a non-null value, such as a default object or an empty collection, before using them in your code. This will ensure that your object references are always pointing to a valid object, and will prevent the NullPointerException from occurring.

```java
List<String> list = new ArrayList<>(); 
// initialize list to an empty ArrayList
```

- 
Use the `null` keyword only when you explicitly want to represent a null value, and avoid using it as a default value for object references. Instead, use a default object or an empty collection, as shown above.


- 
Use the `Optional` class to represent optional values, rather than using null directly. The `Optional` class allows you to safely access the value inside the optional without the risk of a NullPointerException, and provides methods for handling the case when the optional is empty.

```java
Optional<String> optional = Optional.ofNullable(str); 
// create an Optional from a potentially null value
```

- 
Use the `requireNonNull` method to validate that an object reference is non-null before using it. This method will throw a `NullPointerException` if the object is null, which can help you identify and fix null references in your code.

```java
String str = requireNonNull(inputString); 
// throw a NullPointerException if inputString is null
```

By following these tips, you can avoid NullPointerExceptions and write safer and more reliable Java code.

Happy Coding !!

{% embed https://youtu.be/W3d9uvTu7Wc %}
Remote jobs paying $100K+ - RevampedCP
Tags: career
Published: 2022-12-15 10:22:42

####   Original Tweet From  [@RevampedCP](https://twitter.com/RevampedCP)
{% embed https://twitter.com/RevampedCP/status/1602732838062882817 %}
Remote jobs paying $100K+

#### 🏙 Company: [@AlightSolutions](https://twitter.com/AlightSolutions) 
💰 Salary: $111K 
🔗 Link to apply: 
 https://careers.alight.com/us/en/job/ALIGUSR19454EXTERNALENUS

####  🏙 Company: [@DocuSign](https://twitter.com/DocuSign) 
💰 Salary: $105K - $154K 
🔗 Link to apply:https://careers.docusign.com/jobs/20878?lang=en-us&iis=Job+board&iisn=LinkedIn

AdSpace Here!!


#####  🏙️ Company: [@ingenovishealth](https://twitter.com/ingenovishealth) 
💰 Salary: $104K - $130K
🔗 Link to apply: 
https://ingenovishealth.wd1.myworkdayjobs.com/Ingenovishealth/job/Remote/Senior-Project-Manager_JR223?source=Linkedin

####  🏙 Company: [@FanDuel](https://twitter.com/FanDuel) 
💰 Salary: $126K - $165K 
🔗 Link to apply: https://boards.greenhouse.io/fanduel/jobs/4731015?gh_src=ba823b7b1us 
AdSpace Here!!


#### 🏙 Company: [@Airbnb](https://twitter.com/Airbnb) 
💰 Salary: $130K+ 
🔗 Link to apply: 
 https://careers.airbnb.com/positions/4733092&gh_src=34ewj2/

#### 🏙 Company: [@RobinhoodApp](https://twitter.com/RobinhoodApp) 
💰 Salary: $120K+ 
🔗 Link to apply: https://boards.greenhouse.io/robinhood/jobs/4723398?t=gh_src%3D&gh_jid=4723398&gh_src=ed898e781us&source=LinkedIn

#### 🏙 Company: [@Google](https://twitter.com/Google) 
💰 Salary: $103K - $157K 
🔗 Link to apply: https://careers.google.com/jobs/results/129318170453254854-policy-enforcement-manager-youtube-scaled-abuse-and-monetization/
AdSpace Here!!


#### 🏙 Company: [@zillow](https://twitter.com/zillow) 
💰 Salary: $125K+ 
🔗 Link to apply:  https://zillowgroup.eightfold.ai/careers/job/240532792601?domain=zillowgroup.com 


Click [Here](https://www.knowledge-twitter.com/?utm_source=dev.to)  For More Posts Like This [https://www.knowledge-twitter.com](https://www.knowledge-twitter.com/?utm_source=dev.to)
Node_exporter and vmstat statistics
Tags: linux, performance, monitoring
Published: 2022-12-15 10:21:17

[Node_exporter](https://github.com/prometheus/node_exporter) is a monitoring agent that has become the standard agent in lots of environments and especially in the cloud, because of flexibility, ease of use and integration with [prometheus](https://github.com/prometheus/prometheus).

One of the statistic sources which is collected by node_exporter is the vmstat source. This is called the 'vmstat collector' by node_exporter, and it exports the linux `/proc/vmstat` file statistics. 

However, that is not the full story. I was looking for some specific vmstat statistics in the node exporter, and couldn't find these. The specific statistics I was looking for were 'allocstall*', 'pgscan*' and 'pgsteal*'. Because I was pretty sure these exist, I then gone to the linux system and looked in the `/proc/vmstat` file. And there they were... That begs the question: what is going on?

It turns out that for each specific collector, there is a default setting which turns it on or off. Most collectors are turned on, some are turned off by default, such as collector.perf, collector.ntp, collector.cgroups to name a few.

On top of the enable or disable switch, some of the collectors have one or more configuration options. One of these is, you probably guessed it by now, the vmstat collector, or `collector.vmstat`, for which the configuration switch is aptly named `collector.vmstat.fields`, which makes it obvious that only certain fields can be selected.

The `collector.vmstat.fields` setting with node_exporter version 1.5.0 is: `^(oom_kill|pgpg|pswp|pg.*fault).*`. For those of you that speak regex, this makes it obvious: this does NOT include the statistics that I was searching for above, and the reason is this regex that filters only very specific fields.

To enable additional fields to be shown/exporter by node exporter, add the `--collector.vmstat.fields` flag to the startup command of node exporter, and set the regex to include the additional fields: `--collector.vmstat.fields="^(oom_kill|pgpg|pswp|pg.*fault|pgscan|pgsteal|allocstall).*"`