teleren/devto huggingface dataset:
Lambda expressions in python
Tags: programming, tutorial, python, beginners
Published: 2021-01-29 16:11:00

Lambda expressions in python are one-time anonymous functions which we don't need more than once.

Consider the following example where we use a function to multiply a list of numbers with the mathematical constant pi:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cddv78unsuwiwfbw890y.png)

Output:
```
[3.14, 6.28, 9.42]
```

What if I say that we could do all of this in one line.
Well, it turns out we can do it.
We can convert the above example into a single line of code using *Lambda expressions*.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/1mwdlksnzbkrm75fpxoi.png)

Output:
```
[3.14, 6.28, 9.42]
```


## Lambda function
Syntax: `lambda arguments : expression`

* A lambda function can take any number of arguments, but can only have one expression:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/tbrruohlgfjdrb3nwu7h.png)

Output:
```
94
```


## Why do we need to use Lambda functions?
* Well, it contributes to the code by reducing the number of lines of functions which we may use only once.
* To take it to the next level, we can return an anonymous function inside another example:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/i43fua0ehhc72hc5evlp.png)

Output:
```
62.800000000000004
119.32000000000001
31.400000000000002
```
As you can see, we got to use the same function to calculate different values.
You get to create a function definition that takes one argument, and that argument will be multiplied with an unknown number (which you can specify in the future).

That's the power of lambda expressions.

### Best Resources

- [Python Blog Series](https://dev.to/aswin2001barath/series/10416) : A Blog series where I will be learning and sharing my knowledge on each of the above topics.

- [Learn Python for Free, Get Hired, and (maybe) Change the World!](https://academy.zerotomastery.io/a/aff_tz1t0tpx/external?affcode=441520_dcwk-s8s) : A detailed roadmap blog by Jayson Lennon (a Senior Software Engineer) with links to free resources.

- **Zero To Mastery Course** - [Complete Python Developer](https://academy.zerotomastery.io/a/aff_9khypm7v/external?affcode=441520_dcwk-s8s) : A comprehensive course by Andrei Neagoie (a Senior Developer) that covers all of the above topics.

**Who Am I?**

I’m Aswin Barath, a Software Engineering Nerd who loves building Web Applications, now sharing my knowledge through [Blogging](https://medium.com/techsoftware) during the busy time of my freelancing work life. Here’s the link to all of my socials categorized by platforms under one place: https://linktr.ee/AswinBarath

**Thank you** so much for reading my blog🙂.
Auto Reconnect(ing) OpenVPN client connections on EdgeOS
Tags: edgeos, edgerouter, ubiquiti, router
Published: 2021-01-29 16:08:00

EdgeOS should automatically reconnect your OpenVPN client tunnel. If it doesn't, there are two things you can add to your OpenVPN client config that will make the client reconnect when it's down (eg. because the server or your internet connection has been down).

1. You can let your EdgeOS router ping over the VPN connection, and if it's down, reconnect it
2. Tell EdgeOS (OpenVPN client) not to store Auth Tokens, and always perform full auth after reconnecting.

Especially #2 is a problem for some, and hard to debug. You know this is happening if your log files show something like this:

```
grep "AUTH" /var/log/messages
```

#### Response:

```
messages:Month Day Time Hostname openvpn[id]: AUTH: Received control message: AUTH_FAILED
```

Let's add the `ping` setting to ping and auto-reconnect, and tell the EdgeOS OpenVPN client to ignore 'auth tokens' received (for a full re-auth on reconnect) assuming your OpenVPN client tunnel is `vtun1`. Then commit, save and exit.

```
configure
set interfaces openvpn vtun1 openvpn-option "--ping 10"
set interfaces openvpn vtun1 openvpn-option "--ping-restart 60"
set interfaces openvpn vtun1 openvpn-option "--pull-filter ignore auth-token"
commit; save; exit
```

Optionally you can add these settings to your `.ovpn` client config as well, without the prefixed double dash. Eg. edit your client `.ovpn` file, and add these lines to your client config:

```
ping 10
ping-restart 60
pull-filter ignore auth-token
```
How to use the fileReader to show a file with Javascript
Tags: javascript, webdev, filereader, files
Published: 2021-01-29 16:04:05

# **🤔 What is the fileReader ?**
"The FileReader object lets web applications **asynchronously** read the contents of files (or raw data buffers) stored on the user's computer, using File or Blob objects to specify the file or data to read." - MDN web Docs

# **🤔 So how does it work ?**
The user use an upload type input to transfer the data, when we upload it we'll use a addEventListener onChange like this:

# **💻 A real exemple**

Here I'm making a poll app, and before sending the datas into the db, I'm letting the user see the result, I'm using react but this does not really matter, you can do it with vanilla Javascript

## **HTML side**
Here I'm creating a html input element with the type file, I'm using onChange because I'm using react, I'd rather recommend you to add an event listener for the input if you're using something else than react

### React way

```html
<input 
id="form__cover" 
type="file" 
onChange={(e) => handleFiles(e, 0)}></input>
```

### Vanilla way

```html
<input 
id="form__cover" 
type="file"
></input>
```

And then into the Javascript:

```javascript
const input = document.getElementById("myElement");
input.addEventListener("change", function(){
  //Do something in it
});
```

## The fileReader
```javascript
const handleFiles = (e) => {
    const reader = new FileReader();
    let file = e.target.files[0];
```

So in the code above we:
- First declare the variable reader equals to a new Filreader Object / Instance
- Then with define the file equals to the e (event) target (the element targeted) and then the files[0] because we can have an input with multiple files

```javascript
  reader.readAsDataURL(e.target.files[0]);
    reader.onload = function () {
      console.log(reader.result);
    };
    reader.onerror = function () {
      console.log(reader.error);
    };
```

We then here first read the data as Data URL, so the data can be read by the browser as a blob, then we:
- Add an event listener for reader wich listen to the load event and then pass a callback function wich will console log the URL of the file
- Add a error handling with the on error wich is an event listener for error, we then pass a callback function as well and console.log the error returned by the reader 

# Conclusion
Using this is really interesting since we can for exemple display a profile picture selected by the user before sending it to the DB, wich allow the user to have a better feedback and not wait until the page has been reload or the server sent back the data

Thank you for reading this article 🙏, I hope this was helpful for you
Force Reconnect OpenVPN client connections (commandline) on EdgeOS
Tags: edgeos, edgerouter, ubiquiti, router
Published: 2021-01-29 15:55:33

If your EdgeOS router has one or more OpenVPN **client** connections configured, you may want to restart the OpenVPN connection at some point. Either because it is down and somehow doesn't come back and you want to force that, or because you simply want it to restart (and pick up new settings / IP / ...).

In the EdgeOS web interface you can simply disable and re enable the VPN interface, but on the commandline it's not that easy.

Let's say your OpenVPN client connection is `vtun1`. To restart the connection the easy way, simply create (you can do this the easy way after [installing the nano text editor](https://dev.to/wietse/install-nano-on-edgeos-2-x-3e7j))a script somewhere (eg. in `/config/scripts`. Let's call it `restart-ovpn.sh`.

The contents of the `restart-ovpn.sh` file (assuming your SSH client connection is `vtun1`) should be:

```
#!/bin/bash
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper begin
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper set interfaces openvpn vtun1 disable
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper commit
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper delete interfaces openvpn vtun1 disable
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper commit
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper end
logger -t piareset openvpn restarted
```

This scripts start a config session, disables the OpenVPN client, commits, deletes the disable flag, commits again, ends the config session and then writes a logline (for future reference).

You can now make the script executable:

```
chmod +x restart-ovpn.sh
```

... and the next time you want to restart your OpenVPN client connection on the commandline, simply run (from the folder where you created the `restart-ovpn.sh` file):

```
./restart-ovpn.sh
```
Unity Multiplayer Tutorial - Send Back Data to Clients
Tags: multiplayer, client, udp, server
Published: 2021-01-29 15:54:29

In this video I'll show you how to enable your client to receive data from the server so you can update your client on whats going on with the other clients!
we will do small refactoring as always :) and use delegates to make our life a bit eaiser
Enjoy!

{% youtube HR_apl1pKHc %}

> Like this post? 
> Subscribe to my [YouTube Channel](https://www.youtube.com/channel/UCVUNeBGM5wZJKcOx0QwAaTA?sub_confirmation=1)
> You can also follow me on [Twitter](https://twitter.com/elbaz_eran)
Know about Affiliate Marketing by RevGlue.com
Published: 2021-01-29 15:45:06

![Pros and Cons of Affiliate Marketing](https://dev-to-uploads.s3.amazonaws.com/i/slc6p6lzpczhltjejnjl.jpg)

Link to read further about [Pros and Cons of Affiliate Marketing](https://www.revglue.com/blog-detail/52-the-pros-cons-of-affiliate-marketing-for-affiliate-marketers-infographic)
When to refactor?
Tags: dotnet, csharp, refactorit
Published: 2021-01-29 15:44:53

# When should I refactor?
 
Always. 
 
Not kidding.
 
Have you ever experienced a situation when there was a small piece of functionality that had to be added to existing code?
 
Did you then think that if you would change the existing structure, just a little bit, it would be piece of cake to add the new feature here?
 
That was the right thinking. It’s a way better direction to take instead of copy-pasting function and changing only the piece of code that you need.
 
This way the code would end up with duplicated logic, which needs to be changed in multiple places, whenever business logic changes (and you have to find that code in multiple places).
 
## Seriously always?
 
Well. There’s a but.
You should have tests.
 
Either way, how can you verify that one of the key aspects of refactoring is fulfilled?
 
The one that is saying there’s no change in observable behavior.
 
If you don’t have tests, write them before you start.

 There are three major benefits of that:
1. The test will let you know whenever you broke functionality, so you’ll have to do more confidence doing small changes
2. You’ll get to understand code better
3. Tests often lead to simple & elegant solutions
 

Do you do continuous refactoring?
Reload BGP routes / configuration on your EdgeRouter
Tags: edgeos, edgerouter, ubiquiti, router
Published: 2021-01-29 15:43:37

So you updated your BGP configuration and your EdgeRouter doesn't reflect your updates? Or the BGP service seems to have stopped and doesn't come back?

You run into this if you have BGP configured, but all `show ip bgp` commands return nothing, eg.:

```
show ip bgp summary
```
... results in just a newline and even stopping* & starting* the BGP service doesn't help.

A workaround is to save your existing config, delete the bgp settings, `commit` (that'll get EdgeOS to disable BGP), reload (`load`) your config (with BGP settings), `commit` (that'll get EdgeOS to restart EdgeOS with the most recent BGP config).

```
configure
save
delete protocol bgp
commit
load
commit
exit
```

### *) Starting/Stopping the BGP service

When not in a `configure` session:

```
/etc/init.d/vyatta-quagga stop bgpd
/etc/init.d/vyatta-quagga start bgpd
# or:
/etc/init.d/vyatta-quagga force-reload bgpd
```
Enable key based SSH login to your EdgeRouter
Tags: edgeos, edgerouter, ubiquiti, router
Published: 2021-01-29 15:37:08

If you want to login to your EdgeOS router using your SSH identity instead of a password, you can. Make sure you already have your SSH identity (key, pubkey). You'll need your pubkey later on to whitelist it in your EdgeOS config.

To configure SSH login using your your ssh key instead of a password, SSH into your EdgeRouter:
```
ssh {your-webinterface-username}@{your-router-ip} -p 22
```
Eg. `ssh johndoe@192.168.1.1 -p 22`

When logged in, start configuration mode:

```
configure
```

This tutorial assumes your username (to access the EdgeOS web interface (and SSH, just now)) is `johndoe`, replace `johndoe` with your actual username.

Now configure your SSH login key type:

```
set system login user johndoe authentication public-keys johndoe@device type ssh-rsa
```

Eg. `set system login user myAdminAccount authentication public-keys myAdminAccount@myMacbook type ssh-rsa`

Now add your public key. The value to add after `key` in the command below should be the Base64 string that's usually in your `id_rsa.pub`, without the `ssh-rsa` prefix, and without the hostname@device appended.

On OSX you can get this value using:
`cat ~/.ssh/id_rsa.pub|cut -d " " -f 2`

```
set system login user johndoe authentication public-keys johndoe@device key AAAAB.........
```

Now commit your settings:

```
commit
```

Open a second terminal window to check if you can sign in using your SSH identity, without a password. If everything works, you can save & exit:

```
save; exit
```

### Done 🎉
Property 'maxCount' does not exist on type 'IntrinsicAttributes
Tags: react, typescript
Published: 2021-01-29 15:36:15

I am trying to implement antd upload button functionality in tsx file but for some reason I am getting the **following Typescript error**. 

I have also created an interface for the same but no luck. Please suggest me where I am doing it wrong. Thanks

 ```
Type '{ children: Element; maxCount: number; }' is not assignable to type 'IntrinsicAttributes & UploadProps<any> & { children?: ReactNode; } & RefAttributes<any>'.
      Property 'maxCount' does not exist on type 'IntrinsicAttributes & UploadProps<any> & { children?: ReactNode; } & RefAttributes<any>'
```
**Here is the code**

    interface IMyProps {
        maxCount: number,
        }
        
    const AdminPage: React.FC<IMyProps> = ({maxCount}) => {
          const [isModalVisible, setIsModalVisible] = useState(false);
        
            const onFinish = (values:any) => {
              console.log(values)
             };
            return (
                <React.Fragment>
                <div>
                    <Modal title="Create" visible={isModalVisible} footer={null} onCancel={()=>setIsModalVisible(false)}>
                        <Form layout="vertical" onFinish={onFinish}>
                            <Form.Item label="Upload" name="uploading" >
                                <Upload  maxCount={1}> <---------------- GETTING ERROR HERE
                                    <Button icon={<UploadOutlined />}>Click to Upload</Button>
                                </Upload>
                            </Form.Item>
                            <Form.Item>
                                <Button type="primary" htmlType="submit">
                                    Submit
                                </Button>
                                </Form.Item>
                        </Form>
                    </Modal>
                </div>
              </React.Fragment>
              )
        }
        
        export default AdminPage;
How to make simple password manager in python
Tags: python, datascience, buygme
Published: 2021-01-29 15:34:10

##Hello!!!

In this post I will tell you how to make a simple password manager in python. So let's get into.

As First thing we need to do is set your password for password manager and add user Input, so you can type the password.
``` 
Password = "1111"
PasswordGues = input("Password: ")
```
Next Thing we need to add is if statement, which checks if the entered password is correct.

```
Password = "1111"
PasswordGues = input("Password: ")
if(Password == PasswordGues):
```
And Now we can Print our password for reddit for example.

```
Password = "1111"
PasswordGues = input("Password: ")
if(Password == PasswordGues):
print("Reddit Password: BUY_GME")
```

Now we have all done!

Thanks for reading my article. If was this helpfull, you can leave a like or you can buy me a coffee. Thanks!
[![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/i8comzg9c1cp3pnksqwv.png)](https://www.buymeacoffee.com/vector3studio)
🔥 Top 10 Most Useful Coding Tools & Resources Every Programmer 👨🏻‍💻 Should Know 🤔
Tags: coding, programming, productivity, todayilearned
Published: 2021-01-29 15:23:27

## Hello Everyone!!!

In this post, I will tell you some awesome tools that every programmer should know. These tools are very useful & can increase your productivity.

### 10. Learning Platforms
- [Udemy](https://www.udemy.com/)
- [YouTube](https://www.youtube.com/)
- [Coursera](https://www.coursera.org)
- [Microsoft Learn](https://docs.microsoft.com/en-us/learn/)

### 9. Discussion Forums
- [Stack Overflow](https://stackoverflow.com/)
- [Stack Exchange](https://stackexchange.com/)
- [Quora](https://www.quora.com/)

### 8. Competitive Programming
- [HackerRank](https://www.hackerrank.com/)
- [HackerEarth](https://www.hackerearth.com/)
- [CodeChef](https://www.codechef.com/)
- [LeetCode](https://leetcode.com)

### 7. Frontend Portfolios
- [Wix](https://www.wix.com/)
- [Strikingly](https://www.strikingly.com/)
- [Squarespace](https://www.squarespace.com/)

### 6. Databases
- [FireBase](https://firebase.google.com/)
- [Realm](https://realm.io/)
- [MySQL](https://www.mysql.com/)

### 5. Quick Resume Builders
- [NovoResume](https://novoresume.com/)
- [Resume.com](https://www.resume.com/)
- [ResumeGenius](https://resumegenius.com/)
- [Overleaf](https://www.overleaf.com)

### 4. Design Tools
- [Canva](https://www.canva.com/)
- [Sketch](https://www.sketch.com/)
- [Adobe XD](https://www.adobe.com/in/products/xd.html)

### 3. Design Resources
- [FreePik](https://www.freepik.com/)
- [FlatIcon](https://www.flaticon.com/)
- [ColorHunt](https://colorhunt.co/)

### 2. Team & Project Management
- [Slack](https://slack.com/)
- [Trello](https://trello.com/)
- [Atlassian Jira](https://www.atlassian.com/)
- [Asana](https://asana.com)

### 1. Code Management
- [GitHub](https://github.com/)
- [DropBox](https://www.dropbox.com/)
- [Atlassian](https://www.atlassian.com/)
- [GitLab](https://about.gitlab.com)

### 0. Real Coding Experience
- [Internshala](https://internshala.com/)
- [Freelancer](https://www.freelancer.com/)
- [Fiverr](https://www.fiverr.com/)

## To sum it all...
These are some useful resources that can increase your productivity. If you like it, please share it with your friends & leave comments below. In the next part, I will post detailed information about these platforms that will explain to you how to use it.

## Thank You !!!
URI | URL | URN
Tags: beginners, webdev
Published: 2021-01-29 15:15:16

#### The world of Uniform Resource ___

![sum-up](https://media.geeksforgeeks.org/wp-content/uploads/20200205203241/gfg30.jpg)

**Here the word `resource` could be anything, take it as a img on your computer for easier understanding**

### URI 

- `URI` stands for *Uniform Resource Identifier*
- A `URI` contains two things
  - Name
  - Location
- We need URI so identify the resource from its name and also be able to locate it using location

### URL

- `URL` stands for *Uniform Resource Locator*
- This is basically the address of the resource.

### URN

- `URN` stands for *Uniform Resource Name*
- This is basically the name of the resource.


**Therefore : `URI = URL + URN`**

The URI generic syntax consists of a hierarchical sequence of five components

```
URI = scheme:[//authority]path[?query][#fragment]
```

where the authority component divides into three subcomponents:

```
authority = [userinfo@]host[:port]
```

```
             host   port
          ┌───┴───┐ ┌─┴┐
  https://localhost:8080/forum/q/?tag=networking#top
  └─┬─┘   └───────────┬──────────────┘└───────┬───────┘ └───────────┬─────────────┘ └┬┘
  scheme          authority                  path                 query           fragment
```

I hope you like this article !
Hiring: Experienced, full-stack developer
Tags: hiring, python, career
Published: 2021-01-29 15:15:11

## About Us
Ipsos is a publicly-traded company with 18,000 employees.


## About The Opportunity
We need an experienced, full-stack developer (back-end required, front-end desired) with proficiency in python and ETL. Please see the following link:
https://jobs.silkroad.com/Ipsos/Careers/jobs/5403

## Skill & Qualifications
Python, ETL, APIs, containers, front-end, back-end

## How To Apply
Please apply here:
https://jobs.silkroad.com/Ipsos/Careers/jobs/5403


_Please feel free to leave questions in the comments section._
[Idea] Troubleshooting CLI - What do you think?
Tags: discuss, idea, troubleshooting, cli
Published: 2021-01-29 15:09:59

I thought of creating an open-source project which includes a Troubleshooting CLI application that supports macOS, Linux, and WSL2 (Linux VM on Windows).

This CLI will assist DevOps engineers to perform an analysis on common issues (challenges), without the hassle of repeating common tasks.

I call it **tbs** (troubleshooting)

As always, it's easier to explain with an example -

```
$ tbs --help

Usage:
tbs vendor service-name action [-arg, --argument]

# Example:

$ tbs aws efs mount --id my.efs.id --efs-mount /data --local-mount-path /home/ubuntu/data
[DOCS] https://docs.aws.amazon.com/efs/latest/ug/troubleshooting-efs-mounting.html
[LOGS] Describe EFS
[LOGS] Describe VPC
[LOGS] Check if EFS is available (provisioned)
[LOGS] Check if DNS support is enabled in VPC
[LOGS] Check if EFS is reachable from local machine - ping
[LOGS] Check if EFS DNS can be resolved from local machine
[LOGS] Attempt to mount EFS on local machine
[RSLT] DNS support needs to be enabled in the VPC - my-vpc-id
```

What do you think? Is this something that you'll use? I'd love to hear your opinion