teleren/devto huggingface dataset:
React manejo de estado con objetos
Tags: javascript, react
Published: 2022-09-15 16:17:39

El manejo de estados en React es muy flexible pues permite manejar cualquier tipo de valor de Javascript pero no solo los de uso frecuente como son strings, booleans, numbers los cuales son inmutables es decir no se cambian en sentido profundo lo que se hace es una nueva representación para reemplazar un valor 

```javascript
const [name, setName] = useState("Kevin");

const [number, setNumber] = useState(7);

const [adult, setAdult] = useState(false);
```

Pero en ocasiones podemos tener más 5 estados que hacen referencia a una misma cosa en este caso puede ser persona y puede llegar a tener más atributos por lo tanto podemos manejarlo como un objeto, así se podría ver de una forma más sencilla que el ejemplo anterior multiplicado por 5 de modo que se puede quedar así

```javascript

const [persona, setPersona] = useState({name: "", number: null, adult: null});

```

Manejo más simple 

```javascript
import { useState } from 'react';

export default function Form() {
  const [person, setPerson] = useState({
    firstName: 'Barbara',
    lastName: 'Hepworth',
    email: 'bhepworth@sculpture.com'
  });

  function handleChange(e) {
    setPerson({
      ...person,
      [e.target.name]: e.target.value
    });
  }

  return (
    <>
      <label>
        First name:
        <input
          name="firstName"
          value={person.firstName}
          onChange={handleChange}
        />
      </label>
      <label>
        Last name:
        <input
          name="lastName"
          value={person.lastName}
          onChange={handleChange}
        />
      </label>
      <label>
        Email:
        <input
          name="email"
          value={person.email}
          onChange={handleChange}
        />
      </label>
      <p>
        {person.firstName}{' '}
        {person.lastName}{' '}
        ({person.email})
      </p>
    </>
  );
}

```


Referencias para profundizar:

https://beta.reactjs.org/learn/updating-objects-in-state

https://blog.logrocket.com/using-react-usestate-object/

https://daveceddia.com/usestate-hook-examples/
Exploring the application development tools | Catalyst 101 webinar
Tags: webdev, beginners, tutorial
Published: 2022-09-15 16:15:00

Catalyst 101 is a webinar series to educate the developer community on the Catalyst platform. The webinar series helps you familiarise yourself with this platform and empower you to build your serverless solutions quickly.

> Topic: Exploring the application development tools in Catalyst

> Date: September 22, 2022, 9 am - 10 am PDT | 9:30 - 10:30 pm IST

We are excited to launch the second episode of the Catalyst 101 webinar, scheduled for September 15th, 2022. Check out the [first episode](https://www.youtube.com/watch?v=O8vOXUg4yR0&themeRefresh=1) to understand what we covered. Looking forward to hosting you for the rest of the series!

[REGISTER FOR FREE WEBINAR](https://meeting.zoho.com/meeting/register?uId=664000084472376&utm_source=third-party&utm_medium=referral&utm_campaign=webinar)

**AGENDA**

- Explore the purpose of debugging environments and the tools available.
- Delve deep into the Catalyst console.
- Discuss Catalyst CLI setup and how to leverage the Catalyst SDKs.
- Dig into how to use the Catalyst REST APIs to build and deploy projects quickly.
Binary Numbers
Tags: binary
Published: 2022-09-15 16:13:21

The word binary comes from "Bi-" meaning two. We see "bi-" in words such as "bicycle" (two wheels) or "binocular" (two eyes). A Binary Number is made up of only 0s and 1s. For example 10100, which is decimal number 20. Every number is possible to be converted to binary. We start from 0 then go to 1 then 0 again but add 1 on the left. For example, 0 is 0, 1 is 1, 2 is 10, 3 is 11 and so on. A single binary digit (like 0 or 1) is called a "bit". For example 11010 is five bits long.
Lets say we want to convert binary number to decimal. To begin with, we write down the binary number and list the powers of 2 from right to left. Increment the exponent by one for each power. Then stop when the amount of elements in the list is equal to the amount of digits in the binary number. For example, we have the binary number 1010. Starting from the right we get 2 squared 0 times 0 + 2 squared 1 times 1 + 2 squared 2 times 0 + 2 squared 3 times 1 and we get 10. Now lets say we want to do the opposite convert decimal to binary. We take decimal number as dividend. Divide this number by 2. Store the remainder in an array (it will be either 0 or 1 because of divisor 2). Repeat this two steps until the number is greater than zero.
We add binary numbers just like we add other numbers, from right to left. For example we want to add two binary numbers 110 and 101, we get 1011. The subtraction happens same way.
In order to multiple two binary numbers we have to keep in mind four things
0 × 1 = 0
1 × 0 = 0
1 × 1 = 1
0 × 0 = 0
We multiply each digit of the second number by the first whole number, then we just need to add them, switching each resulting multiplication one digit to the left. Division also follows the same process as decimal numbers.
Error - Exception occurred during code generation for the WSDL
Tags: java, soap, wsdl
Published: 2022-09-15 16:02:33

I'm trying to generate the java classes from the .wsdl file, but when trying to generate the following error:

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


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



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


```
Exception occurred during code generation for the WSDL : java.lang.NoClassDefFoundError: org/apache/ws/commons/schema/utils/NamespacePrefixList
     java.lang.reflect.InvocationTargetException
```


In the pom I added the lib:

```
<dependency>
<groupId>org.apache.ws.xmlschema</groupId>
<artifactId>xmlschema-core</artifactId>
<version>2.2.1</version>
</dependency>
```

But the error remains.





Solution:

As decker's comment, I added the lib below in the pom and it worked, after that I managed to generate the class.

```
<dependency>
			<groupId>org.apache.ws.xmlschema</groupId>
			<artifactId>xmlschema-core</artifactId>
			<version>2.0.2</version>
		</dependency>
```
Catalyst by Zoho–Highly scalable developer platform
Tags: webdev, serverless, programming
Published: 2022-09-15 15:59:34

Hello all,

We at Catalyst are happy to be part of the developer community at Dev.to. We have created this dedicated space to connect, engage, network, and share insights to use the Catalyst platform.

Hoping that this page provides an ideal platform for you to ask questions, seek insights, and share your innovative ideas. Most importantly, we hope this page fosters connections between like-minded developers to learn, discuss and grow in the Catalyst developer space.

We are excited to keep you engaged by exchanging ideas, boot camps, tips and tricks, webinars, and anything under the roof to soar your developer productivity and enhance your developer experience.
Easily check if web service available outside the local network
Tags: webdev, selfhosting, portforwarding, devops
Published: 2022-09-15 15:35:54

## When is this relevant?
- If you have a web service on your local network you want check if its accessible publicly on the internet.

## What do i need?
- It's a bit of a hack, but you can use google translate as a proxy. From [here](https://translate.google.com/?sl=auto&tl=en&op=websites) in google translate you can get a url from which you can access your site's translated version. The site might not render properly but the important thing is that this url will always point to your website. So if this site is available so is yours and vice versa. 
- You can do a GET request and test for site availability in two ways. 
	- Do a keyword search if you know a word that should always appear on the site
	- Another way is to check the request's status code, if it's not 200 the site is most likely down. 
	- You can monitor this with a scheduled script that would notify you if the site is down, here's a simple python example:
	```python
	import requests  
	url="'translated' url"  
	keyword=""  
	r=requests.get(url)  
	if keyword not in r.text:  
	    print("send notification")  
	# or  
	if r.status_code!= 200:  
	    print("send notification")
	```
- For less headaches instead of a script i would suggest downloading [Uptime kuma](https://github.com/louislam/uptime-kuma) which is specifically made for checking website status, it supports status code and keyword checking and a lot more. It has a lot of options for notifications, not limited to but including Telegram, Discord, Gotify, Slack, Pushover, Email (SMTP) and it has a nice web ui.
- ![Uptime Kuma dashboard](https://camo.githubusercontent.com/9674a2b1b7d094b060fd79e6df7dca10b86a484ce6015b2668cff768dfc786ee/68747470733a2f2f757074696d652e6b756d612e7065742f696d672f6461726b2e6a7067)

## Soo
- I hope it was helpful in some way, if you have an alternative idea be sure to comment it below.
Omnisharp not working in vscode - fix
Tags: csharp, vscode, dotnet, azure
Published: 2022-09-15 15:33:17

My intellisense for vscode suddenly bailed out on me:

Before we start mucking about too much let's try some standard things to get it back up and running:

1. Reset the OmniSharp server - Command palette - OmniSharp: Restart OmniSharp.
2. Check that OmniSharp is looking at the right project - Command palette - OmniSharp: Select Project.

If neither of these work - follow on for another option:

Microsoft released a new version of the C# extension (v1.25) for vscode that breaks for older projects (the one I'm using is 2.1 :\ ). The tools required for it to work are no longer included in the extension - so you need to download them yourself.

1. In vscode go to settings (I used workspace settings) and search for "Omnisharp - use modern net" set this to off.
2. Mac: [Download](https://www.mono-project.com/download/stable/) and install Mono that includes the build tools (Visual Studio Channel).
   Windows: [Download](https://visualstudio.microsoft.com/downloads/) and install Visual Studio MSBuild Tools or a full Visual Studio version.

Restart vscode. I had restart the OnmiSharp server (see above) even after a restart of vscode itself.

If this helps a single person I'll be happy - I lost hours to this!
What is the Binary system? Conversion, addition and multiplication of the binary numbers.
Tags: binarynumbers, addition, multiplication
Published: 2022-09-15 15:31:44

One of the four types of the number system is the binary one. It describes numbers by only two digits: 1 and 0. A Binary digit or, as we call it, bit is the smallest unit of data. One bit represents either 1 or 0, which means it can’t take any other value. That is why it is called the base - 2 system. These digits are also called electric signals. In transistors, for example, 1 refers to a flow of electricity, and 0 refers to the lack of it.
In contrast to the binary system, decimal one is a base - 10 system, in which we use one of ten digits (0-9) to describe a number. And there are various methods for decimal to binary conversion. One of those methods is repeatedly dividing the decimal number by 2, and the remainders are written down till we get to the 0 quotients. After these steps, we need to write the remainders in reverse order to get the binary value of our decimal number. 
The following steps will guide you on how to do the inverse conversion from binary to the decimal system. Firstly, we should multiply each digit of our binary number by the base of 2, raised to the respective power depending on the digit’s position in the number. And the sum of all these values will be the decimal version of our binary number. 
With binary numbers, we can also do mathematical operations: multiplication, addition, subtraction, and division. 
In this post, I’ll explain how you can do only two operations: multiplication and addition. The same principle does these operations of binary numbers as with decimal numbers. 
Binary addition is considered much easier to do than decimal one. In order to add binary numbers, we add the first digit of the first number to the first digit of the second number, and so on. If we have 1+1, we should write 0 in the respective position and carry 1. 
Then comes the multiplication of binary numbers. The first step is multiplying the second number’s first digit with the first number. Afterward, we do the same with the second digit but write the result shifting it one digit to the left. After doing the same action with all of the digits of the second number, we should add them together, which is explained above. 
And this is how two mathematical operations are done in the binary numerical system.
How to extend enum in TypeScript
Published: 2022-09-15 15:17:33

From time to time you need to extend an enum in TypeScript, however, we can't use `extends` construction like in case of  `interface`.

```typescript
enum MySuperEnum {
  ONE,
  TWO
}

enum MyMoreSuperEnum extends MySuperEnum // This is wrong
```

Of course, we can create one more enum and then create union type:

```typescript
enum MySuperEnumExtender {
  THREE
}

type MyUnionType = MySuperEnum | MySuperEnumExtender;

```

What we can get and why this approach is not good? `MyUnionType` is a type, we can't use it like enum to call its props.

**So what we can do then?**

First of all, we should use another and more preferable way of enum implementation with `const`. [Why?](https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums)

```typescript
// describe an enum object
const  MySuperEnum = {
  ONE: 'ONE',
  TWO: 'TWO'
} as const

// create the MySuperEnum type
type MySuperEnum = typeof MySuperEnum[keyof typeof MySuperEnum];
```

What is `as const`? Please [click](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions) to find out more. 

Cool! Now our `MySuperEnum` is defined in a different way! 

It is time to create new `MyMoreSuperEnum` that will be extended with `MySuperEnum`.

```typescript
// describe an enum object
const  MyMoreSuperEnum = {
  ...MySuperEnum,
  THREE: 'THREE'
} as const

// create the MyMoreSuperEnum type
type MyMoreSuperEnum = typeof MyMoreSuperEnum[keyof typeof MyMoreSuperEnum];
```

Profit. Hope this trick will be useful for you.
React Hooks useContext con createContext
Published: 2022-09-15 15:17:10

![reacthook](https://user-images.githubusercontent.com/47307889/116921331-826bbe80-ac5c-11eb-9f48-d8fbde144b04.png)

Para poder hacer uso de este hook de React es necesario implementar 3 sencillos pasos. Lo primero sería crear un archivo donde vivirá el contexto para toda nuestra aplicación, para este ejemplo lo llamaremos **Contexto.jsx**. 
Hacemos la importación de los hooks  a utilizar para este ejemplo

```javascript
import {createContext,useContext,useState} from 'react'
```
1. Definimos el contexto
```javascript
const Appcontext = createContext({
  items:[],
  create:()=>{}
})
```
Dentro estamos nombrando las operaciones que van a vivir dentro del contexto las cuales van a poder ser accedidas desde los otros componentes.

2. Implementación
```javascript
export default function Contexto({children}){
  const [items,setItems]= useState([
    {
      id: 0,
      title: 'empezar'
    },
    {
      id:1,
      title: 'terminar'
    }
  ])

  function create(item){
    setItems([...items,item])
  }

  return(
    <AppContext.provider
    value={{
      items,
      create,
    }}
    >
      {children}
    </AppContext.provider>
  )
}
```
Va a recibir como **prop** la palabra **children**  que hace referencia a los hijos que va a contener en este caso la función **contexto**.
Dentro del mismo archivo que estamos trabajando vamos a crear la función que va a contener los metodos y operaciones que se quieran llevar a cabo y que serán ejecutadas desde los componentes que necesiten acceder a ellas.
Por ultimo en el return hacemos el llamado a **<AppContext.provider>** para pasar como **props** la información del componnete y el **<chlindren>** quien dibujara los elementos contenidos.

3. Adicionalmente podemos crear una función que haga el llamado a el contexto para con esto únicamente tener que invocarla dentro de los componnetes que necesiten acceder a la información.

```
export function useAppContext(){
  return useContext(Appcontext)
}
```
Ahora para poder hacer uso de este *Hook* dentro del componente **APP.jsx** hacemos la importación del componnete **Contexto.jsx** y envolvemos dentro de este al componente que queramos que tenga acceso a lo establecido dentro de **Contexto.jsx**, en este caso será el componente **Todo**

```javascript
import Todo from './components/Todo'
import {Contexto} from './components/Contexto'

function App() {
  const [count, setCount] = useState(0)

  return (
    <div className="App">
      <h2>Provider</h2>
      <Contexto>
        <Todo/>
      </Contexto>
    </div>
  )
}

export default App
```
Para finalizar en el componente **Todo.jsx** importamos el **useAppContext** para poder acceder y modificar los elementos del contexto.

```javascript
import { useAppContext } from '../utils/Contexto'

export const Todo = () => {
    const contexto = useAppContext()
  return (
    <div>
     <p>conexto.items[0]</p>
    </div>
  )
}
```

## 👽 Espero sea útil esta información, no olvides dejar tu comentario y dar like :)👽

👀👀👀👀También pueden seguirme en [tiktok](https://www.tiktok.com/@avxc.dev?_t=8VMXUQ1YSBh&_r=1)👀👀👀👀
60 Days of Data Science and Machine Learning
Tags: datascience, ai, machinelearning, python
Published: 2022-09-15 14:55:20

Hello, everyone.

Followings are fifth week of this series. You can find them on my [GitHub](https://github.com/thunderstroke325/60-Days-of-Data-Science-and-ML). You can run all the notebook on colab or jupyter notebook as well.

- [Day 31 - Machine Learning Linear Regression](https://github.com/levintech/60-Days-of-Data-Science-and-ML/blob/main/Day_31_Machine_Learning_Linear_Regression.ipynb)

    Topic : Univariate linear regression

- [Day 32 - Multiple Linear Regression](https://github.com/levintech/60-Days-of-Data-Science-and-ML/blob/main/Day_32_Multiple_Linear_Regression_.ipynb)

    Topic : Multiple linear regression

- [Day 33 - Logistic Regression Project1](https://github.com/levintech/60-Days-of-Data-Science-and-ML/blob/main/Day_33_Logistic_Regression_Project1.ipynb)

    Topic : Logistic Regression

- [Day 35 - Principle Component Analysis](https://github.com/levintech/60-Days-of-Data-Science-and-ML/blob/main/Day_35_Principal_Component_Analysis.ipynb)

    Topic : Principle Component Analysis

- [Day 36 - Advanced Regression Techniques Part1](https://github.com/levintech/60-Days-of-Data-Science-and-ML/blob/main/Day_36_Advanced_Regression_Techniques_Part1.ipynb)

    Topic : Advanced Regression Techniques

- [Day 37 - Advanced Regression Techniques Part2](https://github.com/levintech/60-Days-of-Data-Science-and-ML/blob/main/Day_37_Advanced_Regression_Techniques_Part2.ipynb)

    Topic : Advanced Regression Techniques

- [Day 38 - Support Vector Machine](https://github.com/levintech/60-Days-of-Data-Science-and-ML/blob/main/Day_38_Support_Vector_Machine.ipynb)

    Topic : SVM (Support Vector Machine)

- [Day 39 - Scikit-learn](https://github.com/levintech/60-Days-of-Data-Science-and-ML/blob/main/Day_39_Scikit_learn.ipynb)

    Topic : Basics of Scikit learn

- [Day 40 - Tensorflow](https://github.com/levintech/60-Days-of-Data-Science-and-ML/blob/main/Day_40_Tensorflow.ipynb)

    Topic : Basics of Tensorflow


Hope my work would be little bit helpful for AI enthusiastic.
If that, please **star** that repository then **follow** me on **Github** and **Dev.to**

https://github.com/levintech
https://dev.to/levintech
Best Regards.
Extension Function
Published: 2022-09-15 14:50:52

Kotlin gives the programmer the ability to add more functionality to the existing classes, without inheriting them.

This is achieved through a feature known as extensions.

When a function is added to an existing class it is known as Extension Function.

To add an extension function to a class, define a new function appended to the class name.

For Example : 

```
fun main() {
 val list = mutableListOf(1,2,3,4)
 list.swap(0,2)
 print(list)
}
fun MutableList<Int>.swap(index1: Int, index2: Int) {
    val tmp = this[index1] // 'this' corresponds to the list
    this[index1] = this[index2]
    this[index2] = tmp

}
```

 ` Output : [3,2,1,4]`
Validations in Ruby on Rails
Tags: ruby, rails
Published: 2022-09-15 14:49:45

Validations are basically used to check and see if the data that is sent through your application is what you expected it to be.

You can basically think of it like a data filter, and there are many validation helpers you can use. Here are a few that I find useful:

```
class Teenager < ApplicationRecord
  validates :age, comparison: { greater_than_or_equal_to:13,
less_than_or_equal_to: 19}
end

```this is used to compare the data to parameters that you set. In the example above we are validating if someone is considered a teenager by comparing the data we get to the parameters set and if the integer is between 13 and 19 it will pass the validation.

```
class Salsa < ApplicationRecord
  validates :spice, inclusion: { in: %w(mild medium hot),
    message: "%{value} is not a valid spice level" }
end
```this is used to give a specific piece of data that must be included. In the example above the data enter must include mild, medium, or hot or it will not pass the validation. (a side note: the %w(data) used above is the same as [data] in ruby.)

```
class EmployeeDinner < ApplicationRecord
  validates :name, length: { minimum: 2 }
  validates :employee_number, length: { is: 9 }
  validates :menu, length: { maximum: 1000 }
  validates :times_attended, length: { in: 1..15 }
  
end

```this is used to give a specific length for whatever you are validating. In the example above the name has a minimum of 2 so the string must be longer than 2 characters, the employee_number is setting a specific value of 9 so it cannot be anything more or less that 9 characters, the menu is setting a maximum character limit of 1000, and times_attended is giving a range of anywhere between 1 and 15.

There are many different options for validations and they are all useful and unique it is worth taking the time to learn what each of them can do. I have only included 3 here, but there are many more. I have included a link below that goes over validations in far more detail. Hope this is helpful!

source: https://guides.rubyonrails.org/active_record_validations.html
A Bash script to configure Linux
Tags: linux, bash, script, security
Published: 2022-09-15 14:43:58

I made a Bash script to configure Debian-based Linux machines for cybersecurity:

{% embed https://github.com/jmau111-org/golinux %}

The script is quite straightforward:

```
git clone https://github.com/jmau111-org/godebian
cd godebian
sudo -s
bash godebian
```

I've included a way to opt out of some specific steps.

Of course, it's not exhaustive at all, and I like to keep it very light, without too much third-party apps. It's **cybersecurity-oriented**, but even in that perspective, it's pretty light.
Kotlin Flows On android
Published: 2022-09-15 14:42:15

In [Coroutines](https://dev.to/janakbist/coroutines-3m4l), a Flow is a type that can emit multiple values sequentially as opposed to suspend functions that return only a single value.

For Example : we can use Flow  to receive live updates from database.

Flows are built on top of coroutines and can produce multiple values.

A flow is conceptually a stream of data that can be computed asynchronously. The emitted values must be of the same type. For example, a `Flow<Int>` is a flow that emits integer values.