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!

Friday, 15 November 2019

Useful Docker commands

Start services listed in docker-compose.yml file for the first time

docker-compose up -d

Stop services listed in docker-compose.yml

docker-compose stop

Subsequently start services listed in docker-compose.yml file

docker-compose start

Clean up services listed in docker-compose.yml file

docker system prune

Bring up all services listed in docker-compose.yml file

docker-compose up

Bring up "node" service listed in docker-compose.yml file

docker-compose up node

Clean up all services listed in docker-compose.yml file

docker-compose rm -f

Rebuild your services on restart

docker-compose up -d --force-recreate --build

Log into a container named webserver

docker exec -it webserver /bin/bash

Provide information about the running container "ubuntu".

docker inspect ubuntu

Look for containers

docker container ls
This will give you a list of CONTAINER ID's.

Remove containers

docker container rm -f <CONTAINER ID>

Look for images

docker images
This will give you a list of IMAGE ID's.

Remove containers

docker rmi -f <IMAGE ID>

Look for volumes

docker volume ls
This will give you a list of VOLUME NAME's.

Remove volumes

docker volume rm -f <VOLUME NAME>

Thursday, 25 April 2019

Why use PhpStorm over Atom

I'm just about to do a lot more work with PHP and I will be using PhpStorm. What's so good about PhpStorm. Below are a few examples.

Working with scratch files

New->New scratch file : Creates a file without yet including it in your project.

Refactoring

Select the variable you want to refactor.
Right-click->Refactor->Rename.
All occurrences of the variable will be renamed.

Search everything in your project

Tap the Shift button twice.

Version control

If you already have a repository, one of the options on the PhpStorm welcome screen is 'Check out from version control'. Here you can select your repository type. You will then be asked for the repository location and PhpStorm will load with your repository.
Let's assume your project uses git or Bitbucket.
When you add code to your project a new tab appears at the bottom-left of PhpStorm titled 'Version Control'. This allows you to track, stage, and commit changes.

Databases

When you open up a project which contains a database connection you can work with the database.
A tab appears at the top-right of PhpStorm titled 'Databases'. From here you can click on the '+' button and add a new connection, if the connection has not already been made.
Once the connection has been established, the 'Databases' window shows the database structue, but you also have a console window into which you can add queries such as SELECT * FROM country.
When the query results are displayed in the console, it's possible to edit the data returned.

Vagrant

First set Vagrant up in your project
Tools->Vagrant->Init in Project Root
If Vagrant is not set up on your computer a dialogue box appears asking you for configuration details of Vagrant.
If Vagrant is set up on your computer a dialogue box appears asking you for your chose Vagrant instance.
Once Vagrant has been set up you can move 'Remote Host', find a file, right-click and select 'Edit remote file'.

REST

In your project you can test RESTful web API's for your project before you add the code.
Tools->HTTP Client->Test RESTful Web Service

Emmet built in

Type a tag name followed by TAB
e.g. html:5
e.g. html>head+body

Wednesday, 24 April 2019

Using Windoze for the first time in years

I'm having to use Microsoft Windows 10 for some work. I haven't touched Windows since XP. Here are some things which I thought would be useful.

The 'Start menu' is that ugly stuff at the bottom left which appears when you click on the Windows icon. It may look bad now, but when Microsoft brought out Vista etc, things looked so much worse.

Pin an application to the start menu

Left click on the Windows icon at the bottom left of the desktop. This shows the Windows 10 primary start menu ('Start menu').
Find your application shortcut by going through the alphabetically ordered list in the 'Start menu'.
Right click on your chosen shortcut.
Choose 'Pin to start menu'.

Remove an application from the start menu

Left click on the windows icon at the bottom left of the desktop. This shows the 'Start menu'.
Find your application shortcut icon within the 'Start menu' on the right.
Right click the icon and choose 'Unpin from start'.

Pin an application to the taskbar

Left click on the windows icon at the bottom left of the desktop. This shows the 'Start menu'.
Find your application shortcut by going through the alphabetically ordered list in the 'Start menu'.
Right click on your chosen shortcut.
Choose 'More' -> 'Pin to taskbar'.

Settings

Left click on the primary 'Start menu'.
To the far left are a small number of small icons.
Choose 'Settings'.

Notifications

Left click on the primary 'Start menu'.
To the far left are a small number of small icons.
Choose 'Settings'.
Choose 'Notifications & actions'.
Turn off some of those pesky apps which send you notifications when you're trying to work.

Keyboard shortcuts

Alt + Tab : Switch between open apps
Alt + F4 : Close the active item, or exit the active app
Windows logo key  + L : Lock your PC
F10 : Activate the Menu bar in the active app
Ctrl + Esc : Open Start
Ctrl + Shift + Esc : Open Task Manager
Esc : Stop or leave the current task
Windows logo key  + E : Open File Explorer
Windows logo key  + I : Open Settings