teleren/devto huggingface dataset:
Testing Form Requests with PHPUnit
Tags: laravel, testing, webdev, php
Published: 2022-02-11 20:41:07

Countless are the times I've had to test for validation errors, and countless are the times I've repeated the same code for this purpose. Duplicating testing code is not always a bad thing though, but for validation errors, I don't know, it doesn't feel right. If it is acceptable to test one FormRequest with duplicated code, it's a sin to do that for a whole project. And I've been guilty. 🤣

What I'm talking about looks like this:
{% gist https://gist.github.com/GeniJaho/e1d9ca435ed17169f753454a2132b04c %}

Every method has the same setup phase, the same action, and the same assertions. The only difference is the data being provided with the request, and the errors that are expected to be returned. I don't usually like to check for specific error messages, as it makes the tests more fragile. The error key should suffice most of the time.

##Refactor into a common method
The obvious solution here is to refactor into a method that encapsulates the common logic. Let's do that and see what we get:
{% gist https://gist.github.com/GeniJaho/6531b89361a6fc6ef34643afe1c19a5e %}

This looks a lot better and cleaner. However, we can go a step further, as PHPUnit offers some helper methods called [Data Providers](https://phpunit.de/manual/3.7/en/writing-tests-for-phpunit.html). Essentially, a data provider is a method that returns data that other tests depend on. This allows you to execute a single test multiple times, but with different input, which is perfect for our example. The data provider must be a `public` method, and return a list of input values. The test that uses this provider will run for each element in the list.

##Refactor into a Data Provider
To utilize data providers, we simply annotate the method on the tests we want it to run with. Our finished example looks like this:
{% gist https://gist.github.com/GeniJaho/d4a1310e3307151811da7dfaeda4831e %}

Pretty neat, right? When you run the test it shows that it's run 4 times, each with its own data, like this:


![Test run results](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o7xc5yvv7q942sa7yuyt.png)

Also, when one of the tests fails, you'll get a message indicating which dataset is making the test fail. So helpful. You can even provide keys, and you should, to the data provider array; those keys will be shown on the test results instead of `with data set #0`.

Form validation testing is not the only use-case for data providers though. They're very helpful in any case where you need to test an object's implementation with different input values, or testing `switch` statements, etc.

> The code used for illustration is taken from the [OpenLitterMap](https://github.com/OpenLitterMap/openlittermap-web) project. They're doing a great job creating the world's most advanced open database on litter, brands & plastic pollution. The project is open-sourced and would love your contributions, both as users and developers.

---

Originally published at [https://genijaho.dev](https://genijaho.dev/blog/testing-form-requests-with-phpunit-in-laravel).
Python 101: Ultimate Python guide
Tags: python, codenewbie
Published: 2022-02-11 20:19:14

Python is a high-level and interpreted language that serves a wide range of purposes in programming. Due to its many libraries and frameworks python is used in web development, data science, artificial intelligence, and automation. Python ahs simple syntax and is also portable across multiple platforms.
When learning python I found the following concepts to be the most important for a beginner. 

## Variable
A variable is a defined memory location. In python variables can be defined and assigned values.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h6mm4xv8jxcjlhjqge0j.PNG)
## Output
Python provides the inbuilt function print()to display variables, literals, or any other values.  
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/34t1lcri4ocv99ciovi0.PNG)

## Comments
Comments are lines of code that are not executed. They help to document the code and make it easy to explain some of the complicated parts to other people. In python comments are preceded by the # symbol. 

## input
Python allows for the program to request for user-defined inputs. 
It uses the input() function

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c78fuzhjlx88cqo2qpwv.PNG)
## function
Functions are blocks of code that contain a set of operations. The functions enhance reusability of code. They can be inbuilt or defined by the user. Functions in python are declared using the **def** keyword.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0qvd6yqctx9qdvh1v17r.PNG)
## Data structures
Data structures provide a way to organize data. they are like containers that can store multiple values of the same or even different data types. They include tuple, lists, dictionary, set, array.  
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ptxykxz6rq4ef1l1m6wn.PNG)
## Decision making
Decision making is an important aspect to programming. Some lines of code are only executed while a specific condition is valid conditions or when a specific condition is met. The major key words in decision making and looping are; while, for, if--else.  

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p9g9pww2unktf559l4qd.PNG)
In the next article I will write longer programs that analyze decision making and data structures in a more comprehensive manner. The concepts discussed in this article do not exhaust the basics of python but act as a guide to someone who is thinking of starting the python learning journey.
How to make a "Save" button using JavaScript?
Tags: webdev, begginer, help
Published: 2022-02-11 20:07:38

I'm working on a little project, and want to add a "Save" button which will when clicked convert everything which is inside of a certain div class into a downloadable .txt (or .pdf or any other document viewing file type) document.

I want to note one more thing, the content of that div isn't "static" (if I can call it that), since the user / visitor can edit it, to clarify, the user / visitor can delete the text in that div, as well as add new text to that div. I'm not sure does this make any kind of difference, but there it is just as a little note.

Is this possible?
Piece By Piece #2
Tags: devjournal, pov, discuss
Published: 2022-02-11 20:02:33

Seeing the tiny parts of the universe scattered about in a picture frame made me wonder how all the irregularities could be in order.

God is funny and confusing at times but that's just how He is.

I learned a lot of things from improvisation which sometimes made me embarrassed and devastated.  However, it actually made me stronger and more aware of how beautiful the process is.

Process is a very firm time, with the human process will find its place.
The future will be very very difficult, but when I've gone through the previous processes well
The future will be beautiful in the eyes, it will be fun to feel
Forge: By far the best tiling extention for the Gnome desktop
Tags: gnom, linux, desktop, tilingwindows
Published: 2022-02-11 19:36:49

I recently discovered the Forge extention for the Gnome desktop environment. Before that I had been using the Material Shell, but it had no dock, works ugly and buggy with other extentions etc.
Forge does not has this issues. It is well integrated into the desktop, it respects title bars and it works pretty well and fast, without issues. You can also say things like: Let window 1 and 2 be in a stack layout and window 3 is floating. You also don't have static layouts like grid or horizontal or vertical, you have "your own" layout with forge. You just need to move the window over other windows and you get snap assistants.

I tested the Forge extention https://github.com/jmmaranan/forge in Gnome 3.36 on Linux mint.
🚀 Angular 13 + ESLint, Material + Transloco + Jest, TestCafe + Docker + Prettier 🚀
Published: 2022-02-11 19:16:29

This is the Angular 13 Starter project you are looking for!
With Material, Transloco, Jest, Compodoc, Docker Support, ESLint & Prettier

**GitHub**
https://github.com/wlucha/angular-starter

## Features

✅ [Angular 13](https://angular.io/)
✅ [Angular Material](https://material.angular.io/)
✅ Unit Testing with [Jest](https://jestjs.io/)
✅ End-to-End Testing with [TestCafé](https://testcafe.io/)
✅ Internationalization with [Transloco](https://github.com/ngneat/transloco)
✅ Auto documentation with [Compodoc](https://compodoc.app/) 
✅ Analyse your project with [webpack-bundle-analyzer](https://www.npmjs.com/package/webpack-bundle-analyzer)
✅ [Docker](https://www.docker.com/)
✅ [ESLint](https://eslint.org/)
✅ [Prettier](https://prettier.io/)
✅ [Commit Linting](https://github.com/conventional-changelog/commitlint)

## Demo

[![StackBlitz Demo](https://user-images.githubusercontent.com/7531596/83507657-2424e180-a4c9-11ea-8e4f-b3f8e7d6b4c5.png)](https://stackblitz.com/github/wlucha/angular-starter)

## Install / Development

```bash
# Clone the project
$ git clone https://github.com/wlucha/angular-starter
$ cd angular-starter

# Install dependencies
$ npm install

# Start server
$ npm run start

# Open in browser: http://localhost:4200
```

## Docker Deployment

```bash
# Build Docker image
$ docker build . -t angular-starter

# Run Docker Container
$ docker run -p 3000:80 angular-starter
```

## Docker Hub

https://hub.docker.com/r/wlucha/angular-starter

## Commands

- `npm run start` - start the app
- `npm run lint` - lint the project
- `npm run test` - run unit tests
- `npm run build` - build the project
- `npm run build:prod` - build the project in production mode
- `npm run build:prod:stats` - build the project in product mode with stats
- `npm run analyse` - analyse bundle with [webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer)
- `npm run compodoc` - generate [compodoc](https://github.com/compodoc/compodoc) documentation
- `npm run changelog` - generate changelog
- `npm run prettier` - format the whole project

**GitHub**
https://github.com/wlucha/angular-starter
Building Website from Scratch - Part 4
Tags: webdev, shriekdj, codewithshriekdj, beginners
Published: 2022-02-11 19:02:21

## Preface.

So Now I Made Some Changes About the Sections of HTML Page and also link blank CSS And JS ( JavaScript ) file in `index.html`.

---

## Section Addition in `<body>` tag.

I Added Given Code in body tag after the `div` tag with `wrapper` class.

```html
<!-- Main Section -->
<main class="main">
	Main Section
</main>

<!-- Footer Section -->
<footer class="footer">
	Footer Section
</footer>
```

---

## Blank Style-sheet and JS ( JavaScript ) file Is Created and Linked.

I Created and linked the Blank file with Some New Folder.
> Given Below Is Image of The Structure


![File Structure of The Site](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xauo49wuku6a0g31kpr8.PNG)

```html
static/
  js/
    script.js
  styles/
    style.css
index.html
LICENSE
README.md
```

---

### Added link to Style-sheet and Script file.

Used the `./static/styles/style.css` and `./static/js/script.js` type path with forward slash not backslash for future use in any Type of Operating System

### Within head tag

```html
<link rel="stylesheet" href="./static/styles/style.css">
```

### At the Last of Body Tag

```html
<script src="./static/js/script.js">
```

---

## Pull Request

{% github https://github.com/shriekdj/site-from-scratch/pull/9 %}

---

## GitHub Repo

{% github shriekdj/site-from-scratch %}
Tipos primitivos em Python
Tags: python
Published: 2022-02-11 18:59:51

A pouquissimo tempo eu me interessei por Pyhton com o intuito de aprender inteligência artificial e análise de dados. Essa jornada começou esse ano, tenho muito que percorrer, e como provavelmente meu foco vai se voltar mais para Python mesmo eu amando JavaScript vou tentar sempre postar meu progresso, mais como um jeito de revisar meu conhecimento e reafirma-lo.
Começando do começo **O que são tipos primitivos?**
Tipos primitivos são tipos de dados primitivos(básicos), ou seja tipos de dados que podemos manipular dentro de uma variavel, por exemplo:
```Python
dinheiro = 1.50
```
No código a cima temos uma variavel nomeada como dinheiro contendo um valor, um dado de 1.50, por ser um valor com casas decimais o tipo deste dado é o tipo real ou **float**. Para ficar mais claro vamos a outro exemplo:
```Python
nome = 'Dormin'
```
Certo agora percebemos que o valor a cima não é mais um dado do tipo real, agora se trata de um dado do tipo de texto ou **string**.
Agora que já sabemos o que é um tipo primitivo vamos aos **tipos primitivos em python** que são:

* Inteiro - int -> Numeros inteiros( -2,-1,1,2,3,4....)

* Real, Ponto futuante - float -> Numeros com casas decimais(2.56)

* Booleano - bool -> verdadeiro ou falso (true, false)

* complexo - complex -> aindanão sei tenho de pesquisar mais :c

* String - str -> textos alfanumericos("o rato roeu a roupa do rei")

Para conferir cada tipo podemos usar a função type.
```Python
nome = 'Dormin' #string
idade = 26 #int
altura = 1.75 #float
humano = true #bool

type(nome)
```
Espero ter ajudado conforme for aprendendo postarei cada vez mais :)
Four Ways Get Last ID of an Inserted Model - Laravel
Tags: php, laravel, webdev, programming
Published: 2022-02-11 18:46:24

I found this great resource https://www.larashout.com/laravel-8-get-last-id-of-an-inserted-model which contains 4 methods Get Last ID of an Inserted Model It's great to share this as from projects I needed to get an ID I will show briefly, but visit the source to go deeper.
1. Using Eloquent Save Method
```php
$product = new Product();
$product->name = "product name";
$product->save();

$productId = $product->id();
dd($productId); // will spit out product id
```
2. Using Elogquent Create Method
```php
$product = Product::create(['name' => 'product name']);

$productId = $product->id();
dd($productId); // will spit out product id
```
3. Using DB Facade (insertGetId())
```php
$productId = DB::table('products')->insertGetId(
    [ 'name' => 'product name' ]
);

dd($productId); // will spit out product id
```
4. Using getPDO() Method (lastInsertId())
```php
$product = DB::table('users')->insert(
    [ 'name' => 'product name' ]
); 
$productId = DB::getPdo()->lastInsertId();.

dd($productId); // will spit out product id
```
I hope you enjoyed.
BLOCKCHAIN DEVELOPER
Tags: beginners, programming, react, blockchain
Published: 2022-02-11 18:45:21

THANKYOU DEV COMMUNITY FOR THE WARM WELCOME
MY NAME IS AMIT KUMAR MOHANTY,
I AM A FRONT END DEVELOPER 

I tried learning about web from internet and youtube, i got know to be a block chain developer we have to start from solidity then go for truffle and ganache to use EVM and with help of those i wrote some erc20 token code and small projects using solidity remix ide an met mask ,

now that i am trying to learn how to build Dapps and write erc721 i.e smart contracts i didn't find any structured content where i can learn and write my own dapps and smart contracts

i wanted some help with resources and videos from where i can study and start building Dapps 


**Any kind of help is highly apperciated**
Hello..👋Guys ..! Today i recevied my HacktoberFest 2021 SWAGS.!
Tags: hacktoberfest, digitalocean, github
Published: 2022-02-11 18:24:42


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ggb2a5z2ckf8crarld6w.jpg)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u2lkzwimmhposz3tgjho.jpg)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j2czplgs64oeflkdbi4x.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/02osu78uuk9xxz1g901o.jpg)Today I received my HacktoberFest 2021 SWAGS stickers and t-shirt for making 4 successful PR's on GitHub..!
Cyber Security awareness for everyone
Tags: cybersecurity, github, techtalks, security
Published: 2022-02-11 18:03:40


[![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k23jdk4ufmniy50xnddm.png)](https://www.hackforchange.co.in/events/cyber-security-awareness-for-everyone)
**Description**
Cyber Security is a global phenomenon representing a complex socio-technical challenge for governments but requiring the involvement of individuals. Although Cyber Security is one of the most critical challenges businesses face today, visibility and public awareness remains limited. Almost everybody has heard of Cyber Security. However, the urgency and behaviour of persons do not reflect a high level of understanding. 

**About the speaker**
[Devang Jain](https://devangjain.com/) is a final year Computer Science undergraduate student at the Indian Institute of Technology, Goa. He is a CompTIA Security + Certified Specialist and the founding member of the InfoSec Club of IIT Goa. He has interned previously at Safe Security and is planning to pursue a Master's in Cyber Security in the future.

**Speaker’s Point of View**
Seeing friends and relatives falling into the traps of phishing emails, using/reusing weak passwords, running outdated software/applications, and posting personally identifiable information on social media. I felt there was a lack of awareness in society in terms of protecting data security and privacy. Moreover, I was alarmed after reading a report by Cybint that said, "Human error is the cause of up to 95% of Cyber Security breaches. With simple awareness training courses, this number can be dramatically reduced." Thus, I genuinely believe that learning how to stay cyber secure is the need of the hour, and through educating ourselves and our peers, we can remain safe from the rising cyber-attacks.

**For More:**
Sign up here: [HackForChange](https://www.hackforchange.co.in/events/cyber-security-awareness-for-everyone)
What's the difference between var, const and let
Tags: javascript, webdev, programming, beginners
Published: 2022-02-11 17:59:41

## The quick answer:
- `var` has a different "scope" and it's normally better to use `const` and `let`
- `const` is for variables that will not be updated
- `var` is for variables that will be updated

## Var

Before `const` and `let` the only way to declare a variable was with `var`. The sope of `var` -- where it can be accessed after it's been defined -- is global and function. So if it is defined outside a function it is globally scoped and available anywhere in the program. If it's defined in a function then it is function scoped and only available in that function. `const` and `let` on the other hand are block scoped. They are available in whatever block they are defined in. A block is anything inside curly brackets `{}`

The use of `var` can be confusing in blocks such as for-loops where you can inadvertently update the global scope, when you only want to update the block scope. For example

```
for (let i = 0; i < 5; i++){
  console.log(i) // 0/1/2/3/4
}
console.log(i) //undefined
```
```
for (var i = 0; i < 5; i++){
  console.log(i) // 1/2/3/4
}
console.log(i) // 5
```

For this reason it is preferable to use `const` and `let` over `var`

## const 

When you assign a value to a variable using the `const` keyword you tell JavaScript that you won't assign a new value to it. If you try, you will get an error. 


![Untitled (Postcard) (1).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1643121653526/j3Pz2tSyW.png)

It is worth remembering that while you can't update `const` with a new value, you can still change the content of the variable. This is the case in objects and arrays. The below is valid


![Untitled design (9).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1643125125410/yo-qqVmTa.png)



## let

Use `let` when you will need to update a variable later in your program. You still can't reassign a `let` variable once it's been declared. For instance you **couldn't** use `let cat = "mogy"` and then `let cat = "felix"` but you can update the variable with `cat = "felix"`. 

Unlike with const, you an initialize a variable with `let` without assigning it a value. The variable will then be undefined until you update it with a value

```
let number // number is undefined
number = 5 // number is 5
```
11/2 - DotnetCore masters
Tags: umbraco, donetcore, lego
Published: 2022-02-11 17:57:13


This week most of the talks from the Dutch Umbraco Festival DF21 were uploaded to youtube - if you fancy attending a virtual confrence, in your own time, they are well worth a watch.

https://www.youtube.com/watch?v=AKGjdiquA1I&list=PLh_jm4oU4mFfkLsSXZDEKozkp07djRoFO

--- 

My own personal dotnet core journey continues. This week I have been learning about custom middleware and content buffering. [Mark Ashley Bell, has a good post on this](https://markb.uk/asp-net-core-read-raw-request-body-as-string.html). I particularly like the example of how to register the custom middleware for only some routes. 

```cs
app.UseWhen(
    ctx => ctx.Request.Path.StartsWithSegments("/home/withmodelbinding"),
    ab => ab.UseMiddleware<EnableRequestBodyBufferingMiddleware>()
);
```

_At some point i should probably write up how to then use a `UmbracoPipelineFilter` to do this in an Umbraco package without changing startup.cs - because at the moment [the only results are those from me asking about it in forum post](https://www.google.com/search?q=Umbraco+pipeline+filter&oq=Umbraco+pipeline+filter&aqs=edge..69i57j69i64.3399j0j4&sourceid=chrome&ie=UTF-8)_

---

Sometimes you start to answer a question on the forums and think, that should really be a blog post. I really should do that for this one to Owain about [how I setup for package dev](https://our.umbraco.com/forum/using-umbraco-and-getting-started/108231-package-creation-questions).

---

Looking for some unwind TV his week ? Lego Masters Australia is well worth a watch, it a bit like Lego Masters UK but its better, builds are bigger and the challenges are cooler. In the UK [Season 2 is currently playing out on All4](https://www.channel4.com/programmes/lego-masters-australia)
HELP Opacity problem in images and text.
Published: 2022-02-11 17:52:12

Hey guys, im new in coding. I was trying an images on background with opacity 0.6. The problem is my text is getting opacity too ! I make two different divs but it doesn't work. Can you help me ?


```
    <style>
        .background {
            background-image: url(barhold.jpg);
            background-size: cover;
            filter: alpha(opacity=60);
            opacity: 0.6;
        }

        span {
            color: red;
            opacity: 1;
        }
    </style>
    <title>Document</title>
</head>

<body class="w-75 mx-auto my-4">

    <div class="background">
        <div class="container">
            <span>
                <h1>Lorem ipsum dolor sit amet.</h1>
                <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dolore ullam recusandae
                    consequuntur
                    eligendi numquam vitae doloremque itaque quam, reiciendis perspiciatis.</p>
            </span>
            <hr>


        </div>
    </div>

```
#008 How to Enable Dark Theme in SQL SERVER Management Studio 18 in 6 quick steps
Tags: ssms, sqlserver, darktheme
Published: 2022-02-11 17:50:20

> 
**Step 1:** Open Windows explorer C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE

> 
**Step 2:** Find ssms.pkgundef

> 
**Step 3:** Open the file from the step 2 as an Admin and edit the line FROM
```
         [$RootKey$\Themes\{1ded0138-47ce-435e-84ef-9ec1f439b749}]
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/njw43dmquvcyd3wh5uuc.png)
 
TO
```
        // [$RootKey$\Themes\{1ded0138-47ce-435e-84ef-9ec1f439b749}]
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8s6k1lox317t9yki22l2.png) 

> 
**Step 4:** Save and close the file

> 
**Step 5:** Restart the SQL Server Management Studio

> 
**Step 6:** Go to Tools >> Options >> Environment >> General and set DARK theme options and SAVE

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ijkyea9t6n7m00q01ulm.png)
 

###**ENJOY your SSMS Dark mode and write world class queries :)**