teleren/devto huggingface dataset:
How to get the common values from two arrays in JavaScript?
Tags: javascript
Published: 2020-12-03 00:00:00

---
  title: How to get the common values from two arrays in JavaScript?
  published: true
  tags: JavaScript
  date: Thu Dec 03 2020 05:30:00 GMT+0530 (India Standard Time)
  canonical_url: https://melvingeorge.me/blog/get-common-values-from-two-arrays-javascript
  cover_image: https://melvingeorge.me/_next/static/images/main-ff506822e7937659ea29edc95d9900a9.jpg
  ---
  [Originally posted here!](https://melvingeorge.me/blog/get-common-values-from-two-arrays-javascript)
  
To get the common values from 2 arrays in JavaScript, we can use the `filter()` method on any one of the array and then check to see if the current value is included in the second array using the `includes()` method on that array.

Consider these 2 arrays with some elements repeated on both of the arrays,

```js
// arrays
const arr1 = [1, 2, 3, 4];
const arr2 = [2, 3, 4, 5];
```

Now let's get the common elements from both arrays.

We can acheive this by using the `filter()` method on any one of the array. Let's take `arr1` and use the [`filter()`](https://melvingeorge.me/blog/array-filter-method-javascript) method on that like this,

```js
// arrays
const arr1 = [1, 2, 3, 4];
const arr2 = [2, 3, 4, 5];

// use filter() method
// on arr1
const commonElements = arr1.filter((element) => {
  // some code here!
});
```

Now inside this `filter()` method all we have to do is to check whether the element is present in the `arr2`.

We can check that using the `includes()` method in the `arr2` and returning the boolean value returned from the `includes()` method.

It can be done like this,

```js
// arrays
const arr1 = [1, 2, 3, 4];
const arr2 = [2, 3, 4, 5];

// use filter() method
// on arr1
const commonElements = arr1.filter((element) => {
  // check if the element
  // is present in arr2
  // and return the boolean value
  return arr2.includes(element);
});

console.log(commonElements); // [2,3,4]
```

Great! 🔥 We got the common elements from both the arrays.

See this example live in [JSBin](https://jsbin.com/daberulozu/2/edit?js,console).

### Feel free to share if you found this useful 😃.

---
Python VSCode testing from 0 to 100
Tags: testing, vscode, python, pytest
Published: 2020-12-02 23:43:29

Presumed, you got some scripts, started from scratch some coding. Now you reached a level of complexity, it's dawning that you need a modicum of structure. Preferably an automated test suite to give you the confidence and confirmation that everything is and stays fine in your code base.

https://code.visualstudio.com/docs/python/testing#_enable-a-test-framework

I will go with built-in *unittest* of the Python extension, so no additional configuration is necessary.
Here the steps for a concentrated quick start:
* Ctrl+Shift+P Python: Configure Tests (saved in .vscode settings.json)
 1. unittest
 2. root dir, I'm taking repository root
 3. "*_test.py" pattern

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

* Create tests in test-file https://code.visualstudio.com/docs/python/testing#_create-tests
 1. "python.testing.unittestArgs": [
        "-v",
        "-s",
        ".",
        "-p",
        "*_test.py"
    ],

* Ctrl+Shift+P Python: Configure Tests
* take care of proper imports
* Run All Tests

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

Mistakes FAQ
* Restart VS Code if test framework doesn't show discoveries or the test icon on the left panel in general.
* If you are at odds with import dependencies read: https://stackoverflow.com/questions/448271/what-is-init-py-for

This test approach is really simple and you should stick at least with basics in any early stage of development. I go for DEBUG and print outputs only for simple single file scripting. But if there are encapsulated parts in play, stick with the fundamentals of unit testing to keep dev velocity high and stay productive.

For more information study the docs page https://code.visualstudio.com/docs/python/testing#_a-little-background-on-unit-testing

Next steps for advanced dev automation is setting up a Continous Integration CI config in eg. github.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/a7xhv4gpqesau6bwo03x.png)
What is CSS-in-JS?
Tags: react, javascript, typescript, webdev
Published: 2020-12-02 23:37:57

---
title: What is CSS-in-JS?
published: true
date: 2020-12-02 23:35:02 UTC
tags: react,javascript,typescript,webdev
canonical_url: https://h.shadowtime2000.com/what-is-css-in-js
---

## What is CSS-in-JS?

So you have all probably heard of CSS-in-JS frameworks and libraries such as `emotion`, `styled-components`, and `goober`.

### What is CSS-in-JS

CSS-in-JS libraries follow many different patterns. But usually, they end up allowing you to do one thing:

1. Allow you to create unique CSS classes from JavaScript

Basically, you would typically use it like this:

```javascript
const myButtonsClassName = cssInJsLibraryFunctionHere({
	color: "red",
	"text-align": "center"
});

// Or with tagged template literals

const myButtonsClassName = css`
	color: red;
	text-align: center;
`
```

Some libraries (like `styled-components`) let you create React components from those styles, and allow you to create dynamic values for styling.

```jsx
const Button = styled.button`
	color: ${({ dark }) => dark ? "dark" : "white"}
`;

<Button />
<Button dark />
```

### Conclusion

CSS-in-JS is a pattern that allows you to write CSS styles inside your JavaScript.
How long does it take for your test suite to run?
Tags: testing, discuss, rails, webdev
Published: 2020-12-02 22:45:07

---
title: How long does it take for your test suite to run?
published: true
description: How long does it take for your test suite to run?
tags: testing, discuss, rails, webdev
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/zbg5lgzuxw88hhs9dnum.png
---

I think long-running test suites are the bane of the development flow. They cause friction in what is already a fairly fraught process and often times don't even lead you to the correct results.

How long does it take your test suite to run? How many tests do you have?

Do you run those tests in the cloud? How often do you run tests locally?

Let me know. How long does it take for your test suite to run? Does it take too long?
Write copy in Notion, export to JSON
Tags: productivity, showdev, i18n
Published: 2020-12-02 22:20:59

Hey there! 👋

I made a Low-Code project that I’d welcome feedback on —

Aimed at devs, PMs and copywriters, CopyOcean takes copy from a Notion Table and exports it to JSON, so developers can easily drop it into the app ([https://www.copyocean.com](https://www.copyocean.com)). It also makes i18n a breeze!

It was motivated by experience in product development where copy management was often messy and ad-hoc. Unnecessary communication overhead, outdated copy and lost productivity were some of the problems that came with copy changes. CopyOcean attempts to solve this problem by using Notion Tables as a central source for copy and helping you add the copy to your product with a machine-readable export (JSON).

Would love to know from you (a) how your copy process looks like today and (b) whether this is of interest! Of course any other thoughts welcome.
Day 268: The Heat
Tags: hiphop, code, coding, lifelongdev
Published: 2020-12-02 22:18:17

_liner notes_:
- Professional : Today went much better than yesterday! I answered some question on StackOverflow and in the Community Slack channel. Pushed some changes and updates for the documentation that got merged. Had a team meeting. Continued working on the documentation. Not a bad day at all.

- Personal : Finished up some stuff for work since my day was pretty thrown off. haha Then it got cold and I went to sleep. haha.

![View of a Jacksonville, Florida coastline](https://dev-to-uploads.s3.amazonaws.com/i/z8qkvb5j2xy5t0srxadi.jpg)

May do some more work since I'm on a roll then watch "Legion" on Hulu. It's getting cold so I bought a small heater that should be coming later tonight that I can run from my battery (I think. haha) I live in Florida for a reason. I miss the heat! haha

Have a great night!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube iD4_Np2VM8c %}
More dark mornings
Tags: 100daystooffload
Published: 2020-12-02 22:16:39

Here in the northern hemisphere the mornings are very dark. Despite it happening every year, I always find myself [struggling](https://dev.to/pestrickland/the-surprise-of-darkness-3l2i) to [adapt](https://dev.to/pestrickland/paying-yourself-first-with-non-negotiables-2g41). We had some brief respite by moving our clocks back an hour, but that advantage is well and truly lost now.

In my evolving year of working remotely, running has installed itself at the start of my day. I guess it's almost like a commute for me now. I have mornings where I can barely function, and others where I spring out of bed, but for the vast majority of the time I head out the door and run for up to an hour. Whatever state I left the house in, when I return I am awake: it's good.

After my run, I have just enough time to shower and dress, make a cup of tea and head into my office. It can be a bit hurried, especially when it's so dark that I head out a few minutes late, but sitting down to start the day by 8am is achievable. It's a routine that works well enough for me that I actually look forward to "heading to work". The run has allowed me to clear my mind and I usually have a good idea of what I need to do during the day.

The end of the day is less well defined, and it's something I still need to work on.

_I'm publishing this as part of 100 Days to Offload. You can join in yourself by visiting [https://100daystooffload.com.](https://100daystooffload.com)_
Binomo 
Published: 2020-12-02 22:13:11

Hello. I want to share my methods of getting extra income. I am a trader on the Binomo platform. I like this platform where I can analyze the markets myself. Also, Binomo offers tournaments to traders where they can earn additional income and experience. You can <a href="https://bitcoinnewsindo.com/platform-trading-terpercaya-sekilas-tentang-binomo/">binomo sign up</a> and check everything I said.
#masuk binomo
ประเภทของ Equivalence Class Testing
Published: 2020-12-02 21:29:45

บทความนี้เกี่ยวกับการทดสอบระบบ จะมาเล่าถึงประเภทของ Equivalence Class Testing โดยแบ่งออกเป็น 4 กลุ่มย่อย ๆ ดังนี้

1. **Weak Normal Equivalence Class Testing**: คือการทดสอบที่ ตัวแปลแต่ละตัวจะถูกทดสอบ และผลลัพธ์จะขึ้นอยู่กับค่าเพียงค่าเดียวเท่านั้น หรือรู้จักกันในชื่อ **single fault assumption**

2. **Strong Normal Equivalence Class Testing**: หรือ **multiple fault assumption** นั้นจะทดสอบผลลัพธ์จาก inputs ที่มากกว่า 1 ตัว

3. **Weak Robust Equivalence Class Testing:** จะเหมือนกับข้อแรก แต่จะเน้นในการตรวจสอบค่าที่ไม่ถูกต้อง เช่นค่าที่อยู่นอกขอบเขต ยกตัวอย่างเช่น ถ้าฟังก์ชันที่จะทดสอบรับจำนวนเต็มที่ 0-100 และใส่ -1 เข้าไปโปรแกรมจะทำงานอย่างไร throw exception หรือไม่

4. **Strong Robust Equivalence Class Testing**: เป็นการออกแบบการทดสอบที่อาจจะผสมไปด้วยค่าที่ถถูกต้อง และค่าที่ผิด โดยอาจจะผิดทั้งหมด หรือผิดแค่บางส่วนก็ได้

ซึ่งการออกแบบ test cases ที่ดี ควรลดการซ้ำซ้อนของ test cases ต่าง ๆ ด้วย ในมุมผมใช้แค่ 3 แบบแรกก็เพียงพอแล้ว

### ถ้ายังไม่เข้าใจไปดูตัวอย่าง code (ภาษา Swift) กัน

```Swift
class Calculator {
  let left: Int
  let right: Int

  ...

  func leftAddedWithOne() -> Int {
    left + 1
  }

  func add() -> Int {
    left + right
  }

  ...
}
```

เรามาดูกันที่ 2 ฟังก์ชันของโปรแกรมข้างบน คือ `leftAddedWithOne()` และ `add()`

- `leftAddedWithOne()` จะทำการเข้าค่า `left` มาเพิ่มด้วย `1` แล้วให้ผลลัพธ์ออกมา
- `add()` จะทำการเอาค่า `left` กับค่า `right` มาบวกกัน แล้วให้ผลลัพธ์ออกมา

#### ถ้าเราเขียน unit test ด้วย XCTestCase อาจจะได้เป็น

```Swift
let placeholderValue = Int.min

func test_whenLeftIs99_leftAddedWithOne_shouldReturn100() {
  let calculator = Calculator(left: 99, right: placeholderValue)
  XCTAssertEqual(calculator.leftAddedWithOne(), 100)
}

func test_add_shouldReturnValueOfLeftAndRightAddedTogether() {
  let calculator = Calculator(left: 99, right: -66)
  XCTAssertEqual(calculator.add(), 33)
}
```

จะเห็นได้ว่า test case แรก `test_whenLeftIs99_leftAddedWithOne_shouldReturn100()` จะไม่ได้สนใจ value ของ `right` โดยผลลัพธ์จะขึ้นอยู่กับค่า `left` อย่างเดียวเท่านั้น Test case แบบนี้จัดอยู่ในกลุ่ม **Weak Normal Equivalence Class Testing**

ส่วน test case ที่ 2 `test_add_shouldReturnValueOfLeftAndRightAddedTogether()` ผลลัพธ์จะขึ้นอยู่กับค่ามากกว่า 1 ค่า คือ `left` และ `right` ซึ่งถ้าค่าใดค่า 1 เปลี่ยนไปจะทำให้ test case นี้ fail. Test case นี้จึงจัดอยู่ในกลุ่มของ **Strong Normal Equivalence Class Testing**

***หมายเหตุ*** `placeholder` คือ ค่าที่ใส่แค่ให้ครบตามที่โปรแรกมนั้น ๆ ต้องการไม่งั้น compile ไม่ผ่าน แต่ไม่ได้เอามาคิดคำควณกับ test case นั้น

แต่ก่อนในวงการวิทยาการคอมพิวเตอร์เรียก `placeholder` ว่า `dummy` แต่ Google ได้ออกคำแนะนำใหม่[ให้เรียกว่า `placeholder` แทน](https://www.blognone.com/node/116929)

#### ส่วน robust testing

สมมุติว่ามีฟังก์ชันที่เรา string แล้วจะแปลงค่าเป็น Int ให้ โดยถ้าแปลงไม่ได้จะให้ผลลัพธ์เป็น nil แทน

```Swift
func convertToInt(_ value: String) -> Int? {
  Int(value)
}

XCTAssertNil(Int("ก"))
```

ซึ่ง test case ที่ดีเราไม่ควรทำการทดสอบตัว framework, หรือ library ที่ใช้ในแบบข้างบนนะครับ

ขอให้สนุกกับการเขียนโค้ด สวัสดีครับ 🙏
Advent of Code 2020
Tags: adventofcode, python, discuss
Published: 2020-12-02 22:09:35

Is anyone participating in [Advent of Code](https://adventofcode.com/) this year?

From the website:
>Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like. People use them as a speed contest, interview prep, company training, university coursework, practice problems, or to challenge each other.

>You don't need a computer science background to participate - just a little programming knowledge and some problem solving skills will get you pretty far. Nor do you need a fancy computer; every problem has a solution that completes in at most 15 seconds on ten-year-old hardware.

I just found this website and I'm planning to attempt each day's challenges. I'm going to try to post my solutions, in python, each day as well. I'd be interested to see how you all solved the challenges as well!
Outsourcing -- an inevitable road to failure or a way to optimize the burn rate?
Tags: startup, mobile, productivity
Published: 2020-12-02 21:25:50

Outsourcing firms might be savvy and helpful about both technology and industry expertise for inexperienced and confiding startup founders. This is how consulting companies gain trust and even dominance in negotiations and future business.

In my experience, every collaboration, when a buyer is in the submissive position end up with frustration and regrets for both parties. This happens because outsourcing partner will never replace inhouse personnel.

However, IT giants (Google, Microsoft, IBM...) are [hiring more outsourcing firms](https://nix-united.com/blog/outsourcing-who-does-it-and-why/) and continue to expand remote teams. Seem like they knew something everybody else hadn't learned yet and chances are, most of the startups won't find out ever.

Moreover, for many reasons  [wfh, quarantine, covid] hiring outsourcing agencies became more desirable and extremely popular in 2020.

I submitted some of my thoughts on this matter to the article [How To Outsource App Development](https://nix-united.com/blog/how-to-outsource-mobile-app-development-and-succeed/) -- it is a good starting point for those who haven't ever tried to outsource engineering but already considered.
Icing Developer Weekly, Gopher Gold and Rusticles on Dev.To
Tags: newsletter, update
Published: 2020-12-02 21:21:03

---
title: Icing Developer Weekly, Gopher Gold and Rusticles on Dev.To
published: true
description: An update on my weekly newsletters.
tags: newsletter, update
//cover_image: https://direct_url_to_image.jpg
---

For those who follow me, I have decided to stop posting my weekly newsletters on Dev.to. 

The "why" is straightforward enough: when my article writing slows down, my feed starts to become three newsletters a week. This is not what I am aiming for. I would like to be posting content that others can get a lot from and that won't just become noise for them.

I will continue posting these on [my blog website](https://blog.dennisokeeffe.com) for now with an aim to shift them all onto their own websites in the future!

For now, I will keep previous articles published on here with an aim to write a script down the track to clean up and keep my history to be **articles-only**.

Looking forward to posting more content soon!
Build your own Music Pad with C#, HTML, and CSS (VIDEO)
Tags: csharp, blazor
Published: 2020-12-02 20:50:18

In this video, I create a simple music pad controller with Blazor WebAssembly. 

Blazor is a framework for creating web applications using HTML, CSS, and C# 🔥.

The following topics are cover in the video :

- Components
- Event handling
- CSS isolation
- JavaScript interoperability
- HTML DOM Audio Object

The source code is available here:[https://github.com/estyval/BlazorMusicPad](https://github.com/estyval/BlazorMusicPad) 

If you like the content, feel free to like the video and subscribe to the channel 🙏.

{% youtube QV9iPf7et7A %}
Migrating away from moment.js
Tags: javascript, date, code, webdev
Published: 2021-01-28 08:25:13

---
title: Migrating away from moment.js
published: true
date: 2020-12-02 20:46:00 UTC
tags: javascript,date,code,webdev
canonical_url: 
---

 ![Migrating away from moment.js](https://www.panayiotisgeorgiou.net/wp-content/uploads/2021/01/Migrating-away-from-moment.js.png)

Moment.js was built for the previous era of the JavaScript ecosystem. The modern web looks much different these days. Moment’s usage is so widespread that it’s impossible to deprecate the current version over time. Check out this post on alternative options Migrating away from moment.js

## And in alternative corner…

We started with recommendations from the moment deprecation guide and tossed in some fan favorites to make sure we made the best choice we could. Keep in mind that there was a time constraint, so we couldn’t examine every option. Here’s the list we compiled:

- [date-fns](https://github.com/date-fns/date-fns#readme)
- [day.js](https://day.js.org/)
- [spacetime](https://github.com/spencermountain/spacetime#readme)
- [luxon](https://moment.github.io/luxon/)

## How to choose the correct one ? 

### It will always go down to project size !

- **moment** – 327KB, but also needs moment-timezone (185KB)
  - Total: 513KB 
- **date-fns** – 37.3 KB, but also needs date-fns-timezone (2KB), and all locales (26 KB)
  - Total: ~64KB
  - Eliminated due to lack of pre-built bundle. We need a single source of truth for IWA, and did not want to have to maintain a build process.
- **day.js** – 2KB, but also needs the utc and timezone plugins (4KB), and all locales (26 KB)
  - Total: ~32KB
- **spacetime** – _Zero Dependencies_ [comment in the readme](https://github.com/spencermountain/spacetime#-dst-changes-within-1-hour).
  - Total: ~43KB
- **luxon** – 71KB, Everything is included, and it relies on the INTL api for locales.

[Follow me on Instagram](https://www.instagram.com/panayiotisgeorgiou)

**That’s it for now. **

If you liked this article, then please subscribe to my [YouTube Channel](https://www.youtube.com/c/PanayiotisGeorgiou?sub_confirmation=1) for video tutorials.

You can also find me on [Twitter](http://twitter.com/panay_georgiou) and [Facebook](https://www.facebook.com/panayiotisgeorgiou.net).

The post [Migrating away from moment.js](https://www.panayiotisgeorgiou.net/migrating-away-from-moment-js/) appeared first on [Panayiotis Georgiou](https://www.panayiotisgeorgiou.net).
Advent of Code 2020 w/ GoLang
Tags: go, adventofcode
Published: 2020-12-02 20:19:51

---
title: Advent of Code 2020 w/ GoLang
published: true
description: Thread of AoC 2020 solutions in GoLang
tags: golang, AdventOfCode
series: Advent of Code 2020
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/gb6jnhz1didpnth3pbsw.jpeg
---
![GopherizeMe](https://dev-to-uploads.s3.amazonaws.com/i/n0aj37zh8a3zywvdgsmq.png)
Hey! I'm just opening up this post and keeping a thread/series with my solutions for each day of the Advent of Code 2020. This is more of an incentive for me to actually finish this year. 🙃

[*GitHub repo with my work*](https://github.com/dizveloper/AdventOfCode/tree/main/2020)

Anyways. You should join me in doing the [Advent Of Code](https://adventofcode.com/).

**DISCLAIMERS**: 
- I may not get each day's solutions up on that day
- I may not finish all 25 days 😅
- My solutions may not (*and probably won't*) be the most optimized. I solve them and then move on.
GIT - Unorthodox commands I use from time to time
Tags: webdev, git
Published: 2020-12-02 19:58:04

---
title: GIT - Unorthodox commands I use from time to time
published: true
description: A short-list with GIT commands less known but useful 
tags: webdev, git
cover_image: https://raw.githubusercontent.com/app-generator/static/master/blog/git-hacker-commands-1280x640.png
---
Hello Coders,

This article presents a few commands that I use from time to time to cover my programming mistakes or just shortcut things in my GIT repositories. 
I must warn beginners (and not only) to double-check the effects using test repositories before applying the mentioned commands on production repositories.

> *Thanks for reading!* - Content provided by **[App Generator](https://appseed.us/)**.

---

## GIT - Drop local changes

> Warn: you might lose valuable work

```bash
$ git reset --hard origin/master
```

---

## GIT - Reset to Commit

> Warn: All commits above the used one are lost

```bash
$ # We assume the Commit hash is '288c168'
$ git reset --hard 288c168
$ git push  --force origin master
```

---

## GIT - Print modified files

This command is the safest one and I'm using it a lot to scan for changes.

```bash
$ # List all changes
$ git add -A -n
$ 
$ # Filter the output using grep
$ git add -A -n | grep 'something' 
```

---

## GIT - Ignore files permissions on DIFF

This case might occur if the development PC uses Windows and production is on Linux. To extract the relevant changes and ignore the permissions of the files, the below command can be used:

```bash
$ # Configure GIT to ignore changes on files perms
$ git config core.filemode false
```

---

## GIT - Update single (LOCAL) file

Useful when we need to update a single local file with the remote version. The update can be done from any branch - our sample command uses the project *master* branch.

```bash
git checkout origin/master -- app/some-file.html
```

---

## GIT - Update forked project

This is useful when we want to update a forked project with the latest changes from the parent project.

```bash
$ # CD inside the forked project
$ cd forked-project
$
$ # Fetch all branches of remote upstream
$ git fetch upstream
$
$ # Rewrite your master with upstream’s master using git rebase.
$ git rebase upstream/master
$
$ # Save changes to our forked project
$ git push origin master --force
```

---

### Git resources

- [GIT](https://git-scm.com/) - official website
- [Top 20 Git Commands](https://dzone.com/articles/top-20-git-commands-with-examples) - with Examples

---

> Thank you! Btw, my (nick)name is **Sm0ke** and I'm pretty active also on [Twitter](https://twitter.com/Sm0keDev).