teleren/devto huggingface dataset:
Lambda Expressions
Tags: python, beginners
Published: 2020-02-16 01:39:36


You can create small anonymous functions in <a href="https://python.org">Python</a> using *the lambda keyword*. 

By anonymous I mean it doesn't need to have a name, normal <a href="https://pythonbasics.org/functions/">functions</a> start with the *def* keyword and require a name.A lambda expression is not a statement, it returns a value.

Lets say you want a function that returns the sum of its two arguments
Imagine you have a simple function like this:

```python

def sum(a,b):
    return a+b
```
That is quite a lot to write. 

## Lambda expressions

Instead you can create a lambda expression like the example below. 
A lambda function that adds two variables as an argument and prints the result:

```python
lambda a, b: a+b
```

You can then use it like this:

```python
>>> f = lambda a,b : a+b
>>> f(2,3)
5
>>> f(10,15)
25
>>> 
```

You can create all kinds of lambda expressions, this is a lot shorter to write than creating functions for tiny operations.

```python

# A lambda function that adds 10 to the argument
x = lambda a : a + 10
print(x(8))

# A lambda function that multiplies two variables
x = lambda a, b : a * b
print(x(8, 9))

# A lambda function that sums its arguments
x = lambda a, b, c : a + b + c
print(x(1, 2, 3))
```
IntelliJ - Error:java: release version 5 not supported
Tags: java, intellij, troubleshooting
Published: 2020-02-16 01:25:58

---
title: IntelliJ - Error:java: release version 5 not supported
published: true
description: Troubleshooting IntelliJ error with Java release version
tags: java, intellij, troubleshooting
---

A common error in IntelliJ when attempting to run a new Java maven project is `Error:java: release version 5 not supported`.

Here are 3 techniques to resolve this. Try them in order. If one doesn't resolve the issue, try the next.

## 1. Update Java Compiler

   * Go to IntelliJ IDE menu item (or File on Windows) -> Preferences -> Build, Execution, Deployment -> Java Compiler

   
   * Delete value under Target bytecode version, then click OK


     <img src="http://angiejones.tech/wp-content/uploads/2020/02/intellij-compiler.png">

   
   * Refresh maven
   
     <img src="http://angiejones.tech/wp-content/uploads/2020/02/intellij-refresh-maven.png">


   * Try running again. If problem persists, continue on to number 2 below



## 2. Update SDK Version

   * Go to File -> Project Structure -> Project Settings -> Project. Make sure you have the correct Java version selected. It should be the same as the one you downloaded
   
   * Also on this same panel, go to Platform Settings -> SDKs. Make sure you have the correct Java version selected
   
   * Click OK
   
   * Refresh maven
   
    <img src="http://angiejones.tech/wp-content/uploads/2020/02/intellij-refresh-maven.png">

   * Try running again. If problem persists, continue on to number 3 below


 
   
## 3. Add property to pom.xml

* Within IntelliJ, open pom.xml file

* Add this section before `<dependencies>` (If your file already has a `<properties>` section, just add the `<maven.compiler...>` lines below to that existing section):
    
   ```
   <properties> 
      <maven.compiler.source>1.8</maven.compiler.source> 
      <maven.compiler.target>1.8</maven.compiler.target> 
   </properties>
   ```
    
* Change the `x` in `1.8` to your Java version. For example, if you’re using Java 13, change 1.8 to 1.13

     
* Refresh maven
   
   <img src="http://angiejones.tech/wp-content/uploads/2020/02/intellij-refresh-maven.png">

* Try running again
February 15th: Week in Review
Tags: weeklyretro, react, kotlin, python
Published: 2020-02-16 01:04:40

Hello again! Finally got around to posting one of these on time finally. 

Things I learned/did this week:
- I joined a new team 🎉🎉
- I started learning Kotlin and implemented the [Builder Pattern] (https://sourcemaking.com/design_patterns/builder) for the project I'm working on ✋, it's a great step away from the Java development I'm used to
- Started converting my You Don't Know JS notes into posts that I'll be sharing soon 🤓:book:
- Continuing to wrap my head around [react hooks](https://reactjs.org/docs/hooks-intro.html)

Some articles I read:
- Saw this great video of a guy who [created a nerf dart face tracking turret using Python](https://www.youtube.com/watch?v=cy3QToyba4s)
- Found out [dicts in Python are now ordered as of 3.7](https://softwaremaniacs.org/blog/2020/02/05/dicts-ordered/en/)
- [Some good ol' Kotlin docs](https://kotlinlang.org/docs/reference/)


Gotta say this week has been pretty solid for me, I hope everyone else's was as well. If you did anything cool you want to share tell me about it in the comments. Be seein' ya 🤠🐮
Exploring JSON API data from Node REPL
Tags: javascript, beginners
Published: 2020-02-16 00:29:54

When just starting out at web programming, it is good to understand the underlying data transport format - JSON and how to interact with it. For this we will use some json data from reddit.

Start up a new directory with a node project and install the JSON library. Then download the json data from reddit. 

```
mkdir json_demo
cd json_demo
npm init
npm install JSON --save
wget https://www.reddit.com/r/videos.json
```

Let's start an interactive session with node so that we can load the data and manipulate it. To do this, run `node`. In the node REPL (read-eval-print loop), let's first import the fs and JSON modules which we need to read the file from the disk, and parse the data into an object. 

```
node
var fs = require('fs')
var JSON = require('JSON')
```

Next, let's read the data from the disk into a variable. We will see that videos is just a string, so we can't really use it that easily.

```
videos = fs.readFileSync('videos.json', 'utf8')
typeof(videos)
```

Let's load the videos into an object with the JSON library. Now we see that videos_dict is a javascript object. 
```
videos_dict = JSON.parse(videos)
typeof(videos_dict)
```

We can query the keys to travel into the object and find the data we want. Ultimately I'd like to print the URL's for all the videos. Let's go through the object, determining the type and keys, and descending through the keys until we get to the data we want. Ultimately we find the data at `videos_dict.data.children[n].data.url`.

```
Object.keys(videos_dict)
typeof(videos_dict.data)
Object.keys(videos_dict.data)
typeof(videos_dict.data.children)
Object.keys(videos_dict.data.children)
typeof(videos_dict.data.children)
Object.keys(videos_dict.data.children[0])
typeof(videos_dict.data.children[0].data)
Object.keys(videos_dict.data.children[0].data)
videos_dict.data.children[0].data.url
```

Now, map over the `videos_dict.data.children` to print all the video URL's. 

```
videos_dict.data.children.map( (child) => { return child.data.url } )
```

For any arbitrary JSON from an unfamiliar API, you can easily explore the data and how to use it in your app!
There's Never Time To Code, So Start Now
Tags: starting, procrastination, university, justdoit
Published: 2020-02-16 00:14:11

---
title: There's Never Time To Code, So Start Now
published: true
description: How do you fit anything into your busy schedule?
tags: starting, procrastination, university, justdoit
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/e6aw6uzgzhmyqhrx9ore.png
---

// The Problem
If you're like me, you probably have a lot of goals in life. I want to get good grades at university. I want to do more side projects to be more hireable. I want to be smarter than my friends. It seems impossible to be able to put all the work in. There's so much to do but not enough time to do it all. What's wrong with me?

// The Solution (?)
There's probably nothing wrong with you. If you were expecting a solution or a quick fix, I'm sorry. You've come to the wrong places. Like you, I'm just trying to work out life's problems as it happens. I could tell you the advice you've probably heard millions of times before. 

- Prioritize your work. 
- Wake up early. 
- Don't compare yourself to others. 

// The Action 
But knowing something is completely different than acting on it. So you should start acting on them. No matter how small the progress is. Take this blog post for example. I've been wanting to write something - anything - on dev.to for a year now. Its been sitting in my Google Tasks to-do-list, getting pushes deeper and deeper into my forgotten tasks by more urgent, or frankly just more interesting things to do. 



But I'm writing this now. The quality is not great. The thought structure is all over the place. But hey, its something, right?

Stay tuned. There may (or may not) be more updates coming your way. 

Sincerely, 
Steven Z. Zhang
@zhast
IPv6 Sage Certification with NSX-T, Part 1: Requesting an extended prefix
Tags: bgp, datacenternetworking, ebgp, ipv6
Published: 2020-03-08 00:49:39

---
title: IPv6 Sage Certification with NSX-T, Part 1: Requesting an extended prefix
published: true
date: 2020-02-16 00:14:00 UTC
tags: BGP,Datacenter Networking,eBGP,IPv6
canonical_url: 
---

As is probably obvious from the sidebar, I'm pretty enthusiastic about IPv6 - for quite a few reasons, not least of which is implementing a new Layer 3 protocol after guys like [Vint Cerf](https://en.wikipedia.org/wiki/Vint_Cerf) already did most of the cool stuff.  
  
However, I didn't want to simply complete this task - most people complete all of these tasks without properly implementing IPv6 - no routing, network configuration is required if you simply install a tunnel client on your computer and work from there.  
  
So instead, let's introduce a lot of complexity and make it easier for the testing to fail.  
  
First things first, since we have a whole network in play instead of a single Layer 2 domain, we need to request a bigger prefix. Since you can't ( **shouldn't** ) chop up a /64 for end devices, let's start with establishing a larger prefix. HE.net's [tunnelbroker](https://tunnelbroker.he.net/) site lets us one-click request a /48:

[![](https://1.bp.blogspot.com/-mP3tfyZCrAg/XkA7xD8rKYI/AAAAAAAAA8M/6aboRF--Vx8zbEqlz7Wyc3wcMfoZgGuMgCLcBGAsYHQ/s320/9feb20-1.PNG)](https://1.bp.blogspot.com/-mP3tfyZCrAg/XkA7xD8rKYI/AAAAAAAAA8M/6aboRF--Vx8zbEqlz7Wyc3wcMfoZgGuMgCLcBGAsYHQ/s1600/9feb20-1.PNG)
So I'd recommend doing that - and from there we'd want to modify the tunnel created in my [previous blog post](https://dev.to/ngschmidt/ipv6-up-and-running-address-planning-basics-and-using-a-tunnel-broker-3k85-temp-slug-1263464), and chopping it up as you see fit.  
  
I already have a [dual-stack Clos fabric in my lab](https://dev.to/ngschmidt/spine-and-leaf-networks-an-outline-170m-temp-slug-3995301), so establishing tunneled connectivity here was trivial - standing up a VyOS virtual router (config [here](https://raw.githubusercontent.com/ngschmidt/vyos-ipv6-tunnel-example/master/vyos_example.txt)) and peering BGP with the fabric. This is pretty much the upside to Clos fabrics - you have flexibility in spades.
Slicing in Go
Tags: go, beginners
Published: 2020-02-15 23:23:18

In <a href="https://golang.org">Go</a> you can easily slice <a href="https://golangr.com/strings/">strings</a> or <a href="https://medium.com/rungo/the-anatomy-of-arrays-in-go-24429e4491b7">arrays</a>. As the name implies, a slice is a subset of the whole.

This is unlike C where you would have to use strcpy or other tricks to slice a string. (this is a lot of work)

Not so in Golang, to take a slice is much easier.

## String slice in Go

You can slice a string simply by using brackets and start and end index, as if you were using Python.

The format to slice is:

```go
a[low : high]
```

So to slice from 1 to 3, you would use

```go
a[1:4]
```

A string slice example is shown below. First a string (st) is defined. Then it's sliced and given as input to the Println function:

```go
package main

import "fmt"

func main() {
	st := "Hello World"
	fmt.Println(st[1:3])
}
```

If you run the program it will output a slice of the string st:

```go
el

Program exited.
```

To grab the first word, use st[0:5]. You can do this for arrays too!

```go
package main

import "fmt"

func main() {
	primes := [6]int{2, 3, 5, 7, 11, 13}

	var s []int = primes[1:4]
	fmt.Println(s)
}
```

Here we define an array of primes and then take a slice out of that. That slice is stored as a new variable and shown to the screen.
Introduce myself into DEV
Published: 2020-02-15 23:04:07

MY name is Gatore Jimmy I'm from Africa[RWANDA]In East and in my life i was looking something big to be focused on, so after get a link of free code camp, my life changed and now it gives me an orientation for what i can become in the future, now i earned my first certificate.
So Brievely, now I'm on javascript challenge, i hope you will guide me&help me anytime i look for your advices.
Enumerate in Python
Tags: python, beginners
Published: 2020-02-15 23:00:58

Are you new to <a href="https://python.org">Python</a>? Did you program in other languages before?

You may think the way to get the index is by creating a loop, getting the size of the array, creating an index variable, comparing the index variable to the condition and increasing it manually.. phew!

In the C programming language you get something like this:

```c
int i = 0;
for (i = 0; i <= 10; i++){
    printf("%s\n", list[i]);
```

Very cryptic right! 

## For loop index in Python

There is a Pythonic way to create loops with an index, namely **enumerate()**.

```python
for index, value in enumerate(some_list):
    print(index, value)
```

To give you a full example with a <a href="https://pythonbasics.org/list/">list</a>:

```python
my_list = ['apple', 'banana', 'grapes', 'pear']
for c, value in enumerate(my_list):
    print(c, value)

# Output:
# 0 apple
# 1 banana
# 2 grapes
# 3 pear
```
This works for numeric lists too:

```python
>>> b = [3,6,7,2,9]
>>> for index, value in enumerate(b):
...     print(f"At b[{index}] the value is {value}")
... 
At b[0] the value is 3
At b[1] the value is 6
At b[2] the value is 7
At b[3] the value is 2
At b[4] the value is 9
>>>
```

Great right! Syntax is very readable and Pythonic. 

**Related links:**
* <a href="https://pythonbasics.org/enumerate/">More enumerate examples</a>
* <a href="https://gum.co/dcsp">Learn Python, course</a>
A tricky Python default argument
Tags: python, immutability, testing
Published: 2020-02-15 22:34:55

Check the following code:

```python
def append(l=[]):
  l.append(1)
  return l

```

In my opinion, we have a problematic mutator function, but for the purpose of this article, just focus on the default argument/parameter. What's wrong?


```python
def append(l=[]):
  l.append(1)
  return l

print(append())
# [1]
print(append())
# [1,1]

```

Here's the tricky default parameter: any object (list, map, etc) will be **instantiate and will live in the memory for the rest of the function's life!**



IMHO it's problematic behavior, different from any other language, like Java or [JavaScript](https://repl.it/@jotafeldmann/defaultArgument). Ok, it's cool when you can work with dependency injection because once set, it will never be instantiated again. But in common use, you can forget that default parameter and have practical side-effects. Example: in unitary tests (my reason to write that article).

To avoid that stuff, you can check and instantiate every time, at the beginning of the function:

```python
def immutableAppend(l=None):
  l = [] if l is None else l
  l.append(1)
  return l

print(immutableAppend())
# [1]
print(immutableAppend())
# [1]
```

This gotcha leads me to the great [Python Guide](https://docs.python-guide.org/writing/gotchas/), which first gotcha is exactly this behavior. And one more reason to read all [Python doc](https://docs.python.org/3/tutorial/controlflow.html#default-argument-values), again 😞 (search for "Important warning: The default value is evaluated only once").


You can test it on https://repl.it/@jotafeldmann/trickyDefaultArgument
Learning Nim: OpenArrays vs Varargs
Tags: nim, beginners, codenewbie, learn
Published: 2020-02-15 22:14:00

At first, `openArray` and `varargs` seemed too similar to me, to the point that I felt `openArray` to be redundant. Then I tried to test my assumptions, and found out what I was missing.

## **OpenArrays**
`openArray` is the answer to the question, what if you want to send a whole array or sequence as an argument in a procedure? 
```nim
proc displayOpenArray(oa: openArray[string]) =
    echo oa.len

var fruits: seq[string] = @["apple", "banana", "orange"]

displayOpenArray(fruits)
displayOpenArray(fruits, "something else") #ERROR
```
`openArray` is designed to take only a single argument.

#### Can we pass multidimensional array as an argument?
```nim
#Yes
type
    oneDArray = array[0..1, int]
    twoDArray = array[0..1, oneDArray]

var complexArray: twoDArray = [[1, 2], [3, 5]]

proc displayOpenArray(oa: openArray[oneDArray]) = 
    for rows in oa:
        for col in rows:
            write(stdout, col, " ")
        write(stdout, "\n")

displayOpenArray(complexArray)
```

## **Varargs**
With `varargs` you can pass any number of arguments to your procedure.
```nim
proc displayVarargs1(va: varargs[int]) =
    echo va.len #prints the number of arguments
    
displayVarargs1(1, 2, 3, 4, 5, 7) #6

proc displayVarargs2(va: varargs[array[0..1, int]]) =
    echo va.len #prints the number of arguments
    
displayVarargs2([1, 2], [3, 5]) #2

#Somehow this works too
displayVarargs1([1, 2, 3, 4]) #4

#But this doesn't
displayVarargs1([1, 2, 3, 4], 5) #ERROR
```
#### How can we send a mixture of array/seq and other types?
```nim
proc displayBoth1(oa: openArray[int], va: varargs[int]) =
    echo "Array lenth:", oa.len
    echo "varargs length:", va.len
    
displayBoth1([1, 2], 3, 5, 7)
displayBoth1([], 1, 2, 3, 5, 7)
displayBoth1([])
```

*Note: The should only be one `varargs` parameter in your procedure.*

#### Can we hack it to accept various arrays of multiple lengths?
```nim
proc displayBoth1(va: varargs[openArray[int]]) =
    echo "Number of arguments:", va.len
    echo "length of each argument:"
    for arg in va:
        echo arg.len

displayBoth1([1, 2], [2], [3, 6, 8])
# May be not, openArray cannot be used in the above context. 
```

*Sum up:* `openArray` is used for accepting one argument of array/seq type while `varargs` is used to accept multiple arguments of same type.

#### But can `varargs` replace `openArray` and make it redundant?
Well, I've just started learning the language, but I'd go for yes. As far as passing arrays and sequences are concerned.


If you learnt something, hit ❤️ and share. Others deserve to know about it 🙂
Notable Features In Laravel 7
Tags: laravel, php
Published: 2020-02-15 21:50:52


## Route Matching Performance
the route matching will be twice faster than laravel 6 when using route:cache. thanks to symfony 5 [PR Link](https://github.com/laravel/framework/pull/31449).

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


## Guzzle Abstraction
Laravel 7 will provide a guzzle abstraction to make most easy use cases easier to be handled through laravel instead of Guzzle [PR Link](https://github.com/laravel/framework/pull/31449).


![Guzzle abstraction](https://dev-to-uploads.s3.amazonaws.com/i/jzgc6njmkag8sr5xr9dv.png)


## Blade X
 laravel 7 will provide support for blade x component syntax [PR Link](https://github.com/laravel/framework/pull/31363).


![Blade X](https://dev-to-uploads.s3.amazonaws.com/i/eohp7eenop27m2agsv04.png)


## Customizable Stubs
stub files will be customizable [PR Link](https://github.com/laravel/framework/pull/31054) .

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


## Custom Cast Types + Object / Value Object Casts .

this means you will be able to define your own custom cast types for Eloquent [PR Link](https://github.com/laravel/framework/pull/31035).

![Custom Cast Types](https://dev-to-uploads.s3.amazonaws.com/i/yllzmez578awau92wed6.png)


## View Cache Optimization

there will be a new config option called `expires` inside `view.php` which skip the check to see if a view has expired to determine if it needs to be recompiled [PR Link For Full Benchmark](https://github.com/laravel/framework/pull/31206).

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


## Dynamic Storage Links

`php artisan storage:link` was liking to `public` directory by default . but in laravel 7 developers will define there own storage links dirs [PR Link](https://github.com/laravel/framework/pull/31355).

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

hope you enjoyed with these features and eager to upgrade to laravel 7 once it's officially released on march :wink: .

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/1zc5dnpy2cvl0o359neq.png)
Why we choose Ruby for our projects
Tags: ruby, rails
Published: 2020-02-15 20:46:01

History of Ruby

Ruby, the creation of independent programmer,  Yukihiro Matsumoto, began life over 20 years ago. In 2003, Chicago-based 37Signals launched the popular project management system, Basecamp. 37Signals had developed Basecamp in Ruby, and in 2005, they made the web application framework they’d developed — Rails — public.

Thanks to the versatility and ease of use of the framework, Ruby on Rails became the first choice for web application developers all over the world. Airbnb, GitHub and the first version of Twitter were all written in Ruby. Frameworks such as Hanami and Sinatra emerged alongside Rails. In 2006 Ruby placed first in the Tiobe language ranking and maintained that position for another two years.

https://evrone.com/why-ruby