#!/usr/bin/env bash BASE_DIR=$1 if [ ! -d "${BASE_DIR}" ] ; then echo "$BASE_DIR is not a directory"; fi ## Find those files that are older than a month find "$BASE_DIR" -maxdepth 1 -mtime +30 -type f -name '*.jpg' | while IFS= read -r file; do ## Get the file's modification year year="$(date -d "$(stat -c %y "$file")" +%Y)" ## Get the file's modification month month="$(date -d "$(stat -c %y "$file")" +%b)" ## Create the directories if they don't exist. The -p flag ## makes 'mkdir' create the parent directories as needed so ## you don't need to create $year explicitly. [[ ! -d "$BASE_DIR/$year/$month" ]] && mkdir -p "$BASE_DIR/$year/$month"; ## Move the file mv "$file" "$BASE_DIR/$year/$month" done
Author Archives: stz184
Hot to install GPaste on Ubuntu 23.10
GPaste is an open-source clipboard management tool for Linux-based operating systems. Clipboard managers like GPaste allow users to manage and access a history of items they have copied to the clipboard, enabling them to easily paste previously copied content.
Sadly, there are binary packages available but you can compile it and install it manually.
Docker fails to fetch http://deb.debian.org/debian/dists/buster/InRelease
I found a network issue when trying to build my docker image: the command `apt update` fails with the following error:
W: Failed to fetch http://deb.debian.org/debian/dists/buster/InRelease
W: Failed to fetch http://deb.debian.org/debian/dists/buster-updates/InRelease
W: Failed to fetch http://security.debian.org/dists/buster/updates/InRelease
W: Failed to fetch http://deb.debian.org/debian/dists/buster/Release.gpg Temporary failure resolving ‘deb.debian.org’
W: Failed to fetch http://security.debian.org/dists/buster/updates/Release.gpg Temporary failure resolving ‘security.debian.org’
W: Failed to fetch http://deb.debian.org/debian/dists/buster-updates/Release.gpg Temporary failure resolving ‘deb.debian.org’
W: Some index files failed to download. They have been ignored, or old ones used instead.
This happens because your ISP DNS servers are not reachable from this network. The easiest workaround is to directly instruct Docker to rely on some public DNS servers proven to be stable and reliable (Google, Cloudflare).
Add them to a new configuration file called daemon.json
:
$ sudo pico /etc/docker/daemon.json
Insert the following:
{ "dns": ["1.1.1.1", "8.8.8.8", "8.8.4.4"] }
Then restart the service:
$ sudo service docker restart
Composer 2.3.0 breaks Symfony 3.4 app
If you experience the following error while installing the required packages for Symfony 3.4 packages, it is highly possible to have Composer 2.3.0 or newer installed:
symfony-scripts: Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
In Process.php line 143:
[TypeError]
Argument 1 passed to Symfony\Component\Process\Process::__construct() must
be of the type array, string given, called in /var/www/example.com/releases/20220330124916/vendor/sensio/distribution-bundle/Composer/Scrip
tHandler.php on line 310
The root cause of the issue is that Composer 2.3.x requires symfony/process^5
itself, but your project also has a dependency on symfony/process^4 somewhere, composer loads it first and when your project tries to use it, expecting v4 but using v5 instead it triggers the error
The quick and dirty solution is to downgrade Composer to 2.2.x so you are able to update your dependencies normally. To do that just run the following command
sudo composer self-update 2.2.9
Enjoy!
How to install autojump for Fish on Ubuntu
Autojump is a tool that can be used to jump around in the shell to frequently used directories by typing just a part of their name. It is typically aliased to j
. Autojump is available as a package in the Ubuntu repositories, but it needs manual intervention to be available in the fish shell.
1. Install autojump
sudo apt install autojump
2. Source the autojump.fish file in your fish configuration, by opening the file ~/.config/fish/config.fish
in an editor and adding these lines:
begin set --local AUTOJUMP_PATH /usr/share/autojump/autojump.fish if test -e $AUTOJUMP_PATH source $AUTOJUMP_PATH end end
3. Add j
shortcut command to fish creating a new file ~/.config/fish/functions/j.fish
with the following content:
function j set new_path (autojump $argv) if test -d "$new_path" echo $new_path cd "$new_path" else echo "autojump: directory '$argv' not found" echo "Try \`autojump --help\` for more information." false end end
Usage examples:
– j Down
– changes to my Downloads folder
– j work
– changes to my workspace folder
Enjoy!
Test Assignments
In recent years I have applied to numerous development jobs driven by my will to develop my career and find better pay. It’s common nowadays for companies to give test assignments supposed to verify the candidate’s coding skills, as well as his/her ability to organize work. There is no test assignment I have failed to fulfil, but there are many times when I failed to explain it properly in a technical interview discussing my solution. I am a self-taught developer and have no formal technical education (excluding the high school where I specialized in microprocessors – a more hardware-oriented field of study). So, when the technical interviewer says “Nice solution, but can you describe the cyclomatic complexity of it?” I am done.
Honestly, I am aware of my skills, strengths and weaknesses. I haven’t gained experience with a lot of modern and trendy technologies that well-paying companies require. What kept me in the game for 15 years is mostly my ability to troubleshoot complex problems and provide simple solutions to them. Additionally, I have excellent communication skills, and I can explain complex technical issues to non-technical stakeholders in a way that is easy to understand. This has proven valuable in many situations, where I have been able to build strong relationships with clients and stakeholders and ensure that everyone is on the same page. That’s why my recent employers trust me to mentor and onboard others, not because of my top-notch up-to-date experience with all the fancy new technologies that popped up recently.
Anyway. This post is a short review of what I’ve done as coding challenges in recent years. I hope it’s a pretty comprehensive code base proving my ability to solve problems with code. Honestly, if I have to write yet another code assignment, I feel better working on something else and fuck development.
How to test for uniqueness of value in Yup.array?
Imagine you have a form with a dynamic amount of inputs – in my case, it is an array of objects holding “name” and “surname” properties and you need to validate that all objects in this array have unique name
property.
Example schema:
const users = yup.array().of(yup.object().shape({ name: yup.string(), surname: yup.string(), }))
How can you test for uniqueness? There is no built-in validator, but you can create a custom one easily extending Yup.test. This validator allows you to add a test function to the validation chain. Tests are run after any object is cast. In order to allow asynchronous custom validations all (or no) tests are run asynchronously. A consequence of this is that test execution order cannot be guaranteed.
All tests must provide a name
, an error message
and a validation function that must return true
when the current value
is valid and false
or a ValidationError
otherwise. To make a test async return a promise that resolves true
or false
or a ValidationError
.
For the message
argument you can provide a string which will interpolate certain values if specified using the ${param}
syntax. By default, all test messages are passed a path
value which is valuable in nested schemas.
The test
function is called with the current value
.
const users = yup.array().of(yup.object().shape({ name: yup.string(), surname: yup.string(), })).test( 'unique', t('step2.validation_errors.duplicate').toString(), (value) => { if (!value) return true; const unique = value.filter((v: any, i: number, a: any) => a.findIndex((t: any) => (t.name === v.name && t.surname === v.surname)) === i); return unique.length === value.length; } )
Because the uniqueness check is not related to a particular element of the users object but is a general validation constraint for the whole object, the error message will be populated as “errors.people” property of Formik. That’s why I am checking if the erros.users is a string – if it is a string, I should display a general error above all the user’s fields, but if it is an array of errors – it contains errors for a particular index of the users array.
{typeof errors.users === 'string' && <ErrorMessage name="users" component="div" className="elementor-field-group mt-2 text-sm text-red-600 dark:text-red-500" />}
GSConnect doesn’t mount my phone on Manjaro Gnome, this is the solution
Hi there! I am using the Gnome shell extension GSConnect on Manjaro Gnome to share files from my phone to my laptop. There is an option called “Mount” that initially didn’t work on Manjaro but I found a solution and it now works like a charm!
All you need to do is to edit the file /etc/ssh/ssh_config
sudo vim /etc/ssh/ssh_config
and add to the end of the file the following:
Host 192.168.*.* HostKeyAlgorithms +ssh-rsa
Install docker and docker-compose on Linux Mint 20.3
Issue the following commands in the terminal, one by one and you are ready to go! It’s simple as that 🙂
#docker setup echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" | sudo tee /etc/apt/sources.list.d/docker.list curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io pigz #execution permission sudo usermod -aG docker $USER #docker compose sudo curl -L "https://github.com/docker/compose/releases/download/2.2.3/docker-compose-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose</pre>
Fingerprint reader 0a5c:5843 Broadcom Corp. 58200 Ubuntu / Linux mint driver install
First, we need to checkout the following repo containing the driver:
git clone https://git.launchpad.net/~oem-solutions-engineers/libfprint-2-tod1-broadcom/+git/libfprint-2-tod1-broadcom/
Then go into the cloned folder and issue the following commands:
sudo sh install.sh python3 debian/update-fw.py
You may need to restart the laptop in order the changes to be applied.
Finally, enable fingerprint login using the following command:
sudo pam-auth-update