Skip to main content

24 posts tagged with "vscode"

View All Tags

Format poorly formatted PHP code

· 2 min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

Format poorly formatted PHP code

You're recovering some old PHP code; you want to answer a question asked on a forum and the person who posted the PHP question didn't take care to ensure that it was properly formatted; ... there are too many occasions when the syntactic quality of a code can be rotten.

You'd like to have an online tool that you can use to quickly retrieve code with a much more polished layout, just by copying and pasting. Without having to install anything and without any headaches.

For example, how do you make the code below look cleaner in five seconds?

<?php
abstract class mycollection implements Iterator
{
protected function populate($array, $dataobject){
foreach($array as $item){
$object = new $dataobject();
foreach($item as $key => $val){$object->$key = $val;}
$this->storage[] = $object;
}}
}

JSON - Faker & Mockup

· 4 min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

JSON - Faker &amp; Mockup

I recently worked on an ETL project in Python. Among other things, the script had to process JSON files that users dropped into a specific folder.

As this was a sensitive application, it was important to validate the script by submitting fake JSON files, but also to ensure the quality of the files received.

For the fake files, I used a tool like the Faker library for Python.

JSON - Online linter

· One min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

JSON - Online linter

Exactly like my SQL - Formatting tool, it's always useful to have a tool in your favourites that lets you copy/paste a JSON character string and display it as a tree-view with or without code folding feature.

I use it quite regularly when I'm writing a JSON string and I want to check that there are no syntax errors (lint) or, on the other hand, and for example, when I call an API that returns JSON and I want to analyse the code received. In these cases, the collapse functionality comes in very handy.

Write PHP unit tests using Pest

· 8 min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

Write PHP unit tests using Pest

If you think writing unit tests in PHP is fun, stay in the room; the rest of you please leave. And then everyone leaves, including the person who asked the question.

Writing “old-fashioned” unit tests with PHPUnit is so boring that almost nobody does it.

And for some time now, https://pestphp.com/ has come along and totally changed the way things are done.

Pest is a wrapper around PhpUnit so, for instance, every command line arguments supported by PhpUnit can be used for Pest.

Using the JetBrains Mono font in vscode

· 2 min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

Using the JetBrains Mono font in vscode

As you know, VSCode is highly customizable; you can install plethora of addons, change the default theme and use your preferred font.

Just take a look on the JetBrains Mono font. This is a free of charge font, for both commercial and non-commercial purposes.

In addition to the fact that it is particularly legible, making it much clearer to distinguish between an O (the letter) and a 0 (the number), between an I (upper-case I) and an l (lower-case l); JetBrains Mono font comes with nice ligature elements.

Working with regions in VSCode

· 5 min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

Working with regions in VSCode

VSCode supports region and endregion tags but not everywhere. These two special tags can be written differently depending on the language you're using but have, always, the same objective: allow you to fold part of the code.

Not everywhere means, for instance, VSCode didn't support code folding by default in Dockerfile. Let's see how to solve this.

PHP Getter and Setter in VSCode

· 3 min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

PHP Getter and Setter in VSCode

Because you're an excellent developer, you deny anyone access to the properties of your class directly, but only via a getter or setter.

In other words, in your PHP class, you don't have public properties (they're devil) but exclusively protected ones or better private.

And using getter and setters you allow other objects to interact with your private methods by reading them (getters) or updating their values (setters).

Some people will say "Yes, but it's tedious to write these functions", but not at all.

CodeSnap addon for VSCode

· One min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

CodeSnap addon for VSCode

The extension CodeSnap will take beautiful screenshots of your code in VS Code without effort.

Open your file in vscode, select the desired lines, press CTRL-SHIFT-P, run CodeSnap. You just need to select lines now.

CodeSnap partial example

Export the list of extensions you've installed in VSCode

· One min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

Export the list of extensions you&#39;ve installed in VSCode

A small tip: by running code --list-extensions in a console (Linux or DOS), you'll get the list of all extensions you've installed in VSCode.

Now, just copy/paste that list and you can send it to a friend Hey, here are the extensions I use. Maybe one or the other will be useful to you..

Multiple cursors in vscode

· 2 min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

Multiple cursors in vscode

One of the best features in vscode is the Multiple cursors one.

Imagine you've a bunch of lines where you need for instance remove the first two characters. Each lines starts with '//' and you wish to remove them but only there (a search & replace can't be used).

Or, for another example, you must enclose each line in double brackets.

With vscode, it's ultra-simple: multiple cursors.