teleren/devto huggingface dataset:
Learn to secure your app while coding it ...
Tags: webdev, cybersecurity, javascript, react
Published: 2021-09-17 10:05:29

Every Dev considers his Application as "safe" until he get's proven wrong.
Look up at the OWASP Top10 and tell me what you can check as "done" in your current project state:
-Broken Access Control 
-Cryptographic Failures
-Injection 
-Insecure Design
-Security Misconfiguration
-Vulnerable and Outdated Components
-Identification and Authentication Failures
-Software and Data Integrity Failures
-Security Logging and Monitoring Failures
-Server-Side Request Forgery 


If you want to test your "secure coding skills", there's currently an tournament about exactly that:

https://community.cloudogu.com/t/secure-coding-tournament-how-to-take-part/189

SCW is reviewing your written Code automaticly against the (listed above) vulnerabilities, rates your overall score and shows where and how you can improve your skills.


Languages:
Kubernetes
Java
C# / MVC
JavaScript / React
Go
PHP
Python
SQL Select with IN clause from list with JPA
Tags: java, jpa, codever, snippets
Published: 2021-09-17 10:03:47

The native SQL query we want to map in JPA is similar to the following:

```
SELECT * FROM PARTNER where PARTNER_NUMBER IN ('id1', 'idn').
```

With JPA you can use a `TypedQuery` for example and set the expected list of the `IN` clause directly as query parameter

```java
@Stateless
public class PartnerDataRepository {

	@Inject private EntityManager em;

	public List<PartnerData> findPartnerDataFromList(
		List<String> partnerNumbers) {
	  TypedQuery<PartnerData> query =
		  em.createNamedQuery(
			  PartnerData.FIND_PARTNER_DATA_IN_LIST, PartnerData.class);
	  query.setParameter(PartnerData.PARTNER_NUMBERS, partnerNumbers);

	  return query.getResultList();
	}
}
```

In the named query itself you can pass the parameter with `:` as you would when setting a "normal" parameter:

```java
@Entity
@Access(AccessType.FIELD)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = PartnerData.TABLE_NAME)
@NamedQueries({
  @NamedQuery(
      name = PartnerData.FIND_PARTNER_DATA_IN_LIST,
      query = "select m from PartnerData m where partnerNumber in :partnerNumbers")
})
public class PartnerData {
  public static final String TABLE_NAME = "PARTNER";

  public static final String PARTNER_NUMBERS = "partnerNumbers";
  public static final String FIND_PARTNER_DATA_IN_LIST =
      "findPartnerDataWithPartnerNumbers";

  //... rest ignored for brevity
}

```

<hr>

> Shared :heart: from [Codever](https://www.codever.land/snippets/61446015fb0221040e46d431/details).  :point_right:  use the [**copy to mine**](https://www.codever.land/snippets/61446015fb0221040e46d431/details) functionality to add it to your personal snippets collection.
Coding is a Craft
Tags: javascript, programming, beginners, codenewbie
Published: 2021-09-17 09:23:15

 I'm sitting here working on my fundamental programming-skills and just found the perfect analogy for what I'm actually doing: It's craftmanship, almost like an artform. Even though I already know how to finish the task the seventh time, my brain structures the required steps much faster. Everyone can use a hammer and a nail, but a carpenter has run the miles, if you know what I mean.

I have a history in design and art, and I can say that this is just as much of a marathon as any other craft.

![Craftmanship](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hfzjihlkc4ssvxvdjezt.png)
Foobar: Please Pass the Coded Messages
Tags: google, foobar, python
Published: 2021-09-17 08:06:42

You need to pass a message to the bunny workers, but to avoid detection, the code you agreed to use is... obscure, to say the least. The bunnies are given food on standard-issue plates that are stamped with the numbers 0-9 for easier sorting, and you need to combine sets of plates to create the numbers in the code. The signal that a number is part of the code is that it is divisible by 3. You can do smaller numbers like 15 and 45 easily, but bigger numbers like 144 and 414 are a little trickier. Write a program to help yourself quickly create large numbers for use in the code, given a limited number of plates to work with.

You have L, a list containing some digits (0 to 9). Write a function solution(L) which finds the largest number that can be made from some or all of these digits and is divisible by 3. If it is not possible to make such a number, return 0 as the solution. L will contain anywhere from 1 to 9 digits.  The same digit may appear multiple times in the list, but each element in the list may only be used once.

Languages
=========

To provide a Java solution, edit Solution.java
To provide a Python solution, edit solution.py

Test cases
==========
Your code should pass the following test cases.
Note that it may also be run against hidden test cases not shown here.

Input:
solution.solution([3, 1, 4, 1])
Output:
    4311

Input:
solution.solution([3, 1, 4, 1, 5, 9])
Output:
    94311

Solution:
python
```python
def to_int(l):
    if not l:
        return 0
    return int("".join([str(d) for d in l]))

def solution(l):
    l = sorted(l, reverse=True)
    n = len(l)
    s = sum(l)
    if s % 3 == 0:
        # already divisible by 3 => use all digits
        return to_int(l)
    elif s % 3 == 1:
        # check backward if there is a digit that is 1 mod 3
        i = n - 1
        while i >= 0:
            if l[i] % 3 == 1:
                return to_int(l[:i] + l[i+1:])
            i -= 1
        # there must be two digits that each of them is 2 mod 3
        i = n - 1
        while i >= 0:
            if l[i] % 3 == 2:
                break
            i -= 1
        j = i - 1
        while j >= 0:
            if l[j] % 3 == 2:
                break
            j -= 1
        return to_int(l[:j] + l[j+1:i] + l[i+1:])
    else:
        # check backward if there is a digit that is 2 mod 3
        i = n - 1
        while i >= 0:
            if l[i] % 3 == 2:
                return to_int(l[:i] + l[i+1:])
            i -= 1
        # there must be two digits that each of them is 1 mod 3
        i = n - 1
        while i >= 0:
            if l[i] % 3 == 1:
                break
            i -= 1
        j = i - 1
        while j >= 0:
            if l[j] % 3 == 1:
                break
            j -= 1
        return to_int(l[:j] + l[j+1:i] + l[i+1:])
```
What is a Promise in JavaScript ?
Tags: javascript, programming, object
Published: 2021-09-17 09:10:19

## What is a Promise? 

*(in JavaScript) 

A promise is an article that may 🌌 produce a solitary worth at some point 🕠 later on 📅 with either a settled 💯value or a cause 💬 that it's not 😐 resolved.* 

## How Promises Work 

 *𝐈𝐭 𝐰𝐢𝐥𝐥 👏 𝐛𝐞 𝗳𝗮𝗹𝗹𝗶𝗻𝗴 𝗨𝗻𝗱𝗲𝗿 𝐨𝐧𝐞 ☝️ 𝐨𝐟 𝐭𝐡𝐞 𝟑 𝐩𝐨𝐬𝐬𝐢𝐛𝐥𝐞 𝐬𝐭𝐚𝐭𝐞𝐬:* 

👉𝐏𝐞𝐧𝐝𝐢𝐧𝐠: This is an initial stage of the Promise 🤞 previously 🤔 an operation 💁 starts. 

👉𝐅𝐮𝐥𝐟𝐢𝐥𝐥𝐞𝐝: This state demonstrates that 🔀 the specified operation was finished. ✅ 

👉𝐑𝐞𝐣𝐞𝐜𝐭𝐞𝐝: 🚫 This state 🇺🇸 demonstrates that 👉 the operation 💁 didn't finish. In 😩 this case, a blunder 🚫 esteem 👇 will be thrown🙀. 

##𝐖𝐡𝐲 🤔𝐝𝐨 𝐲𝐨𝐮 𝐧𝐞𝐞𝐝 😬 𝐚 𝐩𝐫𝐨𝐦𝐢𝐬𝐞? 

Promises are utilized 🚟 to deal with nonconcurrent activities. 

They give 👋 an another way to deal with callbacks by lessening ⏬ the callback hell and composing the cleaner code💻. 

##𝐖𝐡𝐚𝐭 🙌 𝐚𝐫𝐞 𝐭𝐡𝐞 𝐦𝐚𝐢𝐧 𝐫𝐮𝐥𝐞𝐬 𝐨𝐟 𝐩𝐫𝐨𝐦𝐢𝐬𝐞? 

🤞 A promise is an item that 🍜 supplies a standard-consistent .then() method 

🤞A forthcoming promise might change into 🤓 either satisfied or dismissed by the state. 

🤞A satisfied or dismissed 🚫 promise 🤞 is settled and it should not ⚙️ change into 👉 any 🕺 other state. 

👆Once a promise 🤞 is settled, the worth 💵 should not ✖️ change. 


## Promise Chaining 
Since .then() consistently returns another promise, it's feasible to chain promises with exact power over how and where blunders are taken care of. Promises permit you to imitate typical simultaneous code's attempt/get conduct. 


## What is the contrast among Callbacks and Promises? 

A callback function is a function passed into 🚟👉 one more function as a contention. 

This capacity is conjured inside 💠 the external function to finish an activity. 🎬 

The principle Difference between Callback-functions and Promises is that we Attach a Callback-function to a Promise instead of passing it. 

So we actually use callback functions with Promises, yet in an unexpected way (chaining).
_________________________________________________
Hope you found it useful...
Tmarketing
Tags: android, aws, azure, architecture
Published: 2021-09-17 08:59:08

<a href="https://tmarketing.vn/">Tmarketing</a> là đơn vị <a href="https://tmarketing.vn/">Digital Marketing Agency</a> chuyên nghiệp uy tín cung cấp dịch vụ thiết kế website, dịch vụ SEO, Đào tạo Seo, Google Ads
<br>
Thông tin liên hệ
Công ty TNHH Tmarketing
Địa chỉ: Lầu 1, 170/19 Dương Quảng Hàm, Phường 5, Gò Vấp, Thành phố Hồ Chí Minh
Website: https://tmarketing.vn/
Phone: 0906985239
Fanpage: <a href="https://www.facebook.com/tmarketingdma/">https://www.facebook.com/tmarketingdma/</a>
Youtube: <a href="https://www.youtube.com/channel/UCUqQRR3TKlV4TqlrwQ9P7CA">https://www.youtube.com/channel/UCUqQRR3TKlV4TqlrwQ9P7CA</a>
Twitter: <a href="https://twitter.com/tmarketingv">https://twitter.com/tmarketingv</a>
Linkedin: <a href="https://www.linkedin.com/in/tmarketingvn">https://www.linkedin.com/in/tmarketingvn</a>
Pinterest: <a href="https://www.pinterest.com/tmarketingvn/">https://www.pinterest.com/tmarketingvn/</a>
Flickr: <a href="https://www.flickr.com/people/tmarketingvn/">https://www.flickr.com/people/tmarketingvn/</a>
Anti-bot protection - is your website being scraped?
Published: 2021-09-17 08:28:52

We are living in the world of bots, but their traffic is not welcome on our websites for many reasons. Some of them are: slowing down response time of your website, scraping content, generating fake interactions and traffic, etc.

What is your experience, is your website being scraped? How can you tell?  I started working on a bot protection test service - there is a lot more to be done before the launch day, but here is my website: https://botmenot.com/
How To Use LinkedIn Automation Software to Grow Your B2b Business In 2021?
Published: 2021-09-17 08:26:02

LinkedIn automation is a great way to find and connect with ideal prospects, send them personalized messages, run campaigns, generate leads, and reach out to your potential clients while saving you maximum time and money.
Read more here
https://nichehacks.com/how-to-use-linkedin-automation-software-to-grow-your-b2b-business-in-2021-rLOjv5
OSD600 Lab1 Peer Review for other code
Tags: java, programming, testing
Published: 2021-09-17 08:24:46

For the lab 1, I had to partner with other student and review each other's code to find areas of improvements. 
I posted a thread in slack, and was able to connect with Tracy. She also used Java for her implementation of ssg application. 

First impression of her work was amazing. Her project is very well-organized. She used springboot and maven for the project, she used Utility classes to divide works. And she also used picocli, which she also suggested to me for future updates, which is a command line integration tool for java.  

First I had some issue with running the project. Readme was unclear about the jssg configuration, and reported this issue to Tracy. Tracy updated readme with the detailed instruction, and I was able to run the code. (https://github.com/trangntt-016/static-site-generator/issues/1)

Another area to improve is text processing. She uses StringBuilder to add all of the lines in paragraph and then transform it into html paragraph. I suggested this could be simplified in the future.(https://github.com/trangntt-016/static-site-generator/issues/3) 

Last issue I create applies to me as well. When passing the folder instead of a single txt file as an input, index.html that contains the link to generated html files is not implemented. (https://github.com/trangntt-016/static-site-generator/issues/1). This is a suggestion for the future updates as well. 

Tracy also reviewed my code. It was nervous to have someone review my code for me, she was able to find issues that I never realized before. 

And here are some issues Tracy reported to me.
1. She was not able to pass argument options because it was very unclear in the readme. I updated readme with the list of argument and some examples. https://github.com/irenejoeunpark/ssgApplication/issues/3

2. She found that I wrote my whole code in just one block, which was the main method. It was hard to read and find bug if it had issues. I cleaned up using two helper functions and it is much more cleaner. 
https://github.com/irenejoeunpark/ssgApplication/issues/1

3. She suggested to put comments in the code so that lines are more understandable by whoever reads it. I added more comments as she advised. 
https://github.com/irenejoeunpark/ssgApplication/issues/2

I learned the importance of the peer review, and testing by different developer, with a different perspective. After Tracy's review and testing, I was able to improve my ssg application, and it is also a great asset for future programming as well. 

My GitHub Repo: https://github.com/irenejoeunpark/ssgApplication
Tracy's GitHub Repo:https://github.com/trangntt-016/static-site-generator
How I create a nice Github profile page in 5 min!
Tags: git, javascript, webdev, github
Published: 2021-09-17 08:19:41

I will show you how create my profile github page in **5 min!**

Let's check my current profile page

**https://twitter.com/Code__oz**

(And follow me on github 👀)

### How I create profile on github

Before custom it, we need to create it!

It's very easy.

Go to github and create a new repository

https://github.com/new

Create the repository with your **own github name!**

![Screenshot 2021-09-16 at 23.24.51](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/clgq2ufp0t2kspyaagy6.png)

You will have a special event from github page!

Make you repository public & click on `Add a README file`

Go back to your profil and you can see that you have a profile page!

![Screenshot 2021-09-16 at 23.26.19](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nmexy17nw1sqcjr64xfu.png)
 
### Custom your profil

Ok so now it's the moment of fun!

Go to https://rahuldkjain.github.io/gh-profile-readme-generator/ 

After you fill all information that you need, click to `Generate README` at the bottom page.

Edit `README` on your repository and paste the code above!

And yes we did it in 5min!

---

I hope you like this reading!

🎁 You can get my new book `Underrated skills in javascript, make the difference` for FREE if you follow me on [Twitter](https://twitter.com/code__oz) and MP me 😁

Or get it [HERE](https://codeoz.gumroad.com/l/RXLYp)

🎁 [MY NEWSLETTER](https://www.getrevue.co/profile/code__oz)

☕️ You can [SUPPORT MY WORKS](https://www.buymeacoffee.com/CodeoZ) 🙏

🏃‍♂️ You can follow me on 👇

🕊 Twitter : [https://twitter.com/code__oz](https://twitter.com/code__oz)

👨‍💻 Github: https://github.com/Code-Oz

And you can mark 🔖 this article!
How to generate a random unique identifier with UUID
Tags: swift, ios, uuid, apple
Published: 2021-09-17 08:15:42

UUID is a universally unique identifier. UUID can be used to identify types, interfaces, and other items.
Creating an object or some entity with an unique identifier is a common task for developers. UUID structure created for to do this and to do it best, do not need create "bicycle".
**UUID is guaranteed to be unique**. When initializing the structure, a new UUID is created with RFC 4122 version 4 random bytes. 

```swift
import Foundation

let identifier = UUID().uuidString
Swift.print(identifier) // Result: "6A967474-8672-4ABC-A57B-52EA809C5E6D" 
```
> Available iOS 6.0+, macOS 10.8+, tvOS 9.0+, watchOS 2.0+.

### What's UUID from a code perspective?

[UUID](https://developer.apple.com/documentation/foundation/uuid) is a simple structure and is a part of Foundation framework.

```swift
public struct UUID: ReferenceConvertible, Hashable, Equatable, CustomStringConvertible {
  /// ...
}
```
UUID conforms 4 protocols: 
- [ReferenceConvertible](https://developer.apple.com/documentation/foundation/referenceconvertible)
- [Hashable](https://developer.apple.com/documentation/swift/hashable)
- [Equatable](https://developer.apple.com/documentation/swift/equatable)
- [CustomStringConvertible](CustomStringConvertible)

Also, the structure has some properties:

1 ``uuid`` - Returns the UUID as bytes.
```swift
var uuid: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8) { get } 
```

2 ``uuidString`` - Returns a string created from the UUID, such as “E621E1F8-C36C-495A-93FC-0C247A3E6E5F”
```swift
var uuidString: String { get }
```

Articles comes to devto portal with delay 1-2 week, if you want read my articles without delay you can visit [ToniDevBlog](https://tonidevblog.com/) 

> Article originally published at [ToniDevBlog](https://tonidevblog.com/posts/how-to-generate-a-random-unique-identifier-with-uuid/)

Thanks for reading! See you soon. :wave:
Static Site Generator
Tags: java, programming
Published: 2021-09-17 07:48:49

Built a static site generator (SSG) using Java.

Feel free to check it out: 
https://github.com/irenejoeunpark/ssgApplication

Example: 
Given text file textFile.txt 
```
Sample Text File


This is a sample text file to test the ssg created by Irene
```

Run:
```bash

java -jar out\artifacts\ssgApplication_jar\ssgApplication.jar -i sources/textFile.txt

```
textFile.html will be generated in the folder called "dist"
```html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
<STYLE type="text/css">
   H1 {border-width: 1; border: solid; text-align: center; font-family: Arial, Helvetica, sans-serif}
   p{font-family: Arial, Helvetica, sans-serif;}
    body {background-color: #d6ecf3;padding-left: 10%;padding-right:10%; padding-top: 0.5%;line-height: 1.5;text-align: center;}
 </STYLE>  <title>TextFile</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>Sample Text File</h1><br/><br/><p></p><br/>
<p></p><br/>
<p>This is a sample text file to test the ssg created by Irene</p><br/></body>
</html>
```

##Option

-v or --version : display version of the application
-h or --help : display the list of options and its description
-i or --input : allow to pass input file(s)


##Remark

More features will be added. I am considering to create more argument options by using picocli.
Ecommerce and Next.js on the Jamstack — with Colby Fayock
Tags: nextjs, webdev, ecommerce, javascript
Published: 2021-09-17 07:47:04

I sat down with [Colby Fayock](https://twitter.com/colbyfayock) to talk about [Next.js](https://nextjs.org/docs), how all of its features help enable developers to build great experiences on the web, and how it can help solve the many challenges of building e-commerce sites on the Jamstack.

In this video, we cover:

- What is Next.js?
- Is Next.js a static site generator?
- What does server-side rendering mean?
- What makes Next.js a strong framework?
- What are some e-commerce challenges that Next.js helps to solve?
- How is performance important to e-commerce?
- How does Next.js help with performance?
- How is SEO important to e-commerce?
- How does Next.js help with SEO?
- What's the most overlooked, yet oddly difficult part of e-commerce?
- Accessibility, internationalisation and personalisation in e-commerce

Colby is a super-nice host and I can't wait to hang out with him again. Thanks for having me, Colby!

{% youtube GyXyygeC2RE %}

{% user colbyfayock %}
A Starter's guide to testing React-Native WebViews with Detox
Tags: reactnative, testing, android, mobile
Published: 2021-09-17 07:41:52

![An image of a mobile phone](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a57u1fdxqwqik786jy1r.jpg)
You can finally write end-to-end tests for your WebViews using Detox!

… well, on Android anyway.

At this moment, iOS is not supported. However, that's likely to change in future. Interestingly, although functionality exists for testing on Android, Detox's docs haven't been officially updated to include the functionality. This suggests the work might be ongoing and fairly hush hush. Regardless, being able to test webviews on android remains a giant leap for developer-kind!


### How to add a WebView to your app

To include a WebView, add the react-native-webview package as a dependency to your package.json. Import the WebView component, and pass it a source as shown below.
Make sure to include a testID to your WebView so it can be found by detox when you run your test.

{% gist https://gist.github.com/redfoxjones/f5eaffe070c61326f84e9d6c2c88fc07 %} 


### How to write a test for the webview

For this example, we are using the Twitter Login page. We would like to allow the user to:
- Enter a username
- Enter a password
- And click the Login button

We first define a sleep function.
Sometimes, it takes a while for a webview to load, so it might be useful to add a delay to ensure it finishes loading before running the tests.

{% gist https://gist.github.com/redfoxjones/3bed681c17182f4f77487c4a86ecb501 %}

As seen below, we can use Detox's web object to interact with the view and make assertions on located elements.

{% gist https://gist.github.com/redfoxjones/bc45187835d0b49145774f1ac4171d69 %}


### Locating DOM elements:

Detox's web builds on Android's Expresso-Web and provides a list of functions for selecting DOM elements.

- `id` -  finds an element on the DOM tree by its id
- `text` - finds an element on the DOM tree by its CSS class
- `cssSelector` - finds an element on the DOM tree matching the given CSS selector
- `name` - finds an element on the DOM tree by its "name" attribute
- `xpath` - finds an element on the DOM tree by its XPath
- `href` - finds an `<a>` element on the DOM tree by its link text
- `hrefContent` - finds an `<a>` element on the DOM tree by its partial link text
- `tag` - finds an element on the DOM tree by its tag name

## Interacting with located elements:

After locating your element, you can simulate user interaction with the following self-explanatory methods:

- tap
- typeText
- getText
- clearText
- replaceText
- scrollToView
- getCurrentUrl
- getTitle
- runScript
- runScriptWithArgs

### Using Matchers

Detox web also comes with a fun set of matchers:
- toExist()
- toNotExist()
- toHaveText()
- toNotHaveText()

---

Although it might not seem like much, considering how integral webviews are to a lot of applications, this is truly a breakthrough for cross-platform mobile testing. I'm excited to see what this means for the future of mobile e2e testing.

The possibilities are endless!