teleren/devto huggingface dataset:
Docker-compose cheat sheet
Tags: docker, cheatsheet, devops
Published: 2024-01-16 15:19:09

A cheat sheet to create you docker-compose.yml `version: '3.8'`

## Build the image

```yaml
web:
  # build from Dockerfile
  build: .
  # alternative to use a folder with more than one Dockerfile:
  build:
    context: ./dir # path to Dockerfile
    dockerfile: Dockerfile.dev #name of the file
    target: dev # specify the target in a multi-stage build
  # build from image
  image: ubuntu
  image: ubuntu:14.04
```
## Init
Run the service as PID 1. Set this option to true to enable this feature for the service.
```yaml
services:
  web:
    image: alpine:latest
    init: true
```

## Expose port

```yaml
ports:
  - "3000"
  - "8000:80"  # guest:host
# expose ports to linked services (not to host)
expose: ["3000"]
```

### Commands and Entrypoint

```yaml
# command to execute
command: bundle exec thin -p 3000
command: [bundle, exec, thin, -p, 3000]

# override the entrypoint
entrypoint: /app/start.sh
entrypoint: [php, -d, vendor/bin/phpunit]
```

### Environment variables

```yaml
# environment vars
environment:
  RACK_ENV: development
environment:
  - RACK_ENV=development

# environment vars from file
env_file: .env
env_file: [.env, .development.env]
```

## Health check

```yaml
# declare service healthy when `test` command succeed
healthcheck:
  test: ["CMD", "curl", "-f", "http://localhost"]
  interval: 1m30s
  timeout: 10s
  retries: 3
  start_period: 40s
```

### Dependencies

```yaml
# make sure `db` is alive before starting
depends_on:
  - db


# make sure `db` is healthy before starting
# and db-init completed without failure
depends_on:
db:
  condition: service_healthy
db-init:
  condition: service_completed_successfully

```

## Volumes

```yaml
volumes:
  - /var/lib/mysql # anonimous volume
  - ./host_path:/docker_container_path # bind mount
```
```yaml
volumes:
  - type: bind
    source: ./host_path
    target: /docker_container_path
  - type: volume
    # no source. Override the previous volumes for a specific path 
    target: /node_modules
```

## Restart

```yaml
# automatically restart container
restart: unless-stopped
# always, on-failure, no (default)
```

## User

```yaml
# specifying user
user: root
```

```yaml
# specifying both user and group with ids
user: 0:0
```
## Commands
``` shell
# Starts existing containers.
docker-compose start

# Stops running containers.
docker-compose stop

# Pauses running containers.
docker-compose pause

# Unpauses paused.
docker-compose unpause

# Lists containers.
docker-compose ps

# Builds, (re)creates, starts, and attaches to containers for a service.
docker-compose up

# Stops and removes containers.
docker-compose down
```

If you want to contribute leave a comment or fork the project repo:
https://github.com/maiobarbero/docker_compose_cheatsheet

Started from https://devhints.io/docker-compose
Need feedback on my app Chordpedia
Published: 2024-01-16 15:17:12

Hello everyone! 

I've developed a React Native app featuring custom-designed guitar chords and lyrics. I would greatly appreciate your feedback and suggestions for the app. Feel free to share your thoughts and recommendations. 

Thank you!

Android app link: https://play.google.com/store/apps/details?id=com.dez.chordpedia
IOS app Link: https://itunes.apple.com/app/id944763893
Implement Dynamic Programming in a cake shop (with code)
Tags: datastructures, javascript, programming
Published: 2024-01-16 15:11:25

Suppose you own a cake shop and decided to redecide your menu because you want to maximize your profit by selecting the most valuable cakes to include in your menu.
Each cake has a weight ( chota cake, mota cake) and a value (paisaaa).
The goal is to determine the maximum total value you can obtain with a given maximum weight capacity for your menu.



Code explanation
1) Initialize the Table (menu banane ke lie page toh laoge na)

const dp = Array(cakes.length + 1).fill(null).map(() => Array(capacity + 1).fill(0));

This line initializes a 2D array (dp) to store solutions to subproblems. The array has rows for each cake and columns for different weight capacities.

2) Dynamic Programming Iteration:
for (let i = 1; i <= cakes.length; i++) { const currentCake = cakes[i - 1]; for (let w = 0; w <= capacity; w++) {
The outer loop (i) goes through each cake, and the inner loop (w) goes through each possible weight capacity.

3)Decision Making:
if (currentCake.weight > w) { // If the current cake is too heavy for the remaining capacity, skip it
dp[i][w] = dp[i - 1][w]; } else { // Max value between including and excluding the current cake
dp[i][w] = Math.max(dp[i - 1][w], dp[i - 1][w - currentCake.weight] + currentCake.value); }
Here, the code decides whether to include the current cake or not. If the cake is too heavy for the remaining capacity, it skips it. Otherwise, it calculates the maximum value between including the current cake and excluding it.

4) Result Extraction: (bas ab menu print kr do)

return dp[cakes.length][capacity];

The final result is stored in the bottom-right cell of the dp table, representing the maximum profit considering all cakes and the given capacity.

Example Usage:
const cakes = [ { weight: 2, value: 15 }, { weight: 3, value: 20 }, { weight: 1, value: 10 }, ]; const capacity = 5; const maxProfit = maxCakeValue(cakes, capacity); console.log("Maximum profit:", maxProfit);

Real-world Explanation:
The maxCakeValue function helps you decide which cakes to include in your menu to maximize your profit, given the limited space (capacity) available on your menu display. The example usage with the cakes array and capacity variable shows how you can apply this function to find the maximum profit for your specific cakes and menu capacity.

Developer Rounit ❌
Baker Rounit ✅


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u4ti2zz16txtmubh383m.jpg)
What is YOUR theme part.2?!
Tags: productivity, discuss, community, showdev
Published: 2024-01-16 15:06:51

Hello fellow devs!

It's been a while since I posted the first part of "What is YOUR theme?!". Infact it has been 2 years!

I have returned to see if anyone has changed or found new themes they use on a daily basis now!

My theme has changed aswell. I went to buy a license key for the Monokai Pro theme pack and I have been using Monokai Pro (Ristretto Filter for a while now because the shade of brown feels very nice to my eyes and it's not as vibrant as most Monokai themes.

I would love to see everyone's changes and themes once again!

Much Love,
Luna 

![My VSCode Editor Theme (Monokai Pro (Ristretto Filter)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c9w4efmk31b4fr85yyzq.png)
Prevent ChatGPT from Using Your Data: A Privacy Guide
Tags: chatgpt, privacy
Published: 2024-01-16 15:04:00

Last week OpenAI [released](https://openai.com/blog/introducing-chatgpt-team) a new ChatGPT plan - Teams plan. The new plan has one specific feature:

- No training on your data

![a screenshot showing comparison between the two ChatGPT plans, Plus and Teams](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l8hg8ugd3aryz91ztkrf.png)

It struck me because I had previously assumed that Plus users’ data was not used for training by Open AI. Apparently, I was wrong.

I use ChatGPT heavily not just for work, but also for personal matters. I don’t feel comfortable knowing that it uses my data for some training and, potentially, shares it with the world.

**The data I share with ChatGPT should be private.**

I don’t want to use the more expensive Teams plan just for its privacy feature. I wondered if there is any other way of opting out of training?

I dug in and found two ways.

**The first approach** is using a setting in ChatGPT Data Controls. This is the solution that OpenAI promotes and recommends:

- go to “Settings & Beta” ⇒ “Data Controls” ⇒ “Chat History & training” and turn the setting off.

![a screenshot of ChatGPT "Data Controls" settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/56uufl4fgxct5612paqa.png)

This approach has one significant drawback - it’s coupled with the “Chat History” feature meaning that you can’t turn the training off and keep Chat History. You either have both or don’t. Even more so, this setting is not synced across devices: if you turn it off in your Browser, it won’t apply to you mobile app. More about that setting [here](https://help.openai.com/en/articles/7730893-data-controls-faq).

Everything suggests that OpenAI intentionally designed this opt-out feature in a way that users won't use it, and even if they do use it, then it will work only partially.

**The second approach**, the real 💪 approach, is not easy to find. It's mentioned only briefly in OpenAI FAQ. What you need is

• go to [privacy.openai.com/policies](http://privacy.openai.com/policies) page and submit a “Privacy Request” there.

![a screenshot of the OpenAI Privacy Request Portal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a9qg56n8992jfchij79k.png)

After submission you’ll soon be notified that your data is no longer used for training. This is exactly what we need: the ability to opt of Training across all devices, while still retaining all of ChatGPT's features.
What is a Mutex in Golang?
Tags: go, programming, beginners, architecture
Published: 2024-01-16 15:01:41

When you build Golang programs, you will almost always find a use for Goroutines.

Goroutines are powerful and generally easy to use, however, if you need to modify some piece of data that is shared between Goroutines - then you may run into some trouble with data integrity.

In this article, we will look at what is a "Mutex" and how to use it.

## What is a Mutex?

In Golang; a Goroutine is essentially a function that is put in a background queue and executed concurrently whenever resources are available.

```golang
package main

import (
	"fmt"
	"sync"
)

var NUM_PROCESSED = 0

func countNumProcessed(wg *sync.WaitGroup) {
	defer wg.Done()
	NUM_PROCESSED++
}

func main() {
	var wg sync.WaitGroup

	for i := 0; i < 500; i++ {
		wg.Add(1)
		go countNumProcessed(&wg)
	}

	wg.Wait()
	fmt.Println(NUM_PROCESSED)
}
```

If we remove the "go" keyword, each function call to "countNumProcessed" will block the loop and wait for this function to finish before continuing with the loop.

When you use the "go" keyword, these functions will be run concurrently. Which then makes it possible for 2 or more functions to modify the variable at the same time.

If you run this code a few times - you will notice that the total count fluctuates.

This is because each Goroutine, for a few nanoseconds copies the value of "NUM_PROCESSED" in memory to increment it and then update the variable. 

If two (or more) Goroutines copy the value around the same time, they will not be aware of updates made by other Goroutines.

For example: let's assume the value was "200"; each of the two Goroutines will add "1" i.e. "201". Thus the value for "NUM_PROCESSED" will become "201" instead of "202".

This is where a Mutex comes in handy. A Mutex will create a "lock" in the process - so that only one Goroutine can update "NUM_PROCESSED" at a time.

![Goroutines](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y9xzxdoakhs0sgnikhfp.jpg)

The other Goroutines will then be paused until the lock is released. This is very similar to a queue - when each Goroutine releases the lock, the next one acquires a new lock and the process continues until all the queued Goroutines finish updating "NUM_PROCESSED".

## A Mutex example

We can modify the above code to introduce a Mutex as follows:

```golang
package main

import (
	"fmt"
	"sync"
)

var NUM_PROCESSED = 0
var MUTEX sync.Mutex

func countNumProcessed(wg *sync.WaitGroup) {
	defer wg.Done()
	MUTEX.Lock()
	NUM_PROCESSED++
	MUTEX.Unlock()
}

func main() {
	var wg sync.WaitGroup

	for i := 0; i < 500; i++ {
		wg.Add(1)
		go countNumProcessed(&wg)
	}

	wg.Wait()
	fmt.Println(NUM_PROCESSED)
}
```
You will notice with the above code, that no matter how many times you run this function, it will always print "500". This is precisely the same amount of goroutines created in the for loop.
LawyerChat: Where Privacy Meets Productivity in Legal Tech (10x Faster)
Tags: ai, openai, chatgpt, machinelearning
Published: 2024-01-16 14:59:57

The cutting-edge, AI-powered platform is designed
for the modern legal professional. Balancing unparalleled privacy with enhanced productivity, LawyerChat is your trusted partner in navigating the legal landscape efficiently and securely.

Be the first to try: [https://lawyerchat.tech/](https://lawyerchat.tech/)

Trained on billions of lines of text, and legal drafts, LegalWriter.io provides the best results almost instantly.

## Boost Your Productivity

- **Automated Contract Management:** Transform your contract drafting with AI-driven efficiency. Generate, analyze, and optimize legal clauses faster than ever.

- **Intelligent Gap Detection:** LawyerChat's AI swiftly identifies missing elements in contracts, suggesting precise legal language to fortify your documents.

- **Effortless Legal Research:** Our Auto Investigator feature accelerates your legal research, providing quick access to an extensive database of legal resources.

## Our Promise of Privacy

- **Uncompromised Confidentiality:** We understand the importance of client confidentiality in legal work. LawyerChat is built with industry-leading encryption and privacy protocols to safeguard your sensitive data.

- **Local Hosting & Private Containers:** For enhanced security, LawyerChat offers local hosting solutions and private containers, ensuring that your data never leaves your control.

- **No Data Harvesting:** Your data belongs to you. We assure you that LawyerChat does not collect or store your data without your explicit consent.

Sounds interesting? Have a try!
Find the number of occurrences for each character in a string in javascript
Published: 2024-01-16 14:57:24

```
  let str="hell" 
            var count = {};
            for (let i = 0; i < str.length; i++) {
                var ch = str[i];
                if (count[ch] > 0) {
                    count[ch]++;
                } else {
                    count[ch] = 1;
                }
            }
            for(let i in count){
                console.log(i,count[i])
            }
        
```
Electronic load repair
Published: 2024-01-16 14:48:06

I wanted my first post to be interesting, but it was a facepalm instead.

While using my ~~aliexpress~~ cheap electronic load to test a 12V lead-acid battery, I smelled some ~~burnt smell~~ magic smoke and it showed 0A of current regardless of the position of the pot meters.

![Original Aliexpress photo about the electronic load](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tf1fe8nn6eqfth3fejry.jpeg)

_Original Aliexpress photo about the electronic load_

I removed the big heatsink and before measuring / inspecting anything, I quickly replaced the IRFP260N power mosfet, because I had one in the drawer.

![Electronic load without heatsink](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wb3jp0a18b2iz56mqfor.jpeg)

_Electronic load without heatsink (and with the replaced MOSFET)_

After that it showed the same symptoms, 0A of current.

I went through some systematic analysis steps:

1. measuring the old and new power MOSFET (old was bad, new was good), so the replacement was neccessary, but not sufficient.

2. inspecting the whole board under a microscope checking for burnt parts: found nothing.

3. measuring a few components for damage, such as shorted caps and shorted/open resistors, but found nothing

4. taking photos of both sides of the PCB, merging them as semi-transparent images and try to follow the traces to reconstruct the schematics

![Reconstructing the traces](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ngcacsw7l75mbi56njxs.jpg)

_Reconstructing the traces_

During the reconstruction it looked like a standard electronic load design using a power MOSFET and a comparator op-amp, but I had issues drawing the schematics, because the MOSFET pins were weird...

![Part of the schematics](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o80yr1yl8nyb2zabhkbg.jpg)

![Simple Electronic load reference circuit](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8995w8j3g79rs8eag7vm.png)

_My wrong schematics reconstruction vs a good simple electronic load reference circuit... Check for the MOSFET pins_

It took me half a minute to understand I could fix the whole issue under 2 minutes, if I was aware of the orientation of the power MOSFET...

After flipping it, everything was fine...

![Facepalm](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hzevro1nriicr964m0ia.jpg)
The Ultimate Guide to Using SMTP for Transactional Emails What is SMTP?
Tags: transactional, smtp, powermta
Published: 2024-01-16 14:31:08

The Ultimate Guide to Using SMTP for Transactional Emails
What is SMTP?

SMTP, or Simple Mail Transfer Protocol, is an essential component of sending and receiving email messages over the internet. It is a set of rules that govern the interaction between the email client and the email server. When you send an email, your email client uses SMTP to communicate with the recipient's email server, ensuring that the message is delivered securely and reliably.

Why Use SMTP for Transactional Emails?

Transactional emails, such as order confirmations, password resets, and account notifications, play a crucial role in maintaining effective communication with customers. SMTP ensures that these emails are delivered promptly and reliably, helping to build trust and credibility with your audience. By using SMTP for transactional emails, you can also track delivery status and monitor the performance of your email campaigns.

How to Set Up SMTP for Transactional Emails
Choose a [Reliable SMTP Service](https://codermails.in): Look for a reputable SMTP service provider that offers high deliverability rates and robust security features. Popular options include SendGrid, Amazon SES, and Mailgun.
Configure Your Email Client or Application: Once you have selected an SMTP service, follow their documentation to configure your email client or application to send emails using their SMTP server. This typically involves entering the SMTP server address, port number, and your authentication credentials.
Test and Monitor: Before sending out transactional emails to your audience, conduct thorough testing to ensure that everything is set up correctly. Monitor your email delivery and open rates to identify any potential issues or opportunities for improvement.
Best Practices for Using SMTP for Transactional Emails
Implement SPF and DKIM: To enhance the security and authenticity of your emails, enable SPF (Sender Policy Framework) and DKIM (DomainKeys Identified Mail) authentication for your domain.
Monitor Deliverability: Keep a close eye on your email deliverability metrics, such as bounce rates and spam complaints, and take proactive steps to maintain a positive sender reputation.
Optimize Email Content: Craft clear and engaging content for your transactional emails, focusing on delivering value and building trust with your recipients.
Stay Compliant: Adhere to email regulations and best practices, such as including an unsubscribe link and honoring opt-out requests.
Conclusion

Using SMTP for transactional emails is a critical aspect of maintaining effective communication with your audience. By following best practices and leveraging a reliable SMTP service, you can ensure that your transactional emails are delivered securely and promptly, ultimately enhancing your brand's credibility and fostering positive customer relationships.
What are your goals for week 3 of 2024?
Tags: technology
Published: 2024-01-16 14:21:11

Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.

What is Lorem Ipsum?

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Why do we use it?

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
Vue.js3 Usage Survey
Tags: webdev, javascript, vue
Published: 2024-01-16 14:07:02

## Hey folks!

👋 Josun here, a TypeScript and .NET Fullstack Software Developer hailing from the beautiful vicinity of Hamburg, Germany. In my day job, I find myself immersed in the world of Angular, but truth be told, it's not exactly my cup of tea.

Now, in my personal coding adventures, I've been exploring the wonders of Vue.js, and let me tell you, it's been a game-changer for me. The simplicity, the flexibility, it's just something else.

So, I'm curious about your experiences! I've put together this survey to dive into the Vue.js community and understand why you do or don't use it. Whether you're a fellow enthusiast or not, I want to hear your thoughts.

## Survey Questions

1. **Do you use Vue.js3 in your projects?**
   - Yes
   - No

2. **If yes, what aspects of Vue.js3 do you find most appealing?**
   - [ ] Ease of Learning
   - [ ] Flexibility
   - [ ] Community Support
   - [ ] Performance
   - [ ] Other (please specify)

3. **If no, what factors influence your decision not to use Vue.js3?**
   - [ ] Prefer other frameworks
   - [ ] Lack of familiarity
   - [ ] Performance concerns
   - [ ] Other (please specify)

Feel free to share your thoughts and let's have a lively discussion! Looking forward to hearing from you all.

Happy coding! 🚀
Reverse a string in c#
Published: 2024-01-16 13:59:14

```
using System;
public class HelloWorld
{
    public static void Main(string[] args)
    {
        string data ="Miraj";
        string di="";
        for(int i= data.Length - 1; i >= 0; i--){
            di+=data[i];
        }
        Console.WriteLine(di);
    }
}
```