teleren/devto huggingface dataset:
How to use Java 8 Stream FlatMap Examples with List, Array
Tags: java, java8, stream, flatmap
Published: 2021-04-09 17:17:24

https://grokonez.com/java/java-8/how-to-use-java-8-stream-flatmap-examples-with-list-array

How to use Java 8 Stream FlatMap Examples with List, Array

In the tutorial, we will discover more aspect of Java 8 Stream API with <code>flatMap()</code> function by lots of examples.
What we will do:
<ul>
<li>Explain how Java 8 Stream FlatMap work?</li>
<li>Apply Stream FlatMap on Java List, Array</li>
</ul>

Now let's do more details!

Related posts:
- <a href="https://grokonez.com/java/java-8/how-to-use-java-8-stream-map-examples-with-a-list-or-array">Java 8 Stream Map Examples</a>
- <a href="https://grokonez.com/java/java-8/java-how-to-use-stream-filter-in-java-8-with-list-array-examples">Java 8 Stream Filter Examples</a>

<!--more-->
<h2>Java 8 Stream FlatMap</h2>
Java 8 Stream provides 2 mapping APIs: <a href="https://grokonez.com/java/java-8/how-to-use-java-8-stream-map-examples-with-a-list-or-array">map()</a> and <code>flatMap()</code>

- Both <code>map()</code> & <code>flatMap()</code> is an intermediate operation. 
- Stream <code>map()</code> function is used to transform an input stream to a new output stream by applying a mapper function on each element.
-> What is a difference point with Stream <code>flatMap()</code> function?

<pre><code class="language-java">
&lt;R&gt; Stream&lt;R&gt; flatMap(Function&lt;? super T, ? extends Stream&lt;? extends R&gt;&gt; mapper);
</code></pre>

The <code>flatMap()</code> function will do 2 things:
- Apply mapper function to transform each element of input stream.
- Then flattens the result to a new output stream. (Not with Java 8 Stream <code>map()</code> function)
<h2>Stream FlatMap Java List Example</h2>
<h3>Stream FlatMap Integer List Example</h3>
We do a list of examples about Stream <code>flatMap()</code> function combining with others: <code>map()</code>, <code>filter()</code>, <code>reduce()</code>

More at:
https://grokonez.com/java/java-8/how-to-use-java-8-stream-flatmap-examples-with-list-array
Setting up reCAPTCHA with emailJS
Tags: recaptcha, emailjs, javascript, html
Published: 2021-04-09 17:12:32

Its surprisingly easy to add reCAPTCHA to a contact form with emailJS.  You will need the following:
1. A domain (netlify works fine)
2. A google account (used for reCAPTCHA)
3. An email js account [found here](http://emailjs.com)

Once you've set up your email form on email js.  Go into the settings tab and check the box to use reCAPTCHA v2. Keep this tab open, as we will need it again in a moment.
![This is where your secret key goes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/svfd11kfzm64260cz3pg.PNG)

Head over to [reCAPTCHA](http://www.google.com/recaptcha/admin) and click the plus icon to make a new reCAPTCHA.  Enter any domains your site may run on, without https:// or any specific page. (For https://website.com/webpage.html you only need to put in website.com)  Also ensure you've selected reCAPTCHA v2, v3 will not work with emailJS.  You can use any type of reCAPTCHA you like, but I personally used the "I'm not a robot" checkbox.  

You'll then see two keys, the first one is your html key, it goes in the html code, more on that in a moment.  The second key is the one you give to emailJS, simply copy/paste it into the field below the box you checked to activate reCAPTCHA.  

Once you have your form on the page. Place the following code in the form, I prefer directly above the submit button.  
```<div class="g-recaptcha" data-sitekey="your_site_key"></div>
      <br/>```
Replace the site key with your html key given to you by google.  Push your changes and things should work fine!  

One small note is that you won't be able to use your form on a localhost system, since it is not one of the configured domains.  I recommend commenting out the reCAPTCHA while testing, but don't forget to uncomment before you publish!
Java 8 – Lambda Expressions
Tags: java, java8, lambda, expression
Published: 2021-04-09 17:02:13

https://grokonez.com/java/java-8-lambda-expressions


Java 8 – Lambda Expressions

Lambda expressions are new feature in Java 8. We now can represent one method interface by using an expression.

<!--more-->
<h2>I. Overview</h2>
<h3>1. Pass a method as argument</h3>
Assume that we have 2 math operations: <strong>addition</strong> and <strong>subtraction</strong>. Those operations will be chosen in specific cases with 2 numbers: <strong>a</strong> and <strong>b</strong>. So the <strong>math operation</strong> is considered as an argument to method:
<pre><code class="language-java">
int doMathOperation(int a, int b, MathOperation mathOperation) {...}
</code></pre>
To make thing done, in normal approach, we declare an interface:
<pre><code class="language-java">
public interface IMathOperation {
	int run(int a, int b);
}
</code></pre>
and two implementations:
<pre><code class="language-java">
public class Addition implements IMathOperation {

	@Override
	public int run(int a, int b) {
		return (a + b);
	}
}

public class Subtraction implements IMathOperation {

	@Override
	public int run(int a, int b) {
		return (a - b);
	}
}</code></pre>
Main function will be:
<pre><code class="language-java">
int doMathOperation(int a, int b, IMathOperation mathOperation) {
   return mathOperation.run(a, b);
}</code></pre>


More at:

https://grokonez.com/java/java-8-lambda-expressions
SOQL in Salesforce
Published: 2021-04-09 17:00:49

<h1>SOQL</h1>: Salesforce Object Query Language

**Use**: to read information stored in your org’s database

**Implementation**: Can write and execute a SOQL query in Apex code or in the Developer Console’s Query Editor.

**syntax**:(similar to SQL (Structured Query Language))
```SELECT Id, *Name, BillingCity* FROM Account
SELECT *count()* FROM Contact (Give count)
SELECT *FIELDS(STANDARD)* FROM Contact  (Give all std field)```

* * elements are fieldlist and it defines the order of field in result.Fieldlist can also be an aggregate function,such as COUNT() and COUNT(fieldName)

**Child to Parent**
```SELECT <b>Contact.Firstname, Contact.Account.Name</b> FROM Contact```

**Parent to child**
```SELECT Account.Name,(SELECT Contact.LastName FROM Account.Contacts)FROM Account```

**Complete syntex**
SOQL query syntax consists of a required SELECT statement followed by one or more optional clauses, such as TYPEOF, WHERE, WITH, GROUP BY, and ORDER BY.
The SOQL SELECT statement uses the following syntax:
```
SELECT fieldList [subquery][...]
[TYPEOF typeOfField whenExpression[...] elseExpression END][...]
FROM objectType[,...] 
    [USING SCOPE filterScope]
[WHERE conditionExpression]
[WITH [DATA CATEGORY] filteringExpression]
[GROUP BY {fieldGroupByList|ROLLUP (fieldSubtotalGroupByList)|CUBE (fieldSubtotalGroupByList)} 
    [HAVING havingConditionExpression] ] 
[ORDER BY fieldOrderByList {ASC|DESC} [NULLS {FIRST|LAST}] ]
[LIMIT numberOfRowsToReturn]
[OFFSET numberOfRowsToSkip]
[FOR {VIEW  | REFERENCE}[,...] ]
      [ UPDATE {TRACKING|VIEWSTAT}[,...] ]
```

//You don’t need to specify the Id field in the query as it is always returned in Apex queries
 

* **LIKE**: WHERE Name LIKE 'SFDC%'. The % wildcard character matches any or no character


**for loop in SOQL**
```
for (variable : [soql_query]) {
    code_block
}
```
or

```
for (variable_list : [soql_query]) {
    code_block
}
```
**Difference between ':', "=" and "IN" operators**
":" to bind a variable
"=" to check value
"IN" to check value in a collection

```use ":" bind variable for access variable in query like
String MyName = 'vasu';
List<Contact> ListOfName = [SELECT FirstName, LastName FROM Contact WHERE FirstName =  : MyName];
use "=" operator is simple Equal operator in query like-:
List<Contact> ListOfName = [SELECT FirstName, LastName FROM Contact WHERE FirstName =  'vasu'];
[give contact list where firstName = (equal) vasu]
use IN operator in soql for refer LIST or SET direct in query like
List<String> lstOfStr = new List<String>{'testName','testName2'};
List<Contact> ListOfName = [SELECT FirstName, LastName FROM Contact WHERE FirstName IN : lstOfStr];
[here also use bind ":" operator for access varible value in query ]```
[Link] (https://www.salesforceben.com/soql-cheat-sheet/)
Hack: Forcing Puppet to apt update
Tags: puppet
Published: 2021-04-09 16:50:58

Short hack: As seen in [m](https://github.com/docker-library/postgres/blob/master/Dockerfile-debian.template#L11) [a](https://github.com/docker-library/httpd/blob/master/2.4/Dockerfile#L19) [n](https://github.com/nginxinc/docker-nginx/blob/master/Dockerfile-debian.template#L28) [y](https://github.com/docker-library/redis/blob/master/Dockerfile.template#L13) Dockerfiles, the `apt` cache is located at `/var/lib/apt/lists`.

Therefore, we can use it's existence to create an [idempotent](https://puppet.com/docs/pe/2019.2/understanding_idempotency.html) `exec`-Ressouce!

```
exec { 'apt update':
  # Only if the update files dont exist
  unless => '[ "$(ls -A /var/lib/apt/lists)" ]',
  # /bin is needed for bash
  # /usr/bin is needed for [
  path => '/bin:/usr/bin',
}
```

Now whenever you need to have the `apt` cache first, just do something like

```
package { 'your-package':
  ensure => 'present',
  require => Exec['apt update']
}
```

Easy as 🥧
Doodle 0.5.0 released
Tags: showdev, kotlin, webdev
Published: 2021-04-09 16:48:11

[Doodle](https://github.com/nacular/doodle) is a pure Kotlin UI framework for the Web, that lets you create rich applications without relying on Javascript, HTML or CSS. Check out the [documentation](https://nacular.github.io/doodle) and [tutorials](https://nacular.github.io/doodle-tutorials) to learn more.

## Multi-touch Support
Doodle now supports [multiple pointers]((https://nacular.github.io/doodle/#/multitouch)) (i.e. touches) by default. So there is no additional work needed to enable this in apps.

- `PointerInputManager` now tracks a collection of pointers and dispatches events to Views on a per-pointer basis.
- `PointerEvent` now has information about the list of pointers (for the View and overall). This lets handlers support multi-touch.
- `Resizer` now works better with multi-touch.
- Added ability to suppress OS handling of PointerEvent. This is like consume, except it does not affect other app listeners.

## Accessibility Support
This release stabilizes [accessibility](https://nacular.github.io/doodle/#/accessibility) and brings a lot of new support to items in the [Controls](https://github.com/nacular/doodle/tree/master/Controls) library.

- View now supports [`accessibilityLabel`](https://github.com/nacular/doodle/blob/master/Core/src/commonMain/kotlin/io/nacular/doodle/core/View.kt#L88), [`accessibilityLabelProvider`](https://github.com/nacular/doodle/blob/master/Core/src/commonMain/kotlin/io/nacular/doodle/core/View.kt#L94), [`accessibilityDescriptionProvider`](https://github.com/nacular/doodle/blob/master/Core/src/commonMain/kotlin/io/nacular/doodle/core/View.kt#L102), and [`nextInAccessibleReadOrder`](https://github.com/nacular/doodle/blob/master/Core/src/commonMain/kotlin/io/nacular/doodle/core/View.kt#L110).
- View's `visible` and `enabled` properties are now accessible.
- The following widgets now have accessibility support
  - `ToggleButton`
  - `Switch`
  - `CheckBox`
  - `RadioButton`
  - `HyperLink`
  - `ValueSlider` (including `Slider` `orientation`)
  - `ProgressIndicator`
  - `TextInput`
  - `List`
  - `Tree`
  - `TabbedPanel` via `BasicTabbedPanelBehavior`
- `BasicSpinnerBehavior`, `BasicMutableSpinnerBehavior` now supports up/down arrows.

## Kotlin IR compiler Support
Apps can now choose to use either the IR or Legacy artifacts.
Down The Hole Ya Go
Tags: raspberrypi, linux, bash, tutorial
Published: 2021-04-09 16:45:58


# INTRO
YouTube ad sense is a big portion of it's profit stream. Soooooo we are going to stop that! Well not really. However, we can block all of their ad's from reaching us. A while back I set up a Pi Hole and I thought I'd explain my journey into the setup. Pi Hole is a DNS filtering tool that can be configured to block advertisements, trackers, malicious websites, and malware. 

We are going to do this with the help of a Raspberry Pi.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9tvt1foxipi64hiqmy52.png)

# WHY THOUGH!
Traditional ad blockers are set up on a web browser. They typically analyze the data that's coming from your visited web page and either replace or remove advertisements. This works great for that one browser. I ran into a problem where everyone in my house doesn't have this installed or even knows what an ad block extension is. Pi Hole is a great solution as it can block ad on all of the devices within my house (iphones, androids, and computers). 


# Basic Concept
Let's say you launch a mobile game on your phone. As it's launching, all the assists are loading (texters, dialog, music, etc). At the same time, a request is being made by the game's url DNS server, which is managing the ads for that application. Your router then looks up that url and replies to your phone with a specific ip address that contains the ad. Instead of storing ads to application this method allows advertisers to dynamically serve individually tailored ads.  

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0jo99w3m7xrp8xr2zy76.PNG)

Pi Hole can block this process, or stand in between the DNS server and your device. Pi Hole will contain a blacklist of sites to block. If your device is attempting to retrieve information from a blacklisted site, then it would reply to your device with an unspecified address. Which would not show the ad on your device. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/plja8hyc0k3hp7wyuzfc.PNG)

# Setups
This involved the following steps
1. Install Raspbian on a micro sd
2. Change the default passwords
3. Configure a static IP for my raspberry pi
4. SSH into the pi (I didn't want to connect a monitor to my pi)
5. Run the one line install command on the my raspberry pi terminal
6. Get to the networking selection and set up the default blacklists


Whats cool about these steps is that I was exposed to my terminal more than usual!.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wnsayrivgr2x9882zvoj.PNG)

All that's left if the connect the the ip address and we are in!


Finished Product
At the end of it, you get this dashboard where you can manage your blacklist whitelist, devices, and certain statistics :

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i3ugwm3u170o2nio6hw5.PNG)

Overall all, this is a dandy project. If you are interested in in getting your hands dirty and want to setup your own pi hole here is the link [Pihole] (https://pi-hole.net/)
Insert Github Stats into Your Profile's README.
Tags: csharp, dotnet, github, stats
Published: 2021-04-09 16:35:33

This is C# code to demonstrate how to insert Github Stats into your profile's README.

```csharp
// First of all, sign in Github on the default browser.

const string yourGithubUsername = "YOUR_GITHUB_USERNAME";

// Go to README of your Github profile.
Process.Start($"https://github.com/{yourGithubUsername}
                /{yourGithubUsername}/edit/master/README.md");

// Insert this into README file and then replace YOUR_NAME
// and YOUR_GITHUB_USERNAME.
/*
[[YOUR_NAME]'s Stats](https://github-readme-stats.vercel.app
/api?username=[YOUR_GITHUB_USERNAME]&show_icons=true)
*/

// Sleep 15 seconds.
Thread.Sleep(TimeSpan.FromSeconds(15))
Console.WriteLine("Done")
```

It sounds interesting, right?

Happy coding :)
LeetCode 14. Longest Common Prefix
(javascript solution)
Tags: javascript, algorithms
Published: 2021-04-09 16:26:04

###Description:
Write a function to find the longest common prefix string amongst an array of strings.

If there is no common prefix, return an empty string "".

###Solution:
Time Complexity : O(n^2)
Space Complexity: O(1)

```javascript
var longestCommonPrefix = function(strs) {
    if (strs.length == 0) return "";
    let prefix = strs[0];
    for (let i = 1; i < strs.length; i++)
        // Trim the prefix until it fits in the front of the current word
        while (strs[i].indexOf(prefix) !== 0) {
            prefix = prefix.substring(0, prefix.length - 1);
            // If we cannot trim down the prfix to fit in the word then we have no common prefix amoung words in str
            if (prefix.length===0) return "";
        }        
    return prefix;
}
```
What was your win this week?
Tags: discuss, weeklyretro
Published: 2021-04-09 16:25:29

---
title: What was your win this week?
published: true
description: Got to all your meetings on time? Started a new project? Fixed a tricky bug?
tags: discuss, weeklyretro
cover_image: https://cl.ly/188e843c2985/download/Image%202019-02-15%20at%202.36.37%20PM.png
---

Hey there!


**Looking back on your week — what was something you're proud of?**

All wins count — big or small 🎉

Examples of 'wins' include:

- Starting a new project
- Fixing a tricky bug
- Finding some signs of Spring ... or whatever else might spark joy ❤️ 

---

Happy Weekend!

![Spongebob sleeping](https://media.giphy.com/media/3ohuPjybONXKhH8uWI/giphy.gif)
NodeJS/Express – Upload Text-Fields + MultipartFile with Multer, Jquery Ajax, Bootstrap 4

Tags: node, express, multipartfile, ajax
Published: 2021-04-09 16:23:20

https://grokonez.com/node-js/multer/nodejs-express-upload-text-fields-multipartfile-with-multer-jquery-ajax-bootstrap-4

NodeJS/Express – Upload Text-Fields + MultipartFile with Multer, Jquery Ajax, Bootstrap 4

In the tutorial, we show how to upload <code>multipart/form-data</code> with text fields and attached file in NodeJS/Express web-application using Multer, JQuery Ajax, Bootstrap 4.

Related posts:
- <a href="https://grokonez.com/node-js/nodejs-express-upload-multipartfiles-images-multer-jquery-ajax-bootstrap">NodeJS/Express – Upload/Download MultipartFiles/Images – Multer + JQuery Ajax + Bootstrap</a>

<!--more-->
<h2>Goal</h2>
In the tutorial, we build a NodeJS/Express web-application that uses Multer middleware to upload/download multipart/form-data with text-fields & attached file using JQuery Ajax & Bootstrap view.

<strong>Technologies</strong>:
<ul>
<li>NodeJS</li>
<li>Express</li>
<li>Multer</li>
<li>JQuery Ajax</li>
<li>Bootstrap 4</li>
</ul>

Project structure:

<pre><code class="language-javascript">
/NodeJS-Express-Upload-Text-Fields-File
	/app
		/config
			multer.config.js
	/node_modules
	/resources
		/static
			/js
				postrequest.js
	/uploads 
		/*contain uploaded files*/
	/views
		index.html
		404.html
	package.json
	server.js
</code></pre>

-> results:

<img src="https://grokonez.com/wp-content/uploads/2018/05/NodeJS-Express-Upload-Form-Text-Fields-MultipartFile-Multer-uploadedsuccessfully-form.png" alt="NodeJS-Express-Upload-Form-Text-Fields-MultipartFile-Multer-uploadedsuccessfully-form" width="515" height="464" class="alignnone size-full wp-image-12645" />

-> Server's Logs:

<pre><code class="language-javascript">
NodeJS-Express-Upload-Text-Fields-File>node server.js
App listening at http://:::8081
/GET
{
    "firstname": "Jack",
    "lastname": "Davis",
    "file": {
        "fieldname": "resume",
        "originalname": "Jack-Resume.txt",
        "encoding": "7bit",
        "mimetype": "text/plain",
        "destination": "C:\\nodejs\\NodeJS-Express-Upload-Text-Fields-File/uploads/",
        "filename": "Jack-Resume.txt",
        "path": "C:\\nodejs\\NodeJS-Express-Upload-Text-Fields-File\\uploads\\Jack-Resume.txt",
        "size": 12
    }
}</code></pre>
<h2>Prerequisites</h2>
<a href="https://grokonez.com/node-js/nodejs-express-upload-multipartfiles-images-multer-jquery-ajax-bootstrap">NodeJS/Express – Upload/Download MultipartFiles/Images – Multer + JQuery Ajax + Bootstrap</a>
<h2>Practice</h2>

More at: https://grokonez.com/node-js/multer/nodejs-express-upload-text-fields-multipartfile-with-multer-jquery-ajax-bootstrap-4
HashiConf Europe: June 8-11, 2021: An online HashiCorp community conference
Tags: devops, architecture, systems, codenewbie
Published: 2021-04-09 16:19:19

The next HashiConf Europe will take place June 8-11, 2021. HashiConf brings the HashiCorp community together online to deepen connections around the HashiCorp product suite: Terraform, Vault, Consul, Nomad, Packer, Vagrant, Waypoint and Boundary.

Join us for two days of keynotes, technical sessions, product updates, and community connections (June 8 & 9), followed by two days of product workshops (June 10 & 11). 

Registration is free. We hope you can join us.

https://hashiconf.com/europe/

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/610n9hbdndep4wk6de8c.png)
Do you know testing? Maybe it’s not enough...
Tags: testing, softskills
Published: 2021-04-09 16:15:42

_Originally written at my [LinkedIn](https://www.linkedin.com/pulse/do-you-know-testing-maybe-its-enough-rodrigo-matola/) on September 6, 2016. I had just finished my first job with software testing._

I was thinking of writing this article when I read this other here [Do software testers need to learn coding?](https://www.linkedin.com/pulse/20140627110120-3037808-do-software-testers-need-to-learn-coding). They complement each other.

I hear sometimes at work: this is not my problem, I don’t need to know that, it’s not my task and I don’t care. Yes, you will not meddle in the task / work of others, but a project where several areas are involved, we have to get a sense of the role and what makes each project area. This sense needs to be deeper if these areas work directly with each other.

In my case for example, we test the results software. Keeping simple, there are two different companies, one for getting and one for dissemination of results. So I have to deal with two different ways of working (very different).

At the beginning I was told to just do my job (manual testing). Anything needed to be made in the system, was necessary to call someone or open a ticket. This sometimes caused a break in testing, because we depended on others to continue.

Over time, I learned the processes and procedures that helped me to improve my testing and save time. Many defects opened to a system was in fact from another, which have the previous processing. Unfortunately this was not taught and had to run back on its own, on trial and error, asking people who knew more (or should), sometimes with vague answers.

Black box testing is sometimes taken very seriously. You test only what you see, no idea what's behind. By analogy, if your computer crashes is not better you understand how your work tool works? You do not need to know how to fix, but this knowledge will help you to argue with the technician who may want to fool you or make a kludge.

> Anybody know anything about internal combustion engines? Of couse! Anybody know how to fix an internal combustion engine? No... (The Big Bang Theory)

We are not only in the testing department, or development, or software sales. We are in the software delivery business, and to deliver the  best quality software, different areas and companies should work integrated as a single team.


> "Teamwork is not when everyone works together, but when we trust each other." (Unknown)
Change Leaflet Tile control to accordion
Tags: javascript, css, leaflet, accordion
Published: 2021-04-09 16:13:06

If you use Leaflet for map based development, and use large number of tile providers, this trick will be useful for grouping the provider names. The tile provider selector will work as vertical accordion.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2a8nkwvv7ssjmayvmi5.jpg)

The trick is class injection to html tags. 
- Define all tile providers you needed.
- On baseMaps{} object add name to the providers, but the first word must be the main title of the accordion (OSM, Google, Stemen, Stadia, etc...), the other words will be displayed after the radio button.
- The accordion created by setTitleControl() function.

{% codepen https://codepen.io/cosmiclaca/pen/vYgWeZz %}

Git repo: https://github.com/CosmicLaca/leaflet_accordion