teleren/devto huggingface dataset:
REACTJS 
Tags: react
Published: 2021-12-29 18:48:06

[](url) What is the purpose of a custom hook? How will you create a custom hook? Give an
example?
Ans: custom hooks are javascript functions that we create by own. We can use parts of code
anywhere by using a custom hook.

We can create a custom hook like a regular javascript function . example:
Import useState from React
const custom = ()=> {
const [state,setState] = useState()
useEffect(()=>{
axios(`url`).then(result=>setState(result.data))
},[])
return {setState,state}
}
What is the most challenging task you have accomplished using react?
Ans: The most challenging task is using context api that i have accomplished using react is .
What is Redux and uses?
Ans: Redux is a popular library for frontend development used for managing state and it is also
used in react.
Do you know about react native?
Ans: React native an open source cross platform mobile application framework.
What is a higher order component ? Give an example?
Ans: higher component component is function that takes a component and return a function.
import React, {Component} from 'react';
export default function Hoc(HocComponent){
return class extends Component{
render(){
return (
<div>
<HocComponent></HocComponent>
</div>
);
}
}
}
 How would you optimize a reactjs application?
Ans: By Using immutable data structure , Functional state component ,avoid using index as key
for map ,we can optimize a reactjs application.
.What are the features of react?
Ans: the features are unidirectional data flow , virtual dom , client side rendering
What can you do with HOC?
Ans: we can do with hoc we can reuse code , logic ,we can manipulate props.
What are pure components?
Ans: pure components are the simplest and fastest component in react. It can be replaced with
any component.
 What is a react router?
Ans: react router is a library that is built on react. React router is used for single page
application.it has a simple api.
What are the differences between functional and class components?
Ans: before the introduction of hook functional component are known as stateless component
after introduction of hooks it is equivalent to class component and class component is known as
stateful component.
How to use Javascript to auto-update the year of publication on your website 
Tags: javascript, react, nextjs
Published: 2021-12-29 18:33:19

In this tutorial you will learn how to use Javascript to auto-update the year of publication on your website.

Sometimes I like to browse through different websites just to check out design trends and get some inspiration. From my general observation, it seems like the year of publication on most websites will be outdated for example you will notice `Copyright 2017` in 2021 instead of `Copyright 2021`. 

Now imagine you've many projects that you have built and you've to edit the code to update the year of publication on each website manually. It's a very tedious and time-consuming task which however, can easily be evaded by using Javascript. Since we're almost done with 2021, this short and simple tutorial will explain how Javascript can be implemented to automatically change the year of publication on any website whenever the year changes.

**HTML**

```
footer>
    <span>
        &copy;<time></time> Mywebsite. All rights reserved. 
    </span>
</footer>
```

**Vanilla Javascript**

```
const date = new Date()
const currentYear = date.getFullYear()
const time = document.querySelector('time')

time.setAttribute('datetime', date)
time.innerHTML = currentYear
```

**React JS**

Assuming that you already know how to create a new react-app using `npx create-react-app example-app`, let's dive right into the code.

```
export default function Footer(){
    return (
        <Copyright />
    )

    function Copyright(){
        const time = new Date()

        return (
            <footer>
                <span>
                    &copy;<time dateTime={time}> 
                    {time.getFullYear()}</time> Website. All 
                    rights reserved.
                </span>
            </footer>
        )
    }
}   
```

Voila! That's all you need to do and the year of publication on your projects will be auto updated by Javascript.
How to check commit message and branch name with git hooks without any new installation
Tags: git, hooks, devops, programming
Published: 2021-12-29 18:25:40

## Introduction

Hi All ! 
I'm a tech lead, and I'm on charge to check Pull Request/Merge Request on my team. And also to create release notes (CHANGELOG.md) on each release.
So, my first problem was to resolve the commits of the developers, that they always have some mistake, or have errors into the commit message (without correct format), or errors in the branch name.
I searched and I found different solutions. A lot of them need to use an external software, like node (npm library), or php composer library, etc. And the projects are in different technologies, like Android, PHP, .NET, etc.

After checking all that I found, I created a solution that works in all environments without external dependencies.

The solution is really easy.
You need to follow these easy steps

## Steps:

1. create **.git-hooks** folder into your project root directory, at the same level you already have .git folder
2. create 2 files into this folder: **pre-commit** and **prepare-commit-msg** (these two files don't have an extension)
3. put the correct code into each file (I will add them below these steps)
4. run this command in your command line, into your main folder of your project (one level up from .git-hooks): **git config core.hooksPath .git-hooks**
5. READY ! 

## The Code

**pre-commit** file code:
```bash
#!/bin/bash

BRANCH=$(git rev-parse --abbrev-ref HEAD)
REGEX="^(dev|release)-([0-9]+)-q([0-9]+)\.([0-9]+)\.(.+)$"

if ! [[ $BRANCH =~ $REGEX ]]; then
  echo "Your commit was rejected due to branching name"
  echo "Please rename your branch with '(dev|release)-YYYY-qX.X.X' syntax"
  exit 1
fi
```

**prepare-commit-msg** file code:
```bash
#!/bin/bash

MESSAGE=$(cat $1) 
COMMITFORMAT="^(feat|fix|docs|style|refactor|test|chore|perf|other)(\((.*)\))?: #([0-9]+) (.*)$"

if ! [[ "$MESSAGE" =~ $COMMITFORMAT ]]; then
  echo "Your commit was rejected due to the commit message. Skipping..." 
  echo ""
  echo "Please use the following format:"
  echo "feat: #1234 feature example comment"
  echo "fix(ui): #4321 bugfix example comment"
  echo ""
  echo "More details on COMMITS.md"
  exit 1
fi
```

You can edit it according to your needs.


## Explanation

File **pre-commit**: check branch names.
In my case I filter to use only format like that:
dev-YYYY-qX.X.X
release-YYYY-qX.X.X
Where YYYY is the year, and X.X.X is the version, in our case we use the Quarter number.
You could change that using regex and put what you want ;)

File **prepare-commit-msg**: check commit message.
In our case, we use the following format:
https://www.conventionalcommits.org/en/v1.0.0/   
http://karma-runner.github.io/1.0/dev/git-commit-msg.html

Off course, you could change it as your needs.

And finally, the command **git config core.hooksPath .git-hooks** change your local git hooks configuration to use the new path .
Installing Homebrew on Linux
Tags: linux, bash, todayilearned
Published: 2021-12-29 18:10:23

---
tags:
- linux
- bash
- til
series: til
title: Installing Homebrew on Linux
canonical_url: https://waylonwalker.com/til/installing-homebrew-linux/
published: true
---

Installing brew on linux proved quite easy and got pyenv running for me within 4 commands.

I had never used homebrew before, honestly I thought it was a mac only thing for years.  Today I wanted to try out pyenv, and the recommended way to install was using homebrew.  I am not yet sure if I want either in my normal workflow, so for now I am just going to pop open a new terminal and install homebrew and see how it goes.


``` bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/walkers/.zprofile
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
```

That was it, now homebrew is working. Starting a new shell and running the command to install pyenv worked.

``` bash
brew install pyenv
```

## Links

* [homebrew](https://brew.sh/)

---

This post is part of a series of til's where I share things in short digestible chunks.
Abtach – Offering Top-Notch Digital Solutions Across the Planet
Published: 2021-12-29 18:09:21

Abtach is one of the most exceptional and outstanding companies in the digital and information technology industry, known to offer and deliver highly amazing and premium digital and IT related services to customers or clients across the globe at the most reasonable prices in the industry. [Abtach](https://www.abtach.com/) was founded in 2015, with only one goal ahead of it, which was to ensure that each and every entrepreneur of this world, gets the power to use the digital technology, which can help in improving their business in the most extraordinary manner.

See, over the past few years, there have been many innovations in the technology industry, which have literally compelled business organizations across the globe to adopt these technologies because in simple words, if they do not then they will be left out of the game altogether. So, all those startups, which do not have the expertise and talent, which can help them in using this digital technology, they usually approach experts and professionals such as Abtach, to help them with many things such as creating amazing digital marketing strategies and implementing them, developing highly engaging and captivating mobile apps to help in reaching out and engage target audiences and much more. 
Abtach also helps its clients across the planet with many other things such as the creation of amazing and engaging content, which can offer valuable information to the client’s target audience and help in driving their customers towards their products in the most passive but effective manner. In addition to all this, Abtach also has award-winning teams of professional and highly talented animators, who are responsible for creating some of the most highly engaging, creative and out of the box animated videos for their clients, which have helped their clients in building an amazing brand image in their customer’s eyes and allowed them to increase their sales, reputation, credibility and goodwill at the same time.
Furthermore, Abtach is a company, which believes in delivering much more than just professional digital services to its clients. They believe in serving their clients with all their hearts, delivering much more than what they have promised to their clients at the most affordable prices. Now, this is something that most IT companies simply cannot pull off. This is where Abtach is very different from the rest of the companies, who may even be delivering all the same services as them. Most of their competitors simply cannot offer the same level of sincerity and dedication to their target audience, which is where Abtach simply takes a lead. 
Moreover, if you are looking for a one window solution to all your business needs, then Abtach is and should be your go to place. If you are someone, who has just started up your business and you want to focus on your core business and leave the rest of the supporting functions in the capable hands of experts then there is no one better than Abtach.
Counting phrase in string.
Tags: javascript, help, webdev
Published: 2021-12-29 18:01:33

I found a way to find repetitive words and count that words in the text. But I can't find a way to find and count phrases in the text. Do you have any solution?

https://jsitor.com/nhY17bVsu


```
let str = `Tennis superstar Novak Djokovic has pulled out of the ATP Cup in Sydney, amid speculation about his vaccination status and whether he will defend his Australian Open title next month. World No.1 Novak Djokovic has withdrawn from the 2022 ATP Cup,” organisers said in a statement on Wednesday, ahead of the start of the tournament on Saturday.ennis superstar Novak Djokovic has pulled out of the ATP Cup in Sydney, amid speculation about his vaccination status and whether he will defend his Australian Open title next month. World No.1 Novak Djokovic has withdrawn from the 2022 ATP Cup,” organisers said in a statement on Wednesday, ahead of the start of the tournament on Saturday.`
let names = str.split(' ')

const count = names =>
  names.reduce((a, b) => ({
    ...a,
    [b]: (a[b] || 0) + 1
  }), {}) // don't forget to initialize the accumulator

const duplicates = dict =>
  Object.keys(dict).filter((a) => dict[a] > 1)

console.log(count(names)) // { Mike: 1, Matt: 1, Nancy: 2, Adam: 1, Jenny: 1, Carl: 1 }
console.log(duplicates(count(names))) // [ 'Nancy' ]


```
Release ScrcpyHub v1.3.0
Tags: android, kotlin, scrcpy, tooling
Published: 2021-12-29 17:56:21

## Introduction

ScrcpyHub is a GUI application to use scrcpy.

https://github.com/kaleidot725/ScrcpyHub

## Motivation

scrcpy is an Android device screen mirroring command tool.　scrcpy is a useful command tool, but multiple device mirroring is so difficult and bother.

1. Get android device using adb command.
2. Execute scrcpy command using -s option.

![2021-11-27 11-10-40.2021-11-27 11_11_40.gif](https://res.craft.do/user/full/3a21bd0e-fe7a-39aa-73ad-b52ef24b655b/doc/6995FDF2-2CF0-43F5-B9D3-C35F739FF92F/BB45EAD5-A33A-4C88-8243-24E6F425A2F6_2/2021-11-27%2011-10-40.2021-11-27%2011_11_40.gif)

## Features

ScrcpyHub assists in multiple device mirroring. ScrcpyHub makes it easy to do multiple device mirroring.

- Support Windows10 / 11 or macOS.
- Detect android device.
- Control mirroing (Start / Stop).
- Save Screenshot.
- Support Tary Menu.
- ***v1.3.0 NEW Feature : Record Movie.***

![2021-11-27 18-10-59.2021-11-27 18_12_53.gif](https://res.craft.do/user/full/3a21bd0e-fe7a-39aa-73ad-b52ef24b655b/doc/6995FDF2-2CF0-43F5-B9D3-C35F739FF92F/E0E18CA8-8A5C-4633-B72F-FBA8315D34BD_2/2021-11-27%2018-10-59.2021-11-27%2018_12_53.gif)

## New Feature : Record Movie

v1.3.0 support recording movie. You record easily movie with your Android Device. Try it.

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


## How to Use

### Install

Install adb and scrcpy, ScrcpyHub.

#### 💻 Mac OS

1. Install android-platform-tools and scrcpy.
2. Download [here](https://github.com/kaleidot725/scrcpy-hub/releases/tag/v1.3.0) and launch ScrcpyHub.
3. Open ScrcpyHub Preferences.
4. Input adb and scrcpy location, save settings.

```other
brew install android-platform-tools
brew install scrcpy
```

#### 💻 Windows 10 / 11

1. Download [here](https://github.com/Genymobile/scrcpy#windows) and install scrcpy somewhere.
2. Download [here](https://github.com/kaleidot725/scrcpy-hub/releases/tag/v1.3.0) and launch ScrcpyHub.
3. Open ScrcpyHub Preferences.
4. Input adb and scrcpy location, save settings.

![Image](https://res.craft.do/user/full/3a21bd0e-fe7a-39aa-73ad-b52ef24b655b/doc/137C802C-F06D-460A-BA71-9B94DAF64B71/83AAA09B-F6B5-425C-9CF7-FEA002375072_2/Image)

## 🔥Contact

We are working on the development [here](https://github.com/kaleidot725/ScrcpyHub). If you have any suggestions for improvement, please contact us.
Ethereum smart contract development using Solidity
Tags: blockchain, web3
Published: 2021-12-29 17:42:32

Today, I randomly came across a website called crypto zombies. 
![Image of Crypto Zombie website](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mh1rna7folzsu6pnz69a.png)
[crypto zombies](https://cryptozombies.io/)
It's a nice platform to learn solidity and smart contract dev. I completed a starting course (pretty easy if we know programming basics) which consists 15 chapters. Here r few learnings of today:

1. In every solidity program, we need to specify the version of language we are using in it using "pragma solidity <version>".

2. A smart contract or simply contract is a building block of an Ethereum app. It contains the variables, functions etc. just like a class in java/c++.

3. This contract is deployed on blockchain which acts as the backend of our decentralized app (dapp).

4. A contract once deployed on blockchain can't be modified. So, we need to be very careful when writing them.

5. There are many data types in solidity just like other programming languages.

6. Integers are broadly 2 types, signed (int) and unsigned (uint), there are different sizes as well (8, 16, .., 256 bits).

7. Strings are used to store from letters to sentences.

8. Arrays are also 2 types. Static and Dynamic. When we know we make changes to an array in runtime, we should use dynamic arrays as they provide push and pop functionality.

9. "function <name> (<arguments>) <access specifier> <function type> returns (<return type>){}".
Above is the syntax to write a function.

10. Public functions can be called from external contracts also and Private functions are restricted from doing it.

11. A pure type function can only access data which is passed to it as parameters.

12. A view type function can access data which is not passed to but present in that contract.

13. Struct is another data type which is user-defined which contains other variables in it.

14. Parameters can be passed in 2 ways to a function. Pass by value and Pass by reference.

15. To pass a parameter with reference, we need to give keyword "memory" before the name of argument.

16. We can create events, so that when that event occurs, we can perform certain things in our frontend.

17. "event <name> (arguments)". We can catch these events using web3JS.

18. To fire that event in a function, we use "emit <event name>".

19. Push method of dynamic array returns the size of array after pushing.

20.All this info in 20 mins read. Try it if u want to get started.

My twitter: [twitter](https://twitter.com/VChiranjeeviAK)
My LinkedIn: [linkedin](https://www.linkedin.com/in/chiranjeevi-tirunagari-685459191/)
My showwcase: [showwcase](https://www.showwcase.com/vchiranjeeviak)
how i can add timer to this code? any one help,
Tags: beginners, vscode
Published: 2021-12-29 17:42:26

Function Ping(strip)
Dim objshell, boolcode
Set objshell = CreateObject("Wscript.Shell")
boolcode = objshell.Run("ping -n 1 -w 1000 " & strip, 0, True)
If boolcode = 0 Then
    Ping = True
Else
    Ping = False
End If
End Function

Sub PingSystem()
Dim strip As String
Do Until Sheet1.Range("F1").Value = "STOP"
Sheet1.Range("F1").Value = "TESTING"
For introw = 2 To ActiveSheet.Cells(65536, 2).End(xlUp).Row
    strip = ActiveSheet.Cells(introw, 2).Value
    If Ping(strip) = True Then
        ActiveSheet.Cells(introw, 3).Interior.ColorIndex = 0
        ActiveSheet.Cells(introw, 3).Font.Color = RGB(0, 0, 0)
        ActiveSheet.Cells(introw, 3).Value = "Online"
        Application.Wait (Now + TimeValue("0:00:01"))
        ActiveSheet.Cells(introw, 3).Font.Color = RGB(0, 200, 0)
    Else
        ActiveSheet.Cells(introw, 3).Interior.ColorIndex = 0
        ActiveSheet.Cells(introw, 3).Font.Color = RGB(200, 0, 0)
        ActiveSheet.Cells(introw, 3).Value = "Offline"
        Application.Wait (Now + TimeValue("0:00:01"))
        ActiveSheet.Cells(introw, 3).Interior.ColorIndex = 6
    End If
    If Sheet1.Range("F1").Value = "STOP" Then
        Exit For
    End If
Next
Loop
Sheet1.Range("F1").Value = "IDLE"
End Sub

Sub stop_ping()
    Sheet1.Range("F1").Value = "STOP"
End Sub
Artificial intelligence in QA
Tags: ai, testing, sqa
Published: 2021-12-29 17:34:13


Artificial intelligence is increasingly visible in many fields, and so it is in quality assurance. AI is often presented as the perfect solution for every problem, but is that true? I believe everyone has to give credit to the power of AI in image analysis and unit/API/UI test automation. However, it is worth keeping in mind that this field of study is still far from reaching perfection. 

Currently, AI can resolve only specific problems, such as increasing test coverage levels in unit tests. AI testing automation has the potential for some companies to limit unnecessary costs in the supervision of software solutions and products. 

Besides cost reduction, AI in automation testing provides benefits like eliminating lone errors, which are more likely to escape the tester's eye.

How can you use the potential of AI test automation in 2022? 

- Visual testing to check UI design quality.
- Spidering - AI collects the data based on continuous website visits, so it can compare it later on for potential downgrades. It still needs a human touch in the end though.   
- For now, AI cannot provide full test coverage automatically. The current test production process is based on training on a specific dataset, with the test cases being generated later, with checking required by the tester. However, AI systems could take some of the testing load, reducing a lot of the repetitive work.

There are many reasons why this tech is predicted to be worth 310 billion dollars by 2026, and those mentioned above are only a few of them.

#qualityassurance #ai #automation #testing #artificialintelligence
Universalasync – create sync and async libraries at the same time maintaining one codebase
Tags: python, showdev, programming
Published: 2021-12-29 17:21:27

I would like to show my new Python library universalasync: https://github.com/bitcartcc/universalasync

## The problem

Async/await is become more and more popular in python and it makes sense to use it quite often to do something useful when waiting on network I/O. But it is not possible to use blocking (sync) libraries as it would block the whole event loop and defeat the purpose of asynchronous programming. So specialized libraries need to be created. In the same time, async is not always required, so a sync interface is demanded often for all the libraries.
For the library maintainers (like me) it causes an issue what to do. Often we need to maintain two codebases which differ only a little bit.

Some libraries create `async_*` variants of functions, or create classes like `AsyncClient` or use other methods of creating sync versions (for example in my another library some time ago I was just removing async and await and publishing this as a separate package, `mylib` and `mylib-async`).
The solution

The `universalasync` library provides utilities to help library maintainers create so-called "universal" libraries. You need to create only asynchronous version of your library, and synchronous version will be created automatically, so that users could use it in their sync and async apps interchangeably.

The library has 0 dependencies of course, it wraps all public methods of a class to it's implementation. It basically does what you would have done if you needed to run a coroutine from your sync code, but automatically.

Example:

```python
from universalasync import wrap

@wrap
class Client:
    async def help(self):
        ...

    @property
    async def async_property(self):
        ...

client = Client()

def sync_call():
    client.help()
    client.async_property

async def async_call():
    await client.help()
    await client.async_property

# works in all cases
sync_call()
asyncio.run(async_call())
threading.Thread(target=sync_call).start()
threading.Thread(target=asyncio.run, args=(async_call(),)).start()
```

API reference can be found here: https://universalasync.bitcartcc.com/en/latest/api.html

Any feedback, testing and bugs found welcome!