Skip to main content

80 posts tagged with "tips"

View All Tags

Linux - Take advantage of the number of CPUs you have; start concurrent jobs

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

Linux - Take advantage of the number of CPUs you have; start concurrent jobs

In my professional activity, I've been faced with the following requirement: process each line of a CSV file and make a POST API call to upload a document.

One line of the CSV contained information that needed to be communicated to an API service, and each line corresponded to a PDF file. So if there are 1000 lines in the CSV file, I have to make 1000 API calls to upload 1000 PDFs.

I wrote my script in Linux Bash and then it was time to optimise: not just one API call at a time, but as many as possible.

Let's how we can start more than one task at a time using Linux Bash.

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.

Git - Some tips for your .gitconfig file

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

Git - Some tips for your .gitconfig file

In this article, we're going to explore some tips for using Git more easily by customising the ~/.gitconfig file.

We'll create a new git undo command to abandon the last local commit.

We'll see how to share Windows Credentials manager with Linux, to have multiple credentials based on your folders structure, ...

We'll also see how to better works with branches like sorting them by commit date instead of their name, to automatically prune (remove) old branches or to force the creation of a new branch on the remote.

WinSCP - Download files with specific extension recursively

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

WinSCP - Download files with specific extension recursively

The WinSCP FTP client support scripting as we can read on https://winscp.net/eng/docs/guide_automation.

In a previous life, I was often faced with the need to download a certain type of file, e.g. connect to an FTP server and retrieve PHP files locally for analysis.

Since WinSCP allows automation, it's easy to write a little script to do just that.

As an example, we'll thus download any .php files from a host.

WinSCP - Visual Basic for Application use

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

WinSCP - Visual Basic for Application use

WinSCP is a free, open-source file manager for securely transferring files between your computer and remote servers using protocols like SFTP, FTP, SCP, and WebDAV.

Did you know that you can call WinSCP from ... VBA code?

See https://winscp.net/eng/docs/library_vb#using. There are also several posts in the forum: https://winscp.net/forum/search.php?mode=results

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.

Linux - Generate documentation from Bash scripts

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

Linux - Generate documentation from Bash scripts

When writing Bash scripts, I'm always putting some description block in front of any functions like I do in any language (think to PHP Docblock).

With PHP, there are a few tools like phpDocumentor for extracting these blocks and generate documentation but do such tools exist for Bash? I don't know, I haven't found any.

So I've written a small Bash script to accomplish this i.e. parse any .sh file present in a folder, extract doc blocks and create one markdown document for any retrieved script. Each function's documentation will then be copied in Markdown, then a table of contents will be appended and, finally, a generic readme.md file will display the list of markdown files retrieved.

Linux - Compare two versions of the same script

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

Linux - Compare two versions of the same script

Still faced with the problem of having to compare two versions of the same script (see the article Linux - Comparing two folders/files in the console), this time we're going to consider that the file we need to compare is a Bash script and that we have two versions of it.

And that we may have made the two files evolve in different ways, i.e. that one or other, or even both, of the files may have been modified.

The aim is therefore to compare the versions and highlight the differences.