teleren/devto huggingface dataset:
Jest: shared async code between test blocks
Tags: jest, tdd
Published: 2020-05-26 17:09:00

I want to remember this day as the first day I asked something at StackOverflow and receive a brilliant and non-trivial answer!

Check it out, a way to provision a group of tests with some test data asynchronously while getting some data from the provisioning process:

```js
const setupTestContext = testContext => beforeAll(async () => {
  Object.assign(testContext, await setup());
});

...

describe('Some group of tests', async () => {
    const someData = {};

    setupTestContext(someData);

    test('Test1', async () => {
      // context is filled with data at this point
      const actual = myFunc(someData.x)
      ...
    }
    ...
})
```


 https://stackoverflow.com/questions/62019169/jest-shared-async-code-between-test-blocks/62027162#62027162
🔥 Quick Tip: How to create a Factory method pattern
Tags: javascript, tutorial, beginners, showdev
Published: 2020-05-26 17:03:04

On this simple trick, I'll show you how to create a Factory method pattern.

```js
function HttpErrorFactory(statusCode, error = 'Uncaught Error!') {
  if (!statusCode) {
    throw new Error('Invalid status code.');
  }

  function make() {
    return {
      statusCode,
      error,
    };
  }
  
  function print() {
    const _response = make();
  	return console.log(JSON.stringify(_response));
  }
  
  return { 
    make,
    print
  };
}

const badRequest = HttpErrorFactory(400, 'Bad Request!');
const badRequestObject = badRequest.make();

const internalServerError = HttpErrorFactory(500, 'Internal Server Error!');
const internalServerErrorObject = internalServerError.make();

console.log(badRequestObject);
/**
 * => {
        error: "Bad Request!",
        statusCode: 400
      }
 */

console.log(internalServerErrorObject);
/**
 * => {
        error: "Internal Server Error!",
        statusCode: 500
      }
 */

internalServerError.print();
// => "{\"statusCode\":500,\"error\":\"Internal Server Error!\"}"

badRequest.print();
// => "{\"statusCode\":400,\"error\":\"Bad Request!\"}"
```

Did you like it? Comment, share! ✨
ASP.NET Core Series: MVC and Razor Pages
Tags: dotnet, aspnet, webdev, beginners
Published: 2020-05-26 17:01:35

ASP.NET Core is our open-source, cross-platform framework for building modern, cloud-enabled, Internet-connected apps. In this series of videos we’ll be cover many of the interesting features of the framework.

In the episode, Dan Roth comes on to chat with us about the MVC and Razor Pages programming model. 

{% youtube 6GRFDkeCv3k %}

If you liked this video and would like to see some more of our .NET content, please subscribe to our [.NET Developers YouTube Channel](https://www.youtube.com/channel/UCvtT19MZW8dq5Wwfu6B0oxw).


## Useful Links
<ul>
<li><a href="https://docs.microsoft.com/learn/modules/create-razor-pages-aspnet-core?WT.mc_id=ondotnet-c9-cephilli" target="_blank">Create a web UI with ASP.NET Core</a></li>
<li><a href="https://dot.net/?WT.mc_id=ondotnet-c9-cephilli" target="_blank">.NET Homepage</a></li>
<li><a href="https://docs.microsoft.com/aspnet/core/tutorials/razor-pages/razor-pages-start?WT.mc_id=ondotnet-c9-cephilli" target="_blank">Get started with Razor Pages</a></li>
</ul>
Finding DNS hostname for Kubernetes Service
Tags: kubernetes, devops, microservices, servicediscovery
Published: 2020-05-26 16:44:00

Kubernetes is very difficult! If someone says it is easy, do not believe! But we can learn! 😎

There there is a little trick to find the internal DNS for a service.

I have created a service for a Cassandra Database using the following YAML:

```yaml
apiVersion: v1
kind: Pod
metadata:
  name: my-service
  labels:
    app: my-service
spec:
  containers:
  - name: my-service
    image: my-service
---
apiVersion: v1
kind: Service
metadata:
    name: my-service
spec:
  type: NodePort
  ports:
    - port: 8080
      targetPort: 8080
      nodePort: 30080
      protocol: TCP
  selector:
    app: my-service
---
apiVersion: v1
kind: Pod
metadata:
  name: cassandra-db
  labels:
    app: cassandra-db
spec:
  containers:
  - name: cassandra-db
    image: cassandra:3
---
apiVersion: v1
kind: Service
metadata:
  name: cassandra-db
spec:
  selector:
    app: cassandra-db
  type: ClusterIP
  ports:
    - port: TCP
      port: 7000
```

So I have a question? How can I know where I can find my database? I'm using a ClusterIP, so if I redeploy my database, it can change.

So the first approach is to not directly use my database hostname/port on code. I should retrieve it thought *Environment Variables*.

The I have to find the _cassandra-db_ service hostname.

# Finding the hostname

I have to create a pod in the environment, to access the environment topology:

```yaml
apiVersion: v1
kind: Pod
metadata:
  name: dnsutils
  namespace: default
spec:
  containers:
  - name: dnsutils
    image: gcr.io/kubernetes-e2e-test-images/dnsutils:1.3
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
  restartPolicy: Always
```

Apply the created yaml file:

```bash
$ kubectl apply -f dnsutils.yaml
pod/dnsutils created
```

Then I can easily search for the DNS with `nslookup` on `dnsutils`:

```bash
$ kubectl exec -ti dnsutils -- nslookup cassandra-db
Server:         10.96.0.10
Address:        10.96.0.10#53

Name:   cassandra-db.default.svc.cluster.local
Address: 10.98.98.138
```

Easy?

Now that I do not need `dnsutils` pod anymore, I can delete it:

```bash
$ kubectl delete pod dnsutils
pod "dnsutils" deleted
```

# Using the found value as Environment Variable

Now we can use found value as environment variable:

```yaml
apiVersion: v1
kind: Pod
metadata:
  name: my-service
  labels:
    app: my-service
spec:
  containers:
  - name: my-service
    image: my-service
    env:
    - name: DATABASE_HOST
      value: "cassandra-db.default.svc.cluster.local"
    - name: DATABASE_PORT
      value: "7000"
```

# Conclusion

Using Kubernetes is not easy, but we can learn. Here we can find an easy way to find how can we access services internal Kubernetes DNS.
Development Machine Environment Build & Language Stack Installations - Browsers & IDE's
Tags: beginners, tutorial, productivity
Published: 2020-05-26 16:21:40

---
title: Development Machine Environment Build & Language Stack Installations - Browsers & IDE's
published: true
description: In this video I put together some basic IDE's and browsers I install. In the case of browsers that includes more than a few. For the case of IDE's it's my standard arsenal of Jetbrains IDE's and Visual Studio Code.
tags: beginner, tutorial, productivity
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/ok55g11y2llnpwkmv6ja.jpg
---
In this video I put together some basic IDE's and browsers I install. In the case of browsers that includes more than a few. For the case of IDE's it's my standard arsenal of Jetbrains IDE's and Visual Studio Code. For the previous step in this series, check out the [Base OS Load post](https://compositecode.blog/2020/05/24/development-machine-environment-build-and-base-os-load/).

{% youtube DzmySaqFIdE %}

## Additional Notes

Here's the full list of IDE's I installed.

### IDEs

* [Visual Studio Code](https://code.visualstudio.com/)
* [Goland](https://www.jetbrains.com/go/)
* [IntelliJ](https://www.jetbrains.com/idea/)
* [WebStorm](https://www.jetbrains.com/webstorm/)
* [Rider](https://www.jetbrains.com/rider/)
* [PyCharm](https://www.jetbrains.com/pycharm/)
* [CLion](https://www.jetbrains.com/clion/)
* [DataGrip](https://www.jetbrains.com/datagrip/)
* [AppCode (On MacOS only of course!)](https://www.jetbrains.com/objc/)

### Browsers

* [Chrome](https://www.google.com/chrome/)
* [Firefox](https://www.mozilla.org/en-US/firefox/new/)
* [Opera](https://www.opera.com/)

That's it for now. However, if you're interested in joining me for next steps, language stack setup, and more in addition to writing some JavaScript, Go, Python, Terraform, and more infrastructure, web dev, and all sorts of coding I stream regularly on Twitch at [https://twitch.tv/adronhall](https://twitch.tv/adronhall), post the VOD's to YouTube along with entirely new tech and *metal* content at [https://youtube.com/c/ThrashingCode](https://youtube.com/c/ThrashingCode). Feel free to check out a coding session, ask questions, interject, or just come and enjoy the tunes!

For more blogging, I write at https://compositecode.blog and the [Thrashing Code Newsletter](https://compositecode.blog/thrashing-composite-code-newsletter/) for more details about open source projects and related efforts I work on, sign up for it [here](https://compositecode.blog/thrashing-composite-code-newsletter/)!
Getting started with progressive web applications through Workbox and service workers
Tags: pwa, workbox
Published: 2020-05-26 16:05:10

---
title: Getting started with progressive web applications through Workbox and service workers 
published: true
description: 
tags: pwa,workbox
---

In this tutorial, we're going to explore how to make web applications work offline through the use of service workers from Workbox. 

There are many things that make up a progressive web application, whether that be with a mobile-friendly user experience (UX), having a native desktop and mobile API integration, or just being able to use the application without an internet connection.

Service workers are the first step towards developing a fully compliant progressive web application (PWA) and frameworks like [Workbox](https://developers.google.com/web/tools/workbox) make it very easy. 

[Click here](https://dev.to/bnevilleoneill/getting-started-with-progressive-web-applications-through-workbox-and-service-workers-kc0/edit) for a related blog post on getting started with PWAs through Worbox. 

* * *
### LogRocket on [YouTube](https://www.youtube.com/logrocket) 🎬
 
![](https://dev-to-uploads.s3.amazonaws.com/i/2eacqscox237qibs7cho.jpg)

If you enjoy in-depth video tutorials on frontend topics, [check out LogRocket's YouTube channel](https://www.youtube.com/logrocket). Make sure to give us a like if you find the video helpful and subscribe to stay updated on when we post new videos. 
* * *
Problem-Solving Framework for Technical Interview Questions Part 2: Brainstorm Solutions
Tags: career
Published: 2020-05-26 15:56:19

<em>*This is based off of Anthony D. Mays’s technical interview question framework located [here]
(https://anthonydmays.com/blog/2017/01/04/interviewing-at-google-heres-6-things-you-absolutely-need-to-do/). Did some work on my own based on this and felt what I came up with also adds value.</em>

<em>*This article also assumes prior knowledge of data structures and algorithms</em>

Now that you understand the question to the best of your ability, now it’s time to come up with a solution. 

<h4>Brainstorm solutions and select one (Navigate the solution space to find a solution)</h4>

It’s important to note that this is not the point where you start to write code of any form. What I’ve noted during my own practice is that code, once written, tends to have a rigidity that makes the exploration process significantly harder. To keep from having this problem, it’s best to start writing the solution down and thinking about it in plain English. Writing the solution in plain English will act like a guide for you to write code. Also remember to bounce ideas off your interviewer and get them involved in the decision-making process.

These are steps that I take to try and brainstorm a solution:

<ol>
<li>Come up with at least one solution that satisfies all test cases - This/These will usually be of the brute force nature. Don’t worry about space/time complexity, just solve the problem. If time becomes constrained, you’ll end up having to write this solution so it’s important to have it ready.</li>

<li>If multiple solutions are explored, determine the practicality of each solution, strengths and weaknesses or maybe even parts that can augment other solutions - Pretty self-explanatory here. This is just choosing the best of what was come up with.</li>

<li>Brainstorm optimizations of solutions and choose one to continue with - In coding interviews, the interviewer tends to ask a famous question after analyzing your implementation, ‘can we do better?’. This is where we try to answer that question before they have time to ask it. For algorithmic problems, this is where your Computer Science fundamentals will begin to show themselves. Choose optimization techniques to make your solution more efficient.</li>
</ol>

In all of this, make sure to bounce ideas off of your interviewer and try to get their input as you work.

As with the test cases, physically write your solution down so that you can refer to it and the interviewer can see it. This gives the interviewer the ability to follow your thought process as you code your solution and will be able to interject if they find that you are straying away from either your intended solution or the solution they envision.

In the next article of this series, we will discuss some implementation strategies to show good coding ability.

Until then, have a good one!
Link CSS and Js Files With an HTML File. 
Tags: css, javascript, html, codenewbie
Published: 2020-05-26 15:49:26


When you’re working with HTML, styles, and scripts and you’re working on a big project, I really recommend separating files in different folders. Have all of your CSS files in one folder and all your JavaScript files in another folder. Do the same for your HTML files.
To link a CSS file with your HTML file, you have to write the next script on your HTML file inside the head tag.

link rel=¨stylesheet¨ type=¨text/css¨ href=¨..\[folder_name]\[file_name].css¨> */

If you have the CSS file in the same folder as your HTML file, you only have to write the name of your CSS file, like this (I recommend having the files in different folders associated by the type):

<
link rel=¨stylesheet¨ type=¨text/css¨ href=¨[file_name].css¨>

If you’re working with a bootstrap theme, you can add the link of the file:

<
link rel=¨stylesheet¨ type=¨text/css¨ href=¨[url_bootstrap_theme]¨>

To link a Js file with your HTML, you only have to add the source of the script inside the body tag or outside; it doesn’t matter.

<
script src="..\[folder_name]\[file_name].js"></script>

If you have the Js file in the same folder as your HTML file you only have to write the name of your Js file, like this (I recommend having the files in different folders associated by the type):
script src="[file_name].js"></script>
If you are working with libraries, like jQuery, you can add the URL of the library in the source.
script src="[url_of_the_js_library]"></script>
I hope this post helped you.
I made a Dribbble shots generator
Tags: showdev, tailwindcss, react, design
Published: 2020-05-26 15:40:15

[Shooot](https://shooot.bourhaouta.com/) lets you upload your website screenshot to adjust it for a Dribbble shot with background color variants and other features: https://shooot.bourhaouta.com/

Your feedback is needed to get to 1.0.0 version.
[Feel free to check the repo](https://github.com/bourhaouta/shot)
GSoC 2020 | Introduction
Tags: webdev, javascript, opensource
Published: 2020-05-26 15:38:02

![Me](https://dev-to-uploads.s3.amazonaws.com/i/70ixang2487kk3945vwp.png)

Hey there :)

Welcome to my **GSoC'20** microblog series. 
I am Prathamesh, an opensource enthusiast working with the Terasology Foundation as a GSoC'20 student developer, during this summer (May-August 2020). I'll be discussing my project (i.e. Tutorial Journey Website) in upcoming posts.

> Github/Discord- TheShubham99
> `offline` - Prathamesh

### `$ Ctrl+z`

> ### `program exited with exit code 0 (0x0)`
CovidBot - Chatbot
Tags: chatbot, covid19, flask, softwaredevelopment
Published: 2020-05-26 15:36:00

A Simple Bot/Agent which will act as a guide for self assessment of probable risks from corona virus and increase awareness about the pandemic. It answers any type of questions related to the pandemic and also tells you about the pandemic's statistics when asked for. The Bot can be also be asked about myths and rumors related and it also has the capability to mail a detailed report regarding the pandemic to the user.

Live Built - https://lnkd.in/ejwx3nK

For more information, refer to my github repository -
https://bit.ly/Covid_Bot

Telegram Bot : https://t.me/r07_CovidBot

Please feel free to suggest any changes or issues. 

Steps for being a successful software developer :)
Vim to the rescue: Subduing the Shell
Tags: vim, todayilearned, productivity, linux
Published: 2020-05-26 15:21:08

## Introduction

How many times have you ran a command on your terminal and copy pasted its output to vim? Maybe you want to include some terminal output data, or maybe you want to create an issue on github by editing it in vim first. 

In this blog we will be learning how to get the output of shell commands in your current vim buffer. 

For reference, here is what we are going to achieve:

{% youtube euwcDjaBOxI %}


## Getting the output of a script

* You can take the output of any shell script and paste it after your cursor position by using the following command:

```vimscript
" . means current line
:.! <shell_command>
```

* Additionally you can take your cursor to the position where the command output ends:

```vimscript
:r! <shell_command>
```

* The best part about this is that you can use the text inside your vim buffer and pass it through the command line. For example if your current buffer contains something like this:

```
My cow says:

cowsay "Hello, World"
```

You can go over to the cowsay command and press the following keys to get the output right in your buffer:

```vimscript
" passes the current line through a shell
:.!$SHELL
```

You will get an output like this:

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

* Not only this, you can take the text from any line and paste its output:

```vimscript
" takes the text in the 5th line as input
:5!$SHELL
```

## Mapping the madness

I have mapped `<Shift> + q` to the `.!$SHELL` command. So pressing the keybinding instantaneously returns the output of the current line when ran through a shell.

```vimscript
noremap Q !!$SHELL<CR>
```
Microsoft and BeMyApp are running a Middle East / Africa Wide Hackathon!
Published: 2020-05-26 15:12:02

Remote work and distributed teams have evolved from the latest office trend to standard business practice creating an entirely new corporate landscape.

While some organizations have embraced a  remote work culture, others have been forced to acclimate due to the recent health crisis and global lockdowns. Whether they’re adopting or adapting to this new model, businesses are searching for innovative ideas  and creative solutions to better their work from home practices and achieve more.

The goal of this online challenge is to boost your creative concepts around remote work, based on Microsoft solutions!

-Main prize is $4000
-Live 1:1 mentorship 
-Live webinars from industry leaders

Register here: https://remoteresilience-platform.bemyapp.com/
🔎 Search through ~6M code snippets using Google-like queries
Tags: machinelearning, django, showdev
Published: 2020-05-26 15:09:54

Hi devs,

I would like to share http://CodeSnippetSearch.net with you, a side-project I have been working on. It allows you to search through 6M code snippets and functions using natural language. Currently Go, Java, Javascript, Python, PHP and Ruby are supported.

The project is built using Python, Djangom and Keras and is using data from the Github CodeSearchNet project. It is open source and hosted on Github: https://github.com/novoselrok/codesnippetsearch

I'm planning on adding a browser extension that would allow you to search selected public Github repositories in the same manner. I think that would allow new users to better explore new repositories compared to the default GH search.
Anybody here doing side projects?
Tags: webdev, webmonetization, beginners, startup
Published: 2020-05-26 15:08:26

Hey, guys!

I'm Roberto Díaz, a **bullshit-free product manager** that has been developing digital products for the past 10 years.

I've been covering the end to end, from inception to growth, going through design, development, team building, management, and launch, going in-depth in each of those stages.

**And all this experience, mistakes made, successes, and lessons learned, are wildly having sex in my head right now.**

That's why I'm taking a gap period to explore, design, and develop my ideas in cycles of 6 to 8 weeks, launch them, and see what happens. 

One of the main problems I had, when I started developing digital products was that I couldn't see anybody more experienced than me doing it. And that made me lose a lot of time and, probably, great opportunities.

So I decided to tell the story, focusing on what works for me and what doesn't, to help you learn about the process.

**Do you enjoy creating side projects?**

Would you like to turn those that work into a business? 

**Then, this could interest you.**

I'm sharing:

- How I'm going from having an idea to launch, going through all the stages in between (analysis, validation, design, and development).

- Obstacles I find, how I overcome them, and what I learn in the process.

- How to apply state of the art techniques and tools, used by leaders in the industry and other successful makers.

- Details and the thought process behind my strategy, goals, and roadmap.

- Resources I find, or I create that help me advance.

- Early access and updates to every product I'm making.

I'll be posting each edition here on Tuesdays.

And speaking of the devil:

**Which is the main obstacle that stops you right now from developing and launching your ideas?**

Feel free to ask. 

I'll try to help you the best I can :)
Limit Request On Public API: Video Upload Form
Tags: api, security, discuss, webdev
Published: 2020-05-26 15:04:56

---
title: Limit Request On Public API: Video Upload Form
published: true
description: Ideas for how I can limit the number of videos a user can upload on a public video upload form. 
tags: API, security, discuss, webdev
---
Hey all, 

I have an idea to let my clients collect video testimonials from their users. I will build a unique but public video record and upload link/page for each one of my clients. Their users will record a video, then click upload on the page. 

My question is how do I protect against abuse such as a user uploading 100s of videos and running up my storage fees? Should I grab the IP of each user uploading then save that to my db, and check it before each upload? Cookies? Local storage? 

Thanks!