Friday 11 March 2022

Learn to code

 As the world of work changes, people who have worked in industries which now have fewer jobs are often give the catchphrase "Learn to code". This is because, while their industry has fewer jobs, there's always plenty of work in coding.

Of course coding is not for everyone, even coders themselves find it difficult sometimes. Coding is quite a broad subject area, certainly since the growth of the Internet. Some of the people who find themselves out of work may conclude, "OK, I'll give this coding a try". Now they are faced with "What is coding?", or better still, "What would I enjoy coding?".

I have devised a framework, which can help someone answer those questions for themselves. It contains a little pain (but not too much) in the setup. It provides a little documentation to push them in a useful direction, without doing all the learning for them.

You can find it here:

https://github.com/guitarbeerchocolate/learn-to-code-environment

Git branch in Ubuntu terminal

This is the code I added to ~/.bashrc around line 59. It affects the CLI prompt in the Ubuntu terminal in a number of ways.

  1. It removes the username and computer name.
  2. It adds the open Git branch, if one exists.
  3. It adds a new line at the end, because some path's get very long, and don't give you much room to add your commands. 

parse_git_branch() {

 git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'

}


if [ "$color_prompt" = yes ]; then

 PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[\033[01;34m\]\w\[\033[01;32m\] $(parse_git_branch)\[\033[00m\]\n$ '

else

 PS1='${debian_chroot:+($debian_chroot)} $(parse_git_branch)\n$ '

fi

Wednesday 9 March 2022

Running XDebug version 3 in VSCodium (or VS Code)

First of all, this is not a tutorial on how to setup XDebug in your PHP environment. It assumes you've already done that.

This is my .vscode/launch.json

{

    "version": "0.2.0",

    "configurations": [

        {

            "name": "Xdebug Browser",

            "type": "php",

            "request": "launch",

            "runtimeArgs": [

                "-dxdebug.mode=debug",

                "-dxdebug.start_with_request=yes",

                "-S",

                "localhost:5500"

            ],

            "program": "${file}",

            "cwd": "${workspaceRoot}",

            "port": 9003,

            "serverReadyAction": {

                "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",

                "uriFormat": "http://localhost:%s/${relativeFile}",

                "action": "openExternally"

            }

        },

        {

            "name": "Xdebug CLI",

            "type": "php",

            "request": "launch",

            "program": "${file}",

            "cwd": "${fileDirname}",

            "port": 0,

            "runtimeArgs": [

                "-dxdebug.start_with_request=yes"

            ],

            "env": {

                "XDEBUG_MODE": "debug,develop",

                "XDEBUG_SESSION": "1",

                "XDEBUG_CONFIG": "client_port=${port}"

            }

        }

    ]

}

It allows me to debug files on the command line (CLI) and in the browser.

How to run through the CLI

First, open the "Run and Debug" tools of VSCodium from the icon on the left-hand side of the IDE.

Next add a break point in your code where you'd like the code to pause. 

Then click the play button to the right of "Xdebug CLI"

You should now have debugging tools above your code, and variables in the variables section.

How to run through a Web Browser

First, open the "Run and Debug" tools of VSCodium from the icon on the left-hand side of the IDE.

Then click the play button to the right of "Xdebug Browser"

You should now have debugging tools above your code, and variables in the variables section.



Tuesday 8 March 2022

How to keep your Ubuntu laptop running with the lid closed

 I wanted to keep using my laptop running but use my external screens, mouse and keyboard.

To achieve this, you need to make the following changes to your /etc/systemd/logind.conf file:

Change the line

#HandleLidSwitch=suspend

to

HandleLidSwitch=ignore

then, change the line

#LidSwitchIgnoreInhibited=yes

to

LidSwitchIgnoreInhibited=no

You will then need to restart, and hey presto!