teleren/devto huggingface dataset:
Problem Solved!!
Published: 2024-05-30 21:14:41

Hey everyone!

I'm back with an exciting update on my internship journey into the realm of game development! Thanks to the incredible support from my peers and some invaluable feedback, I've managed to overcome the pesky error that had been hindering my progress. It's amazing what a fresh perspective and a collaborative spirit can achieve!

During one of our team meetings, I received some fantastic suggestions for refining the mechanics of my space-themed math game. One of the most significant pieces of feedback was to allow the players more freedom of movement within the game. Instead of restricting them to simple up-and-down motions, I revamped the gameplay to enable players to navigate their spacecraft freely across the screen. This not only enhances the gameplay experience but also adds an extra layer of excitement and challenge.

Another insightful suggestion was to modify the interaction with the floating numbers in the game. Rather than having the numbers collected from a distance, the feedback emphasized making the collection mechanic more intuitive and engaging. As a result, I adjusted the game mechanics so that players now have to directly touch the numbers with their spacecraft to collect them. This subtle tweak adds a tactile element to the gameplay, making it more immersive and enjoyable.

Now, let's talk about the changes I made to the code. Here's an overview of the modifications:

this was the code used for the free-movement mechanic
```
public void OnDrag(PointerEventData eventData)
    {
        Vector3 mousePosition = eventData.position;
        transform.position = mousePosition;
    }

    private Vector3 offset;

    void OnMouseDown()
    {
        offset = transform.position - GetMousePosition();
    }

    void OnMouseDrag()
    {
        transform.position = GetMousePosition() + offset;
    }

    Vector3 GetMousePosition()
    {
        return Camera.main.ScreenToWorldPoint(Input.mousePosition);
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Number")
        {
            objectCollidedWith = collision.gameObject;
            PickUp();
        }
    }
```
and this is the one for picking up the numbers
```


public void PickUp()
    {      

            
            Destroy(objectCollidedWith);

            eqM.AddNumber(gm.number);
    }
```

With these adjustments, the gameplay feels more dynamic and interactive, offering players a truly immersive experience. I'm thrilled with the progress we've made, and I can't wait to see how players respond to the updated version of the game.

Thank you to everyone who has been following along on this adventure and providing invaluable support and feedback. Together, we're crafting something truly special, and I'm incredibly grateful for the opportunity to learn and grow with such an amazing community.

Stay tuned for more updates as I continue to dive deeper into the world of game development!
#1442. Count Triplets That Can Form Two Arrays of Equal XOR
Published: 2024-05-30 20:51:59

https://leetcode.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor/solutions/5228488/98-33-easy-solution-with-explanation/?envType=daily-question&envId=2024-05-30

```js

/**
 * @param {number[]} arr
 * @return {number}
 */
var countTriplets = function (arr) {
    let n = arr.length
    let prefix = new Array(n + 1).fill(0)

    for (i = 0; i < n; i++) {
        prefix[i + 1] = prefix[i] ^ arr[i]
    }

    let count = 0

    for (let i = 0; i < n; i++) {
        for (let k = i + 1; k < n; k++) {
            if (prefix[i] === prefix[k + 1]) {
                count += (k - i)
            }
        }
    }

    return count
};


```
Creating a Smaller Docker Image: A Practical Guide
Tags: docker, optimization, devops, kubernetes
Published: 2024-05-30 20:32:48

To illustrate the process of creating a smaller Docker image, let's consider a simple Python application. We'll leverage several strategies to minimize the image size.

**Step 1: Choose a Minimal Base Image**
Start with a minimal base image like Alpine or scratch instead of larger ones like Ubuntu. Alpine Linux is a security-oriented, lightweight Linux distribution.

```
# Use a minimal base image
FROM python:3.9-alpine
```

**Step 2: Install Only Necessary Dependencies**
Install only the dependencies required by your application.

```
# Install dependencies
RUN apk add --no-cache gcc musl-dev
```

**Step 3: Use Multi-Stage Builds**
Multi-stage builds allow you to separate the build environment from the runtime environment, ensuring only necessary artifacts are included in the final image.

```
# First stage: Build environment
FROM python:3.9-alpine AS builder
WORKDIR /app
COPY requirements.txt .
RUN apk add --no-cache gcc musl-dev && \
    pip install --user -r requirements.txt

# Second stage: Runtime environment
FROM python:3.9-alpine
WORKDIR /app
COPY --from=builder /root/.local /root/.local
COPY . .
ENV PATH=/root/.local/bin:$PATH
CMD ["python", "app.py"]
```

**Step 4: Optimize Layers and Remove Unnecessary Files**
Combine commands to reduce the number of layers and remove unnecessary files and directories.

```
# Combining commands to reduce layers
RUN apk add --no-cache gcc musl-dev && \
    pip install --user -r requirements.txt && \
    apk del gcc musl-dev && \
    rm -rf /var/cache/apk/*
```

**Complete Dockerfile Example**
Here’s the complete Dockerfile incorporating all the strategies mentioned:

```
# First stage: Build environment
FROM python:3.9-alpine AS builder
WORKDIR /app
COPY requirements.txt .
RUN apk add --no-cache gcc musl-dev && \
    pip install --user -r requirements.txt && \
    apk del gcc musl-dev && \
    rm -rf /var/cache/apk/*

# Second stage: Runtime environment
FROM python:3.9-alpine
WORKDIR /app
COPY --from=builder /root/.local /root/.local
COPY . .
ENV PATH=/root/.local/bin:$PATH
CMD ["python", "app.py"]
```

Smaller Docker images bring significant advantages, including faster deployment times, enhanced security, and optimized resource usage. By using minimal base images, installing only necessary dependencies, leveraging multi-stage builds, and optimizing layers, you can create efficient and compact Docker images. This not only streamlines your development and deployment processes but also enhances the overall security and maintainability of your applications. Embracing these best practices will help you make the most out of Docker's capabilities.
Defer Statements in Go: A Short Crash Course
Tags: go, beginners, tutorial, learning
Published: 2024-05-30 20:31:34

## What is the defer statement?

In Go, a `defer` statement gives you the ability to execute a function **AFTER** its containing function has finished execution. 

The easiest way to think about it is a callback, or a finally block for developers more familiar with Java. 

You will commonly see defer statements being used to clean up resources, such as files and database connections. 

## defer Statement Syntax

```
func main() {
  myFile, err := os.Open("my-file.txt")
  defer myFile.close()
  
  if err != nil {
    panic(err)
  }
}

```

The above is an example of using `defer` to clean up resources, in this case, closing a file after we are done with it. The `defer` statement will not execute until after our `main` method has finished its execution. 

Using defer directly after opening a resource that needs to be manually closed or handled (like files!) is a best practice. This way you know for sure there will be no left over resources and you won't forget to manually close it later on in the code.

I like to keep such defer statements as close as possible, ideally right under, the line that opens the resources.

## Using Multiple defer Statements

`defer` statements are placed on a stack. Meaning the last defined statement will be the first to be executed. This is something I had to learn the hard way after facing a particularly confusing bug!


Consider the following code:

```
import "fmt"

func main() {
	defer deferredPrint("0")
	defer deferredPrint("1")
	defer deferredPrint("2")
}

func deferredPrint(s string) {
	fmt.Printf("%s\n", s)
}
```

What might its output be?

Since `defer` statements are placed in a call stack (LIFO) the output is the following:
```
2
1
0
```

Notice that the last defined `defer` statement is executed first!
Keydown Event Listener and Focus
Published: 2024-05-30 20:24:17

Hello readers! Welcome to my first blog where I will be discussing the issues and resolution I had with the "Keydown" event listener in JavaScript. When trying to implement my last event listener I struggled for an hour trying to understand why it was not working although the logic was all there. Here is the original HTML, JavaScript, and CSS for my code:
**HTML**
``` 
<img src="https://pbs.twimg.com/profile_images/1364220282790109188/uT0fQV56_400x400.jpg" alt="blue party hat" id="easterEgg" tabindex="0">
    <div>
```
**JavaScript**

```
const easterEggImage = document.getElementById('easterEgg') 

easterEggImage.addEventListener("keydown", handleKeyDown);

function handleKeyDown(event) {
  if (event.key.toLowerCase() === "h") {
    easterEggImage.style.display = "block";
  }
}
```
**CSS**
```
#easterEgg {
    display: none;
    position: fixed;
    left: 0;
    bottom: 0px;
    margin-left: 5%;
    max-width: 90%;
}
```
 The idea of this was to make an image appear whenever the user pressed the "h" key. Unfortunately it was not working and I could not understand why. After doing research I became more familiar with the concepts of "Event Delegation" and "direct event attachment". When I was using the descendant element `easterEggImage` I was only giving instruction for to apply the event to that element only. This is not what I intended so in order to fix this I attached the `addEventListener` to the document instead. Here is the working code below: 
```
document.addEventListener("keydown", handleKeyDown);
```
Now my keydown event will trigger anywhere in the document! So after my hour long struggle I was able to get my image to appear with this function.
Overview: Express.js Framework Middleware's
Tags: webdev, javascript, backend, express
Published: 2024-05-30 19:54:58

One of the most important things about **Express.js** is how minimal this framework is. Known for its simplicity and performance, Express.js is one of the most popular frameworks in the **Node.js** ecosystem.

Let's dive into interesting parts:

Using **Middleware** functions, is possible to access the request and response objects, making it easy to add functionalities like logging, authentication, and data parsing. Check the example:

```js
const requestLogger = (req, res, next) => {
  console.log(`${req.method} ${req.url}`);
  next();
};
```
The **next()** function, is responsible to pass the control for the next middleware. Without calling this function, the request will not proceed to the next middleware or route handler, and the request-response cycle will be left hanging.

You can also apply this **middleware** for all the routes, using only a line of code.
```js
app.use(requestLogger);
```
This show to how **Express.js** is really simple to read! 😁

## Testing

_This is my favorite part, let's test it!!_
Adding some basic routes to test the **middleware**
```js
app.get('/', (req, res) => {
  res.send('Hello, World!');
});

app.get('/about', (req, res) => {
  res.send('About Page');
});
```

## Follow the full code for test the Middleware functions:
**Note:** Create a file 'index.js' and add the full code.
```js
const express = require('express');
const app = express();
const port = 3000;

const requestLogger = (req, res, next) => {
  console.log(`${req.method} ${req.url}`);
  next(); // Pass control to the next middleware function
};

app.use(requestLogger);

app.get('/', (req, res) => {
  res.send('Hello, World!');
});

app.get('/about', (req, res) => {
  res.send('About Page');
});

app.listen(port, () => {
  console.log(`Server running at http://localhost:${port}/`);
});

```

## IMPORTANT
Before run check if the port in the `const port` is in use.

Run in the terminal:
```js
node app.js
```

**Thank you, Please Follow:** [Webcrumbs](https://webcrumbs.org)

![Webcrumbs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/68jt1eo11phux344foqf.png)

_Bibliography: [Express.js Docs](https://expressjs.com/)_
Publicando imagen docker a repositorio con Azure Devops
Tags: azure, devops, linux, spanish
Published: 2024-05-30 20:56:48

---
title: Publicando imagen docker a repositorio con Azure Devops
published: true
date: 2024-05-30 19:39:00 UTC
tags: Azure,DevOps,Linux,spanish
canonical_url: https://www.ahioros.info/2024/05/subir-imagen-docker-repositorio-con.html
---

En este ejemplo vamos a subir una imagen docker al repositorio de dockerhub con Azure Devops.

Este manual/tutorial es la continuación de [Cómo conectar un pipeline de Azure DevOps Pipelines con DockerHub](https://www.ahioros.info/2024/05/como-conectar-un-pipeline-de-azure.html) y [Creando una imagen docker de una aplicación en react](https://www.ahioros.info/2024/05/creando-una-imagen-docker-de-una.html) si no los has leído por favor hazlo para que te des una idea de dónde nos quedamos.

Ya que hemos creado nuestro archivo Dockerfile y .dockerignore podemos continuar. Básicamente lo que haremos aquí es:

    1. Vamos a poner en nuestro pipeline la creación de una imagen docker de una aplicación en react.
    2. Luego vamos a subir nuestra imagen en nuestro repositorio de dockerhub.
    
<!-- agrega el botón leer más -->
        

Estas dos tareas las haremos en un solo paso (task en este caso).

Tomamos nuestro archivo yaml del pipeline creado anteriormente y le agregamos la tarea de **buildAndPush**.

```yaml
  pr:
    branches:
      include:
        - "*"

  pool:
    vmImage: ubuntu-latest

  stages:
    - stage: LoginAndLogout
      jobs:
        - job: buildandpush
          steps:
            - task: Docker@2
              displayName: Login
              inputs:
                command: login
                containerRegistry: docker-hub-test

            - task: Docker@2
              displayName: BuildAndPush
              inputs:
                command: buildAndPush
                containerRegistry: docker-hub-test
                repository: ahioros/rdicidr
                tags: latest

            - task: Docker@2
              displayName: Logout
              inputs:
                command: logout
                containerRegistry: docker-hub-test
```

**Nota** : En este ejemplo todas las imágenes que subamos tendrán el tag **latest** , esto lo podemos cambiar si deseamos usando el $(Build.BuildId) como tag:
```bash
    	  tags: |
        	$(Build.BuildId)
        	latest
```
Ejecutamos nuestro pipeline con los cambios al finalizar el pipeline vamos a nuestro repositorio dockerhub donde veremos la nueva imagen.

Acá te dejo el video de esta configuración por si tienes dudas:

{% youtube nmhLqZ3Kk_I %}

<iframe allowfullscreen="" youtube-src-id="nmhLqZ3Kk_I" width="480" height="270" src="https://www.youtube.com/embed/nmhLqZ3Kk_I"></iframe>
การป้องกันการทำให้สัตว์เลี้ยงหายออกจากบ้าน: วิธีการง่ายๆ ที่คุณสามารถทำได้
Tags: pet, technology
Published: 2024-05-30 19:37:09


---
published: true
description: "เรียนรู้วิธีการป้องกันสัตว์เลี้ยงของคุณจากการหลบหนีออกจากบ้าน ด้วยวิธีการง่ายๆ ที่สามารถทำได้ทันที"
canonical_url: "https://pey-journey.co"
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gywl0dwy8xi5c5a3vf4g.jpeg
---

## การป้องกันการทำให้สัตว์เลี้ยงหายออกจากบ้าน: วิธีการง่ายๆ ที่คุณสามารถทำได้

สัตว์เลี้ยงเป็นส่วนหนึ่งของครอบครัวเรา และการสูญเสียสัตว์เลี้ยงสามารถสร้างความเศร้าโศกและความเครียดให้กับเจ้าของได้ ดังนั้นการป้องกันไม่ให้สัตว์เลี้ยงหายออกจากบ้านเป็นสิ่งที่สำคัญมาก ต่อไปนี้คือวิธีการที่สามารถช่วยป้องกันการสูญเสียสัตว์เลี้ยงได้

## 1. การติดตั้งรั้วและประตูที่มั่นคง
การติดตั้งรั้วและประตูที่มั่นคงเป็นวิธีที่ดีในการป้องกันไม่ให้สัตว์เลี้ยงหลบหนี รั้วควรมีความสูงเพียงพอและไม่มีช่องว่างที่สัตว์เลี้ยงสามารถหลบหนีได้ สำหรับประตูควรตรวจสอบให้แน่ใจว่าเป็นแบบที่สัตว์เลี้ยงไม่สามารถเปิดได้ด้วยตัวเอง

## 2. การติดแท็กหรือไมโครชิป
การติดแท็กหรือไมโครชิปที่มีข้อมูลของเจ้าของจะช่วยให้สัตว์เลี้ยงสามารถถูกระบุตัวได้ง่ายในกรณีที่หายไป การติดไมโครชิปเป็นวิธีที่มีประสิทธิภาพสูงเนื่องจากไมโครชิปไม่สามารถหลุดออกได้เหมือนกับแท็ก

## 3. การฝึกให้สัตว์เลี้ยงรู้จักคำสั่งพื้นฐาน
การฝึกให้สัตว์เลี้ยงรู้จักคำสั่งพื้นฐาน เช่น "หยุด" หรือ "มา" จะช่วยให้คุณสามารถควบคุมสัตว์เลี้ยงได้ดีขึ้นเมื่ออยู่ในสถานการณ์ที่อาจทำให้สัตว์เลี้ยงหลบหนี

## 4. การดูแลและให้ความสนใจ
สัตว์เลี้ยงที่ได้รับการดูแลและให้ความสนใจอย่างเพียงพอจะมีโอกาสน้อยที่จะพยายามหลบหนีเพื่อค้นหาความสนุกหรือความสนใจจากภายนอก ควรให้เวลาเล่นและออกกำลังกายกับสัตว์เลี้ยงทุกวัน

## 5. การติดตั้งประตูสัตว์เลี้ยงที่มีล็อค
หากคุณมีประตูสัตว์เลี้ยงในบ้าน ควรเลือกใช้ประตูที่มีล็อคเพื่อป้องกันไม่ให้สัตว์เลี้ยงสามารถออกไปข้างนอกได้โดยไม่ได้รับอนุญาต

## 6. การเฝ้าระวังอย่างใกล้ชิด
การเฝ้าระวังสัตว์เลี้ยงอย่างใกล้ชิดเมื่ออยู่ข้างนอกเป็นสิ่งสำคัญ ควรตรวจสอบให้แน่ใจว่าสัตว์เลี้ยงอยู่ในสายตาของคุณตลอดเวลา และหากจำเป็นควรใช้สายจูงเมื่อออกไปข้างนอก

การป้องกันสัตว์เลี้ยงหายออกจากบ้านต้องการการวางแผนและความใส่ใจในรายละเอียดต่าง ๆ แต่การป้องกันเหล่านี้จะช่วยให้คุณมั่นใจได้ว่าสัตว์เลี้ยงของคุณจะปลอดภัยและอยู่กับคุณไปตลอดเวลา

---
Function tricks
Tags: javascript, typescript, webdev, programming
Published: 2024-05-30 19:12:41

## Motivation
Some JS features are hidden under the hood or veiled under some expressions, etc.

This article is about to enlighten some features or approaches that are not on the surface.

## Prerequisites

JS knowledge and that's all.

## Case #1

We have a simple code: 

```js
function test(a,b){
  return {
    sum: a + b,
    multiplied: a * b
  }
}
```
This function just returns an object with _sum_ and _multiplied_ values.

We can invoke the function like: 
```js
test(1,2) // -> {sum: 3, multiplied: 2}
```

But also we can modify our function to:

```js
function test(a,b){
  this.sum = a + b
  this.multiplied = a * b
}
```

In this case, we have no return statement, but in the return of invocation like this:
```js
new test(1,2)
```

we will have the same structure, smth like this:

```js
test {
  sum: 3,
  multiplied: 2,
  __proto__: { constructor: ƒ test() }
}
```

## Case #2
The typical way to invoke the function:
```js
//....
testFunction(a,b,c)
```
but we have another method to invoke if we have no args(e.g): 
```js
function test(){
  return { message: "Hi there!" }
}

const data = new test

console.log(data.message) // -> "Hi there!"
```
<img width="100%" style="width:100%" src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExc3Jmamw5eml2czduOGticmN1d3ZlbWU2M2NvMmJqa21tMDgzbTQ4ayZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/9UmAh3S9S6krqCkZ9p/giphy.gif">

## Case #3

The regular way that we can use it provides the object on the return statement inside the function, but we can use it outside if we need it.

Regular:
```js
function test(){
  return { message: "Hi there!" }
}

console.log(test()) // -> "Hi there!"
```
Weird, but possible:

```js
function test(){
  return { message: "Hi there!" }
}
test.useTest = function(){
  return this()
}

console.log(test.useTest()) // -> "Hi there!"
```
for example in `React` we can use this approach for compositing our components.

## Conclusion
JS is tricky and not as simple as it looks.

<img width="100%" style="width:100%" src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExbjNtZ3NpeDBjaDV4MnFrdWxrbHQ5ZmtrdzNjN3Bob2JqNWJhbzMyNiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/5qlnl8qqLVekKaZaKC/giphy.gif">
Elevate Your Cleaning Routine with Expert Tips from Bokma.de
Tags: cleaning, hometips, spotlesshome, professionalhomecleaning
Published: 2024-05-30 19:06:12

Maintaining a spotless home can often feel like a never-ending challenge. Between work, family, and other commitments, it’s easy for cleaning tasks to pile up. Fortunately, www.bokma.de is here to help with expert cleaning tips that can transform your routine and keep your home sparkling clean.

Why Choose www.bokma.de?

At www.bokma.de, we understand that a clean home is not just about aesthetics – it’s about creating a healthy, stress-free environment for you and your family. Our team of experts is dedicated to providing practical, effective cleaning solutions tailored to your needs.

Top Cleaning Tips from www.bokma.de

Create a Cleaning Schedule: Consistency is key. Break down your cleaning tasks into daily, weekly, and monthly activities to make the process more manageable. For instance, tackle kitchen surfaces and floors daily, while saving deep cleaning tasks like window washing for monthly sessions.

Use the Right Tools and Products: Investing in high-quality cleaning tools and products can make a significant difference. At www.bokma.de, we recommend eco-friendly, non-toxic cleaners that are safe for your family and the environment. Microfiber cloths, a good vacuum cleaner, and specialized brushes can also make your cleaning tasks more efficient.

Declutter Regularly: Clutter can make even the cleanest homes look messy. Regularly go through your belongings and decide what to keep, donate, or discard. A decluttered space not only looks better but also reduces the number of surfaces that need to be cleaned.

Focus on High-Touch Areas: Pay special attention to areas that are frequently touched, such as door handles, light switches, and remote controls. These spots can harbor germs and bacteria, so cleaning them regularly is crucial for maintaining a healthy home.

Don’t Forget the Details: Small details like cleaning baseboards, dusting ceiling fans, and wiping down appliances can make a big difference. These tasks are often overlooked but contribute to the overall cleanliness and feel of your home.

Join the www.bokma.de Community

At www.bokma.de, we believe in sharing knowledge and helping each other achieve a cleaner, more organized living space. Join our community for more tips, product recommendations, and cleaning hacks that can make your life easier.

Visit Us Today

Ready to elevate your cleaning routine? Visit www.bokma.de today for more expert tips and resources. Whether you’re looking for advice on tackling tough stains, organizing your space, or selecting the best cleaning products, www.bokma.de has you covered.