Skip to main content

84 posts tagged with "tips"

View All Tags

Docker - Install and use Git in a container just like you do on your host

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

Docker - Install and use Git in a container just like you do on your host

So, no need to tell it anymore, I'm doing everything in Docker containers even coding (since I'm coding using devcontainers) but ... till now, I was using git on my host only.

I mean, I need git on my host because I should be able to clone a repository. But the question is: should I use git from my host except for git clone? Can I work in my container and from there do actions like a git push?

My current workflow is: from my host, I'm cloning a repo on my disk then I build Docker image(s), run container(s) and jump in it (like starting my devcontainer). I start too a console in my container to start processes, work on files, ...

From time to time, I push my changes to my versioning system (like Gitlab/GitHub) and here is the point: I need to exit my devcontainer (or use another console), go back to my host and run, from my host, commands like git add . && git commit -m "feat: The great feature I'm working on it" && git push.

Let's see how to improve this process and be able to run git commands from inside our container.

Search your FTP server at lightning speed

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

Search your FTP server at lightning speed

Did you know that using WinSCP, you can run a search on your FTP to find all the documents containing a given string? It's native in WinSCP; nothing more to install but...

However, it's insanely slow; let's see how we can do it better and almost instantaneous.

Git - pre-commit-hooks

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

Git - pre-commit-hooks

You like clean code, don't you? And you hate getting an email from your versioning tool (e.g. Github or GitLab) telling you that your last commit didn't go through, that the formatting of your code is bad; this is because you've left one space too many at the end of a line or you've used single quote instead of double (or the opposite), for example.

You've pushed your changes, already start to work on another activity, perhaps another project and boum, two hours after your last commit (because the CI server was working on a lot of pipelines before yours), boum, you get a Your last commit has failed, #gnagnagna. I hate it as much as I love clean code.

So, what should we do to avoid this?

The answer is simple! Before each push, we should run the same code analysis tools that are executed in the CI, i.e. phplint, php-cs-fixer, phpcbf, phan, phpstan, ... (for PHP) or pylint, mypy, prospector, black, ruff, ... (for Python) or shellcheck and shellformat (for Linux Bash) or ...

We should, but do we think about it every time? Unfortunately not.

Let's see how to correct this.

Using Docker init to quickly dockerize your PHP application

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

Using Docker init to quickly dockerize your PHP application

How about asking Docker to create the files it needs itself?

If you're a regular reader of this blog, you'll know by now that you need a Dockerfile to describe how the Docker image should be created and what should be included in it, and very often you'll also need a composer.yaml file to explain how the container should be created, e.g. which port to map to, which volumes to use, and so on.

Imagine you've an existing PHP application and you don't want to create the files needed for the dockerization by hand.

You just want to very quickly and using a wizard, to be able to answer to some questions and hop, it's ready.

The docker init command is the one you're looking for.

Markdown - Convert CSV to Markdown tables

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

Markdown - Convert CSV to Markdown tables

See also Markdown - Convert Excel ranges to Markdown tables.

Next to my XLS2MD script, you can also convert CSV file to Markdown very easily.

Just copy/paste your CSV content like the one below on the main text area appearing on Markdown - Convert CSV to Markdown tables and enjoy.

Column 1 Header,Column 2 Header
Row 1-1,Row 1-2
Row 2-1,Row 2-2

Markdown - Convert Excel ranges to Markdown tables

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

Markdown - Convert Excel ranges to Markdown tables

See also Markdown - Convert CSV to Markdown tables.

I'm a big fan of Markdown for my documentation, and from time to time I have to convert a range in Excel into a table to copy and paste into my documentation.

Years ago, I've found this repo https://github.com/jonmagic/copy-excel-paste-markdown and it's was the trigger for creating an online application in VueJS to make the magic happens.

In practical terms, I open my Excel file, select a range (a series of columns and rows) f.i. $A$1:$J:$50, press CTRL+C on the keyboard, switch to my Markdown - Convert Excel ranges to Markdown tables website, press CTRL+V and the table is converted.

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;
}}
}

Keep running and count the number of files in a folder using inotifywait

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

Keep running and count the number of files in a folder using inotifywait

Over the last few weeks, I've been working on a Python script that generates PDFs. My script had to generate 70,000 of them and that obviously takes a while.

My idea was to have my script run in a Linux console and, in a second console, with a counter that increases with the number of files that have been created on the hard disk.

The first script will be in Python and I wanted something ultra-simple and using a simple Linux command.

The command ls folder_name | wc -l works but didn't stay running. Let's see how we can do better with inotifywait.

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.

Drawdb-app - Render your database model as png, markdown, mermaid, ...

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

Drawdb-app - Render your database model

In my RSS feed recently, I came across another great application that lets you create a database model from scratch, i.e. create tables one by one and create the links between them.

However, there's another option that I find really nice: you can get a visual of the tables and relationships of any existing application in a few seconds from an .sql file that you import into drawdb-app.

Let's take a quick look at how it works.