teleren/devto huggingface dataset:
Code Smell 201 - Nested Ternaries
Tags: webdev, javascript, beginners, programming
Published: 2023-03-14 23:53:13

*Arrow Code, Nested Conditions, switches, else, and many more*

> TL;DR: Don't use nested IFs or nested ternaries

# Problems

- Readability

- Default Case

# Solutions

1. Rewrite the code as an IF condition with an early return

# Context

Nesting is always a problem with complexity. 

We can fix it with polymorphism or early returns

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/45754a6d586d067627c4796748686384)

```javascript

const getUnits = secs => (
 secs <= 60       ? 'seconds' :
 secs <= 3600     ? 'minutes' :
 secs <= 86400    ? 'hours'   :
 secs <= 2592000  ? 'days'    :
 secs <= 31536000 ? 'months'  :
                    'years' 
)

```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/4ac913c6d842c4f0fc9d8e9998348335)

```javascript

const getUnits = secs => {
 if (secs <= 60) return 'seconds'; 
 if (secs <= 3_600) return 'minutes'; 
 if (secs <= 86_400) return 'hours';   
 if (secs <= 2_592_000) return 'days';    
 if (secs <= 31_536_000) return 'months';  
 return 'years' 
}

// More declarative

const getUnits = secs => {
 if (secs <= 60) return 'seconds'; 
 if (secs <= 60 * 60) return 'minutes'; 
 if (secs <= 24 * 60 * 60) return 'hours';   
 if (secs <= 30 * 24 * 60 * 60) return 'days';    
 if (secs <= 12 * 30 * 24 * 60 * 60) return 'months';  
 return 'years' 
}

```

# Detection

[X] Automatic 

Linters can detect this complexity using parsing trees.

# Tags

- IFs

# Conclusion

We must deal with [accidental complexity](https://dev.to/mcsee/coupling-the-one-and-only-software-design-problem-2pd7) to improve code readability.

# Relations

{% post https://dev.to/mcsee/code-smell-133-hardcoded-if-conditions-53bi %}

{% post https://dev.to/mcsee/code-smell-78-callback-hell-287f %}

{% post https://dev.to/mcsee/code-smell-102-arrow-code-4kfk %}
 
# Disclaimer

Code Smells are my [opinion](https://dev.to/mcsee/i-wrote-more-than-90-articles-on-2021-here-is-what-i-learned-1n3a).

# Credits

Photo by [NIKHIL](https://unsplash.com/@vinikhill) on [Unsplash](https://unsplash.com/photos/pThIEv416pE)
  
  * * *

> One of the best things to come out of the home computer revolution could be the general and widespread understanding of how severely limited logic really is.

*Frank Herbert*
 
{% post https://dev.to/mcsee/software-engineering-great-quotes-26ci %}

* * *

This article is part of the CodeSmell Series.

{% post https://dev.to/mcsee/how-to-find-the-stinky-parts-of-your-code-1dbc %}
Is Shopify Plus Worth It?
Tags: shopify
Published: 2023-03-14 23:26:13

Hi all, curious to get your thoughts on Shopify Plus... read a [Shopify Plus article](https://www.whitepeakdigital.com/blog/is-shopify-plus-worth-it/) about the pros and cons for $2,000/mo. Would you recommend it for high-growth merchants?
Monitor Persistent Volume usage in your cluster using kwatch
Tags: devops, kubernetes, monitoring
Published: 2023-03-14 23:23:23


In this tutorial, I will help you set up and deploy kwatch on your Kubernetes cluster to monitor Persistent Volumes (PV) usage and detect crashes in your running apps.

Plus, integrate with Teams to get notified on a channel when volume usage is higher than a threshold.

You can integrate with your favorite channel as [kwatch](https://github.com/abahmed/kwatch) supports integrations with (Slack, Discord, Email, PagerDuty, Telegram, Rocket Chat, Mattermost, Opsgenie, Matrix, DingTalk, FeiShu, And Custom webhook).

### Configure kwatch with Teams

**Step 1: Get webhook**

First of all, we need to get the webhook URL of the channel you want the notification to be received on it.
([Here](https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=dotnet#create-incoming-webhooks-1)
is how to get it)

**Step 2: Get Configuration**

Get the configuration template

```bash
curl  -L https://raw.githubusercontent.com/abahmed/kwatch/v0.8.3/deploy/config.yaml -o config.yaml
```

**Step 3: Edit config.yaml with the corresponding config**

```yaml
apiVersion: v1
kind: Namespace
metadata:
  name: kwatch
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: kwatch
  namespace: kwatch
data:
  config.yaml: |
    alert:
      teams:
        webhook: WEBHOOK_URL
    pvcMonitor:
      enabled: true
      interval: 5
      threshold: 70
```

For more configurations check [here](https://kwatch.dev/docs/pvc-monitor-configuration)

**Step 4: Apply Configuration**

```bash
kubectl apply -f config.yaml
```

### Deploy kwatch

Deploy kwatch on your cluster with one command

```bash
kubectl apply -f https://raw.githubusercontent.com/abahmed/kwatch/v0.8.3/deploy/deploy.yaml
```

After deploying you will get notified on the channel that kwatch has started
successfully. Now, kwatch is monitoring your volumes and apps!


![kwatch start message](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v2vsfq5z9i5r7bndfamq.png)

Here is an example of kwatch messages when volume usage exceeds the threshold


![kwatch detected issue](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b6aoar2e7xqaxuacsi8z.png)

*If you like kwatch, give it a star on [GitHub](https://github.com/abahmed/kwatch)!*

*We are happy to hear feedback from you and if you have any request, or suggestion don't hesitate to ping us on our channels ([Discord](https://discord.gg/kzJszdKmJ7), [GitHub](https://github.com/abahmed/kwatch))*
Update von abgelaufenen keys : was kann man hier im Allgemeinen machen!?
Published: 2023-03-14 22:54:58



 heute mal eine wichtige Frage ansprechen, mit der ich immer wieder zu tun hab - bei Upgrades /dates scheitert der Prozess gelegentlich. 

M.a.W: - ich laufe des öfteren in das Problem rein, dass ich die Updates nicht fahren kann weil ich ggf. 

a. zu lange gewartet hab oder 
b. irgendwelche keys expired sind.. 

ich muss mal nachsehen - ggf hilft  das hier. 

Daraufhin hab ich dann das mit diesem Versuch und Ansatz behoben (bei einem EndeavourOS): 


[code]
sudo pacman -Sy archlinux-keyring endeavouros-keyring
sudo pacman -Syu
[/code]


Hmm - sieht so aus als hätte ich hier dann auch praktisch Ruhe - und seitdem ich mit diesem Ansatz dort auf dem EndeavourOS - Notebook so verfahre scheint das updaten irgendwie problemloser.
Kann das sein dass dies ein allgemeiner Schlüssel zur Lösung eines allgem. Problems sein kann - denn ich hatte das m.E. auch schon bei anderen Linux-Systemen erlebt  - m.a.W. also auch dort (MX, OpenSuse) schon ähnliche Probleme mal bekommen kann mit den Keys !? 

hab mal versucht, herauszufinden was hier helfen kann  - und versucht mich in das Thema einzulesen: ps. ggf. kann [b]das hier helfen: [/b]


[b]How to solve an expired key (KEYEXPIRED) with apt[/b] 

Updating expired keys on Debian and Ubuntu: Software updates and package management is easy with systems based on Debian or Ubuntu. Just apt-get update (or apt update) and run an upgrade. But sometimes you may encounter the following situation: a KEYEXPIRED message.

vgl. [url]https://linux-audit.com/how-to-solve-an-expired-key-keyexpired-with-apt/[/url]

[quote]
[b]Step 1: Run apt-key[/b] Using the apt-key utility we can display all the known keys.

[code]apt-key list[/code]

[code]pub 2048R/7BD9BF62 2011-08-19 [expired: 2016-08-17]
uid nginx signing key <signing-key@nginx.com>[/code]

To quickly find the expired keys, search for “expired:”:

[code]apt-key list | grep “expired:”[/code]


[b]Step 2: Update the key[/b]
We can now use the key gathered in step 1 to update it:

[code]apt-key adv --keyserver keys.gnupg.net --recv-keys [KEY][/code]

The output might look like this:

[code]/etc/apt/trusted.gpg.d/nginx-development.gpg
——————————————–
pub 1024R/C300EE8C 2010-07-21
uid Launchpad Stable[/code]

As you can see in the output above, nothing happens when you select the wrong key.

[b]Step 3: Update[/b]
After renewing the expired key you can run apt update again and install any available upgrades.

[code]apt update && apt upgrade[/code]

[/quote]


Was meint Ihr denn - könnte das ein Weg, ein Verfahren sein, dem Thema "expired-keys" allgemein abzuhelfen!?

Wie gesagt  - ich laufe des öfteren in das Problem rein, dass ich die Updates nicht fahren kann weil ich ggf. 

a. zu lange gewartet hab oder 
b. irgendwelche keys expired sind.. 


Wenn ich weiß wie ich damit umgehen kann /& soll. dann bin ich auf alle Fälle weiter. 

Freue mich über eine Rückmeldung

Viele Grüße
PostgreSQL SELECT STATEMENT.
Tags: sql, postgres, database, webdev
Published: 2023-03-14 22:43:13

## How to use the PostgreSQL `SELECT` statement.

In this short tutorial, you are going to learn how to use the Postgres `SELECT` statement to query the database and retrieve information from a table.

The Postgres `SELECT` statement is one of the most used queries in SQL, it is used to retrieve data from tables. It is part of the queries used to perform CRUD (Create, Read, Update, Delete) operations in SQL. The `SELECT` statement is the READ in the CRUD operations, since it is used to read or retrieve data.

Let's see an example of how to use `SELECT`. 
The following shows an example on how to use `SELECT`:

```
SELECT list_name FROM table_name;
```
Now, let's break it down:

- First, specify a list, can be a column or list of columns from the table you want to query.

- Ensure that the data you want to retrieve exists in the table.

- If you are selecting multiple columns, you need to use comma `,` after each column name.

- Use the asterisk `*` shorthand to retrieve all the columns from a table (not a good practice).

- The `FROM` clause specifies the table you want to select from.

- And finally, the table name, which is the name of the table you want to select from. 

**NOTE**: In PostgreSQL, the semicolon at the end of the `table name` is not optional. If you skip the semicolon, Postgres will throw an error.

**Conclusion:** In this short tutorial, you have learned how to use the PostgreSQL `SELECT` to query a database and retrieve information from a table.
Quit Tracker
Tags: python, flask, javascript, beginners
Published: 2023-03-14 22:33:03

It is very important to hold on to something for motivation after quitting smoking, and contrary to popular belief, quitting smoking is pretty easy if you have a determined mindset.
With this application, you will be able to follow the money and life you do not spend without smoking and you'll be more motivated as you see the steps to success. Good luck everyone 🙏🙏


![Stats1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n384llx7a648ek8hltut.png)

![Stats2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xvrmp1qzncftj6zutg5m.png)
Cleaning your Xcode's garbage
Tags: ios, xcode, productivity, tooling
Published: 2023-03-14 22:22:29


Mobile devs out there with 128 or 256Gb SSDs Macbook: Hear me out!
If you find yourself struggling with the available free space on your disk, like Xcode not building or Terminal commands failing. All these happen because they can't write files to the SSD.
The good news are, I have a great solution for you:

[Xcode-clean script](https://github.com/niklasberglund/xcode-clean.sh)
_Shout out to Niklas Berglund_

I found this script many years ago and I still use it, even when I am currently working on a 512Gb Macbook Pro.

Of course there are several less technical alternatives to do this, like cleaner apps, cache cleaning tools, etc. 
But for some reason I tend to go with the nerdiest solutions.

For convenience you can create an alias like I did. Add the following line to your bash profile, oh-my-zsh, or whatever shell you use:

`alias cleanxcode='~/xcode-clean.sh/./xcode-clean.sh'`

Then, you can use it like:
`> cleanxcode --help`

Output:

```
Usage: /Users/.../xcode-clean.sh/./xcode-clean.sh [options]

Frees up disk space by removing Xcode data. NOTE: you might want to keep backups of the dSYM files in ~/Library/Developer/Xcode/Archives

EXAMPLE:
    /Users/.../xcode-clean.sh/./xcode-clean.sh -A

OPTIONS:
   -h           Show this help message
   -b [path]    Backup dSYM files to specified path before removing archives
   -a           Removed all Xcode archives
   -d           Remove everything in DerivedData folder
   -D           Remove everything in DeviceSupport folder
   -s           Remove simulator data
   -A           Remove all of the above(archived, DerivedData and simulator data)
   --dry-run    Dry run mode prints which directories would be cleared but don't remove any files
```

A common use case for me is:
`> cleanxcode -a -d -s`

It wiped out a total of 9Gb this time 👍🏻

```
Clearing archives in /Users/.../Library/Developer/Xcode/Archives/* (freeing 25M disk space)
Clearing DerivedData content in /Users/.../Library/Developer/Xcode/DerivedData/* (freeing 7.6G disk space)
Clearing simulator data in /Users/.../Library/Developer/CoreSimulator/Devices/* (freeing 1.4G disk space)
```

That is all for today.
I hope you find it as useful as I do.
S3A on Spark 3.3 in 2023
Published: 2023-04-29 21:22:07

---
title: S3A on Spark 3.3 in 2023
published: true
date: 2023-03-14 22:07:58 UTC
tags: 
canonical_url: https://mikestaszel.com/2023/03/14/spark-hadoopawsjarawsjavasdkbundlejar.html
---

Updating my post from almost 3 years ago! The world has moved on to Spark 3.3, and so have the necessary JARs you will need to access S3 from Spark.

Run these commands to download JARs for Spark 3.3.2:

```
wget https://repo1.maven.org/maven2/com/amazonaws/aws-java-sdk-bundle/1.12.426/aws-java-sdk-bundle-1.12.426.jar -P $SPARK_HOME/jars/
wget https://repo1.maven.org/maven2/org/apache/hadoop/hadoop-aws/3.3.2/hadoop-aws-3.3.2.jar -P $SPARK_HOME/jars/

```

That’s all there is to it. The `s3a://` prefix should work now for reading and writing data using Spark 3.3.2.
How to build a Container Native DevOps process?
Tags: devops, docker, containers, native
Published: 2023-03-14 22:07:40


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

Building a container-native DevOps process involves a number of key steps:

**1. Containerization of Apps**
Containerization is a technology that allows developers to package and deploy applications and their dependencies in a lightweight, portable container. Containers provide an isolated and consistent runtime environment for applications to run in, regardless of the underlying infrastructure.

Containerization allows developers to package their application code, along with any required libraries and dependencies, into a container image. This container image can then be deployed on any environment that supports containers, such as a local development machine, a cloud-based container orchestration platform, or a server in a data center. Containers are lightweight and portable, making it easy to move applications between environments, scale them up or down as needed, and deploy them quickly and reliably.

**2. Use infrastructure as code:** Infrastructure as code (IaC) is a key component of a container-native DevOps process. It allows you to define your infrastructure and deployment processes as code, making it easier to manage and version control your infrastructure. Tools like Terraform or CloudFormation can be used to implement IaC.

**3. Choose a container orchestration platform:** A container orchestration platform is necessary to manage the deployment and scaling of containerized applications. Kubernetes is a popular choice for container orchestration, but other options like Docker Swarm or Amazon ECS can also be considered depending on your requirements.

**4. Implement continuous integration and continuous deployment (CI/CD):** A container-native DevOps process requires a robust CI/CD pipeline to automate the build, test, and deployment of containerized applications. This pipeline should include automated testing and validation to ensure that the containerized applications are functioning correctly before being deployed to production.

**5. Implement security best practices:** Security is an important consideration in any DevOps process, and container-native DevOps is no exception. It's important to follow security best practices for container images, such as using trusted base images and scanning images for vulnerabilities.

**6. Implement monitoring and logging:** Monitoring and logging are critical to understanding the health and performance of your containerized applications. Tools like Prometheus or Grafana can be used to monitor your containers and generate real-time alerts when issues arise.

[RazorOps team](https://razorops.com/) can help design and implement production ready container native devops. 

**[TRY our FREE Forever Container Native CICD](https://razorops.com/)** 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xt2ldij7fn95iqj4aa9i.png)
Dockerize full stack React app
Published: 2023-03-14 22:06:13

This is the structure of my app

```
my-app
|_server
|__client
```
We need to create separate Dockerfile for client and server app. I also used a postgresql database hence we need to set it up.  

In the client, create a file called Dockerfile 
```
FROM node:16

WORKDIR /usr/app

COPY package*.json ./

RUN npm ci -qy
RUN npm run build

COPY . .

EXPOSE 3000
```

Next step is to build the image and push it to Dockerhub. 
Run the following commands 

```
docker build . -t username/my-app-react
docker push username/my-app-react
```
Navigate to server folder, create another Dockerfile with the following content

```
FROM node:16
WORKDIR /usr/src/app

COPY package*.json ./

RUN npm ci --only=production
COPY . .
EXPOSE 8800
CMD [ "node", "server.js" ]
```

Repeat the step to build and push the image 

```
docker build . -t username/my-app-api
docker push username/my-app-api
```

Now we need a docker-compose file to define and tell docker to launch all the necessary services for our full stack app, including the database.

Navigate to the root directory, in my case it was the server folder, create a `docker-compose.yml` file, add the following

```
version: '3.8'
services:
  pgdatabase:
    image: postgres:14.1-alpine
    restart: unless-stopped
    env_file: ./.env.development
    ports:
      - '5432:5432'
    volumes: 
      - db:/var/lib/postgresql/data
  backend:
    depends_on:
      - pgdatabase
    image: "username/my-app-api"
    env_file:
        "./.env.development"
    build:
      context: ./
      dockerfile: ./Dockerfile
    ports:
      - "8800:8800"
  frontend:
    depends_on:
      - backend
    image: "username/my-app-react"
    env_file:
        "./social-app-client/.env"
    build:
      context: ./client
      dockerfile: ./Dockerfile
    ports:
      - "3000:3000"
    links:
      - "backend:be"
volumes: 
  db:
```

From the server folder, start up docker-compose 

```
docker-compose -f docker-compose.yml up
```
Block ads with Pi-hole and Kubernetes
Tags: raspberrypi, kubernetes, pihole, homelab
Published: 2023-03-14 21:49:35

While there are browser extensions and apps you can use to block ads on your desktop and mobile, they require installing them individually on each of your devices. And that's assuming there's an app available for the device and OS in question. 

Wouldn't it be better to also block ads at the router level? All those smart TVs, set-top boxes, game consoles, VR headsets, smart speakers, smart thermostats, robot vacuums, security cameras, doorbells, and other IoT devices love chatting with metrics/ad services. Let's put a stop to that by deploying a DNS server that will block requests to known ad servers.

[Raspberry Pi](https://www.raspberrypi.com/products/raspberry-pi-4-model-b/) is a tiny computer you can use as a desktop, smart home hub, robot brains, media center, and more. If you have been thinking about setting up a homelab, a Raspberry Pi is a great place to start at an extremely low cost. They are in high demand but [this site](https://rpilocator.com) can help you find one.

[MicroK8s](https://microk8s.io) is a lightweight distribution of Kubernetes (K8s) for container orchestration. We'll also use [Helm](https://helm.sh), a package manager for K8s, for easy deployment.

[Pi-hole](https://docs.pi-hole.net) is a DNS sinkhole that protects your devices from unwanted content, without installing any client-side software. It's installed in one place and blocks ads for your entire home network. 

When you're done you'll have an admin interface for all your K8s workloads:
![k8s](https://i.imgur.com/Gb4C6py.jpg)

And another for your Pi-hole stats:
![pi-hole](https://i.imgur.com/0EDMcjL.jpg)

Let's get started! All the details are here:
{% embed https://github.com/santisbon/pi-hole-k8s %}
Day 713 : Unstoppable
Tags: hiphop, code, coding, lifelongdev
Published: 2023-03-14 21:45:00

_liner notes_:
- Professional : Not a bad day. Had a meeting with my manager to talk about some upcoming projects. Got to show them how far I've gotten on the proof of concept demo I've been working on. He likes where it's going. Cool. Unfortunately, I ran into an issue where I think Astro is affecting my Web Components. I have a work around where everything is working, but it's not fully how I want. Going to work on it some more and see what I can come up with. I also got the flight and hotel booked for my work trip next month.

- Personal : Last night I went through some tracks for the radio show. Did some coding. Then I watched "Vinland Saga" and "Spy x Family" before going to bed.

![Aerial view of Plougonvelin, France coastline with different color patches of land under some sparse puffy clouds next to a vast ocean](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yvoyco4y465cy2hbzqnc.jpg)

I think I may have thought of a way to get my Web Components to work in Astro the way I want. Going to mess around with it later tonight. My desire to make this work is unstoppable! haha I want to work on the radio show. Then watch "Spy x Family" before I go to bed. Oh, and my laptop came back from the manufacturer today! They replaced the battery and everything seems to be working fine so far. Since they replaced the battery, it looks like the memory was wiped. It turned on like it was a brand new laptop with the initial setup process. A good thing about Chromebooks is that I just logged into my accounts and my applications and files in the cloud loaded. 

Have a great night!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube -JJ7PLXOvL4 %}
Introducing: an open source warm up generator
Tags: githubactions, python
Published: 2023-03-14 21:38:41

Here is a link to my project: https://github.com/vikadilly/warmupbot

Are you tired of sitting down to do creative work and struggling to get started? Do you wish you had a way to warm up your mind and get your creative juices flowing? Look no further than the Warm Up Bot! With Github Actions and a CSV file, you can generate a personalized list of warm-up exercises to execute every day.

It's entirely hosted on Github and honestly, it's been super helpful for me to just... get started so I am happy to show everyone this :)