Skip to main content

26 posts tagged with "vscode"

View All Tags

Todo Tree in VSCode

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

Todo Tree in VSCode

When you're working on a large codebase, soon or later you'll find some annotations like @TODO or // TODO put there by people (perhaps you) as a reminder for "Don't forget to (do something)...". And, for sure, these todos remain there months or years because, yup, the programmer forgot they were there.

Personally, I sometimes work on code and comment on the call to a particular method or block. Often during a debugging session (for example on Linux Bash scripts) but, danger, don't forget to remove the comments and return the code to its original state. In that situation, I add a comment like // TEMPORARY just before the first commented line.

The idea behind the Todo Tree vscode addon (you can find the download page here) is to summarise such annotations and display a dashboard with all TODOS, TOFIX, ... and your owns too.

MS Office - Load dropdown from Excel's range

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

MS Office - Load dropdown from Excel's range

In this article, we'll see how, very easily, we can load an Excel range into a ribbon and display it inside a dropdown.

The idea is to provide a list of values in a ribbon but to not have to hardcode values in the list but, just, to link to a range, anywhere in your workbook.

I've used this technique in many of my Excel application's (i.e. Excel having VBA code).

For this blog post, we'll create a list of periods (YYYYMM) in a worksheet and load that list in our custom ribbon.

In this way, we could offer a nicer user experience by proposing a list and executing, for example, a query to a database to obtain the data for this period (or anything else).

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