Dealing with Binary Files in the Console: A Quick Fix for Common Issues – using reset command

Viewing binary files through the console can occasionally lead to unexpected and disruptive issues. You might have experienced situations where the console seems to ‘break’— displaying strange characters, replacing normal text with incomprehensible hieroglyphs, and even triggering unexpected sound alerts or bizarre color blends. These anomalies can render the console practically unusable, disrupting your workflow.

Fortunately, there’s a simple solution to this problem. Whenever you encounter these disruptions, just enter the command:

reset

This command effectively resets your console, clearing any irregularities and restoring its normal functionality. It’s a quick and efficient way to tackle the chaos caused by binary file interactions and ensures you can continue your work without major interruptions.

Remember, while the reset command is powerful, it’s always good practice to understand the nature of the files you’re dealing with. Use appropriate tools and commands for viewing or editing binary files to minimize these occurrences.

Exploring Array Syntax in Shell Scripting: A C-Like Approach

Shell scripting provides a versatile way to automate tasks in Unix-like systems. For programmers familiar with C or languages with similar syntax, the following pattern can be particularly intuitive:

#!/usr/bin/env sh

arr=('foo' 'bar' 'baz')

for ((i=0; i < ${#arr[@]}; i++)); do
    echo "arr[${i}]: ${arr[i]}"
done

In this script, we define an array named arr with three string elements: ‘foo’, ‘bar’, and ‘baz’. We then iterate over the array using a for loop that closely resembles the syntax in C.

The loop utilizes a C-style for-loop syntax to iterate over the array indices. With i as the index, the loop runs as long as i is less than the length of the array, which we obtain with ${#arr[@]}. Within the loop, each element of the array is accessed via ${arr[i]} and printed out alongside its index.

This syntax provides a familiar structure for those accustomed to C-like languages, offering a seamless transition to writing shell scripts.

Linux find search for files changed in date range

Introduction

In this quick guide, we’ll explore some useful bash commands to find files modified within a specific time frame. This is especially useful for system administrators and developers.

Finding Files Modified Today

To find all files in a directory that were modified today, you can use the following command:

find /dir -type f -mtime -1

This command searches for files (`-type f`) in the `/dir` directory that have been modified in the last 1 day (`-mtime -1`).

Finding Files Modified Exactly N Days Ago

If you need to find files changed exactly N days ago, use:

find /dir2 -type f -mtime n

Replace `n` with the number of days ago you are interested in.

Deleting Files Modified More Than M Days Ago

To find and delete files modified more than M days ago, proceed with caution and use:

find /dir3 -type f -mtime +m -exec rm -fv {} \;

Warning: This command will delete files. Use it carefully.

Conclusion

These are just a few basic but powerful ways you can manage your file system more effectively using bash commands.

Some useful composer options we are use for production Docker setup in Laravel apps

Composer logo

As a part of our Docker production setup of Laravel web application we are using the following composer install with some options described below:

  • –optimize-autoloader or -o: This flag tells Composer to optimize the autoloader for better performance. Autoloading is a mechanism in PHP that automatically loads classes when they are needed. Optimizing the autoloader can make your application load faster by reducing the number of file operations required to load classes.
  • –no-dev: This flag tells Composer not to install the development dependencies specified in the `composer.json` file. Development dependencies typically include things like testing libraries, code analysis tools, and other packages that are not needed in a production environment.
  • –prefer-dist: This flag tells Composer to prefer installing package distributions (i.e., ZIP or TAR archives) over the source code from version control repositories. Using distributions can be faster and more efficient because it avoids the need to compile or build the packages from source.

So, when you run

composer install --optimize-autoloader --no-dev

, you are installing the project’s production dependencies while optimizing the autoloading process for better performance and excluding any development-specific dependencies. This is commonly used when preparing a PHP project for deployment to a production server.

We hope this information will help you to prepare your Laravel application for production environment.

The full list of all possible options you could check at composer documentation page.

How to install TeamViewer on Ubuntu Linux 22.04

To install TeamViewer on Ubuntu Linux 22.04 use the follwoing commands:

sudo su

This command will make you Linux administrator super user root. It is needed to install or update any system software on your system.

The first thing we need is to install SSL certificates using commands below:

cd /tmp
wget https://download.teamviewer.com/download/linux/signature/TeamViewer2017.asc
sudo apt-key add TeamViewer2017.asc
sudo sh -c 'echo "deb http://linux.teamviewer.com/deb stable main" >> /etc/apt/sources.list.d/teamviewer.list'

The second part of commands updates system software and install TeamViewer program itself:

sudo apt update
sudo apt upgrade

sudo apt install teamviewer

Check out the video instructions on how to install the TeamViewer on Ubuntu Linux.

PHP – swap two variable values

For example, you have a function which takes two parameters int|float $min and int|float $max parameters and you need to swap variable values vise versa, in case if $max value is less then $min value.

You can do it using the following code below:

if ($min > $max) {
    list($min, $max) = [$max, $min];
}

Git – copy few branches from old repository to a new one

Sometimes, then you need to transfer few Git branches from existing repository to a new one you could run the following commands:

git clone --no-checkout [New Git Repository URL] new-repo-folder

This command will create a new folder new-repo-folder with a .git folder inside, but without any files from branches.

Change to the repository folder:

cd new-repo-folder

Adding the necessary branches: Now you need to do “remote tracking” for the desired branches. You could do it using commands below:

git remote add old-origin [Original Git Repository URL]

git fetch old-origin dev:dev
git fetch old-origin stage:stage
git fetch old-origin prod:prod

This will add the dev, stage, and prod branches from the original repository to your local copy.

Check: Verify that you now have only these three branches.

git branch -l

In case if you have also have copied Git tags use the command below:

git tag -l

to list all Git tags.

To remove all local tags use the command below:

git tag -l | xargs git tag -d

To push all branches to remote use the following command:

git push origin --all

Join the PHP Dinos Telegram Channel!

Are you a PHP enthusiast, developer, or just curious about the world of PHP? Look no further! We’re thrilled to introduce the brand-new Telegram channel, PHP Dinos.

What to expect:

  • PHP tips and tricks.
  • PHP news and updates.
  • Engaging in discussions on PHP development.
  • Valuable resources for PHP beginners and experts alike.
  • Community support and collaboration opportunities.

Whether you’re a seasoned PHP developer or just starting your PHP journey, PHP Dinos is your go-to destination for all things PHP-related. Let’s come together to explore, learn, and share our passion for PHP programming.
Join us now at https://t.me/phpdinos and be part of a vibrant community of PHP enthusiasts. Don’t miss out on the fun – see you there!

#PHP #WebDevelopment #Programming #Community #PHPDinos