Category: Computer Programming

  • How to reduce eye strain when working with a computer

    How to reduce eye strain when working with a computer

    These simple steps help you reduce eye strain when working with a computer in an office or at home.

    Light should be from the side left or right.

    Natural light is ideal, wost is mixed natural + artificial.
    Once in a while get up walk around and look out the window somewhere far.

    Get your eyesight checked and wear glasses if you need.

    Drink water from a small reusable container. Make frequent trips to the water cooler.

    Most important, in Windows 11 enable reading mode / night light. It reduces the blue light from the PC monitor. Makes pages a bit warmer in color – yellow but it makes a big difference.

    Set any programs you can to Dark theme.

    Set Google search theme to dark theme.

  • Zip folders to separate files

    Zip folders to separate files

    How to zip folders to separate files.

    If you have a few folders and you want to create one archive for each folder.

    Video how to steps.

    Zip folders to separate files

    Setup environment

    How to create individually separate archives there is a way you can zip all folders to separate archives using the 7-Zip command line to you can install 7-Zip from the 7-zip website download page.

    Once you have 7-Zip installed, you can run this command below in a batch file you can create a .bat file.

    Auto zip folders script

    The batch file contents are just text commands to run as part of the .bat script or batch file.

    You can name the .bat file anything you like.

    How to run it

    To run the .bat file in the current directory where you have your folders ready.

    Copy the .bat file next to your directories and double click to start to zip all folders into separate archives – folders in the current directory where the .bat file is saved.

    Zip folders into separate archive files script

    This is the script, please do NOT run this .bat script until you read ALL of this post.

    You try this at your own risk, no liability accepted, no support.

    for /d %%n in (*) do "%ProgramFiles%\7-Zip\7z.exe" a "%%n.zip" "%%n\"

    The auto zip script explained:

    for /d %%n in (*) do

    It goes thru all directories in the current folder and does the next action.

    “%ProgramFiles%\7-Zip\7z.exe” a “%%n.zip” “%%n\”

    Calls 7-Zip to the default install location (you might have to change this) and passes parameters to 7-Zip in CLI mode – command line interface. Add / archive zip file name using target folder.

    Then goes to the next folder and runs the same steps until there is are no more folders to archive left.

    The script does not delete anything, it olny creates zip files from subfolders.

    How I use it

    The way I have it set up is the .bat script is in the folder where I keep the folders I want to be zipped.

    It’s looking at all the current folders in the current folder where the script is saved and it will go through each folder creating a zip file archive for all the folders and the files inside the folders.

    Most importantly to be sure it’s ok you’ll also want the files that are contained within this folders and afterwards, check the folders count.

    I check the count of the zip files first you should also check try to extract a few of the zip files make sure that the zip file actually contains the correct files you want.

    Once I make sure that all the files and folders were archived in the zip files.

    I delete the archived folders and I move the zip files to the archive location.

    This is the way I do it and hopefully this is helpful.

    It’s a very simple Windows script using built-in functions of Windows.

    Verify

    There is nothing special about this. The most dangerous thing would be that it is not archiving all the files you want to archive so before you delete anything make sure that you have all your files from inside the zip folder to inside the zip file. First few tries, extract all zipped files and compare file/folder count with the original source folders.

    Right click – properties on both and see file count and size. File count and size should be identical between source and extracted folder.

    I really only checked the count to count of folders I checked if there are 10 photos that should be 10 files and the size is not too small for them I did two folders and I archive the files without too much trouble but the first time you tried to do this make sure you extract the zip files all of them actually extract all the files.

    Make sure that all the parts are from folders you have so that there’s not one missing the first one or the last one is missing so the count should be the same of zip files and folders in the content should be the same after extracting them.

    Hopefully this is helping you. Thanks for reading!

    How to create zip files

    How to Create a Zip File in Windows 10 or 11

    Extract multiple archives in separate folders

    How to extract multiple archives in separate folders in the same way as zipping.

    All you have to do is make another .bat file call it anything you like extract_all.bat seems ok.

    contents of the extract zip archives (untested) bat:

    for /f %%n in (*.zip) 
    do "%ProgramFiles%\7-Zip\7z.exe" x "%%n.zip" -o "%%n\"

    this time we look for each file in the current directory /f that ends with .zip – you can change it to ” for all files.

    Then run 7zip and pass the x argument to extract preserving full directory path and -o to set the output directory to a sub-folder with the same name as the zip archive file.

    It’s easy to adjust both zip all folders and extract all archives scripts to fit your needs.

    Enjoy your scripts!

  • Auto zip folders in separate archive files 7zip bat script

    Auto zip folders in separate archive files 7zip bat script

    Automatically zip folders in separate archive files 7zip bat script batch processing separate folders to archive in separate zip files or 7zip files.

    How to use

    7zip auto archive batch script

    Zip folders in separate archive files with 7-Zip and a batch file script in Windows 11.

    This productivity life hack will speed-up your work when you need to archive multiple folders.

    The batch script is with the extension .bat and it will do what you tell it to.

    The Bat script

    File name, you can name it anything .cmd I named it _7zipall.cmd

    Batch file contents, file should have the .cmd extension to be executable.

    Whole _7zipall.cmd script

    You try this at your own risk, no liability accepted, no support.

    for /d %%n in (*) do "%ProgramFiles%\7-Zip\7z.exe" a "%%n.zip" "%%n\"

    The auto zip script explained:

    For each sub directory loop

    for /d %%n in (*)

    goes thru each sub directory where the script is saved in / executed from. Then puts the directory details in a variable / parameter to be used in the next step.

    Do run CLI program

    do "%ProgramFiles%\7-Zip\7z.exe"

    Run the 7z 7zip executable in the script – you should check your path, you might have to change this for it to work if you installed 7zip in a different directory.

    7zip archive directory

     a "%%n.zip" "%%n\"

    When calling the 7zip executable you pass the parameters telling it to add to archive (a) in a zip file named same as the sub directory and add the current folder in the loop to the zip file. We use the %%n variable that was set earlier.

    Once 7zip finishes the current zip file, the script continues to the next directory and all steps are repeated until the last sub directory is zipped.

    This script does not delete the original folders used for the zip files, you can delete those if you want. This is for safety, best to to a compare at the end if at least the count of folders and zip files is equal.

    The script shown in the video will look at all directories in the current folder (where the script is saved) and
    For each sub-directory it will create a new .zip file and add all the files contained in that directory to it’s zip file, then it moves to the next folder until it goes thru all the folders it found.

    Archive files from sub-folders without creating the sub directory in the archive file

    Updated 2024-03-18: Added the option to add to archive without creating a folder inside the zip archive file but it will create any sub folders if there are any under that.

    Like this it skips the parent folder creation and puts the folder contents directly into the zip file.

    If you have multiple directories and you want to archive all sub-folders into separate archive files but without creating a directory in the archive file, you can modify the path of the files to be archived.

    Normally I would say better have the folder so that if you extract it, it goes back to the original folder structure. This is how I use it but you can change the script as below.

    If this is what you want “.\%%n\*” instead of “%%n\” like below complete script:

    for /d %%n in (*) do "%ProgramFiles%\7-Zip\7z.exe" a "%%n.zip" ".\%%n\*"

  • Why I deleted all my GitHub repos

    Why I deleted all my GitHub repos

    Why I deleted all my GitHub repos and why you might want to do that too.

    GitHub is a popular website to share Git repositories or repos as they’re usually called.

    When you create a Git repository on GitHub, you can share it with the public and be able to work together on the same project with various people.

    All this sounds great and it is but there are some good alternatives out there. Even open source ones that you can self-host if you prefer it like that.

    The Problem with GitHub

    GitHub is not open source and was aqquired by Microsoft.

    This wouldn’t matter for me much but there is something else about GitHub and public repos in general.

    I had to setup Github Desktop because of enhanced security. Had to use keys and extra security for verified commits. Perfect did that.

    Also in the settings I saw a fake email my.name.@ github.com or something similar actually was: dragosion@users.noreply.github.com.

    There I had the option to choose my real github email so I did that… changed from the strange email to my real one.

    Later I started getting and still getting more and more nigerian letter type scam emails or various types of scam emails in general and I wondered why now.

    What changed?

    Then I remember, GitHub

    So it goes like this…

    If you put your real email in the commits, everyone can see them in public repos. The whole point of Github as a non-pro account is to have public repos.

    Now everyone can see you email in the commit history.

    You don’t believe me?

    This this go to your repository on GitHub, example https://github.com/dragosion/GitHubEmailLeak_CommitHistory_Test

    Click the commit history button https://github.com/dragosion/GitHubEmailLeak_CommitHistory_Test/commits/main

    Select any of your commits https://github.com/dragosion/GitHubEmailLeak_CommitHistory_Test/commit/40de73094fd3d11868ce3803c3460243f452cfb4

    Now in this url at the end add .patch: https://github.com/dragosion/GitHubEmailLeak_CommitHistory_Test/commit/40de73094fd3d11868ce3803c3460243f452cfb4.patch

    You can see now the commit details and email related to this commit. Useful feature if you are looking to patch a bug but also useful for a spam-bot to harvest email addresses and this is plain text – no anti spam features as far as I see but they might have rate limiting.

    From 40de73094fd3d11868ce3803c3460243f452cfb4 Mon Sep 17 00:00:00 2001
    From: Dragos Ion <dragosion@users.noreply.github.com>
    Date: Thu, 29 Sep 2021 22:49:42 +0300
    Subject: [PATCH] Update README.md
    
    ---
     README.md | 1 +
     1 file changed, 1 insertion(+)
    
    diff --git a/README.md b/README.md
    index 8f1c617..8559c60 100644
    --- a/README.md
    +++ b/README.md
    @@ -1,2 +1,3 @@
     # GitHubEmailLeak_CommitHistory_Test
     GitHubEmailLeak_CommitHistory_Test what is says above.
    +test edit.
    
    

    GitHub now has the option to block commits from clients that would leak your real email address but the damage is already done and what they should offer is a way to remove the real email from past commits not future ones like it does now.

    Even if you do a clean local git repo and do a git push –force you might have some unexpected results and mess-up the whole repo.

    The only way to be sure is to remove the email from your Git settings locally, delete the whole remote repo, then push the local new repo to remote github.

    Same on Github desktop.

    My Github repos didn’t matter much so I deleted them and didn’t re-create them but can do it in the future on Bitbucket or even GitHub.

    A good alternative to Github is:

    Freemium / Professional options:

    You can continue to use GitHub as I probably will but woult look at sourceforge too and be more careful with the commit email leaking to spam bots.

    This happened because of me, it was my fault. GitHub could have explained it to me better – Your REAL Email WILL be LEAKED to the PUBLIC and POSSIBLY WILL be Harvested BY SPAM BOTS in red, and a are you sure you want that button should do it for me but this is still my fault for using my real email on a Git repo.

    That’s all for now.

  • 412. Fizz Buzz Python 3 Solution

    412. Fizz Buzz Python 3 Solution

    412. Fizz Buzz Python 3 Solution for LeetCode and HackerRank problems

    Requirements

    Input: integer n

    Output: string array answer (1-indexed) where:

    • answer[i] == “FizzBuzz” when i is divisible by both 3 and 5.
    • answer[i] == “Fizz” when i is divisible by 3.
    • answer[i] == “Buzz” when i is divisible by 5.
    • answer[i] == i for no condition matched above.

    Examples

    n: 3
    result is: ['1', '2', 'Fizz']
    n: 5
    result is: ['1', '2', 'Fizz', '4', 'Buzz']
    n: 23
    result is: ['1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz', '16', '17', 'Fizz', '19', 'Buzz', 'Fizz', '22', '23']
    n: 15
    result is: ['1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz']

    Solution in Python 3

    Using If elif and modulus operator to determine if the number i is divisible by 3 and 5 then by 3 then by 5 only.

    When no condition matches, the actual value of i is stored in the string array and move to the next iteration.

    Test Solution

    import time
    start_time = time.time()
    def main():
        print("start")
        
    
        n = 15
        print ("n: " + str(n))
        
        sol = Solution()
        result = sol.fizzBuzz(n)
        print("result is: "+ str(result))
    
        print("end")
    
    class Solution:
        def fizzBuzz(self, n: int) -> list[str]:
            result = []
            for i in range(1, n+1):
                if i%3 == 0:
                    if i%5 == 0:
                        result.append("FizzBuzz")
                    else:
                        result.append("Fizz")
                elif i%5 == 0:
                    result.append("Buzz")
                else:
                    result.append(str(i))
            return result
    if __name__ == "__main__":
        main()
    print("--- %s ms ---" % int(((time.time() - start_time)*1000)))
    

    The If / Elif can be either this

    class Solution:
        def fizzBuzz(self, n: int) -> list[str]:
            result = []
            for i in range(1, n+1):
                if i%3 == 0:
                    if i%5 == 0:
                        result.append("FizzBuzz")
                    else:
                        result.append("Fizz")
                elif i%5 == 0:
                    result.append("Buzz")
                else:
                    result.append(str(i))
            return result

    Or like this

    class Solution:
        def fizzBuzz(self, n: int) -> list[str]:
            result = []
            for i in range(1, n+1):
                if i%3 == 0:
                    if i%5 == 0:
                        result.append("FizzBuzz")
                    else:
                        result.append("Fizz")
                elif i%5 == 0:
                    result.append("Buzz")
                else:
                    result.append(str(i))
            return result

    Or checking if divisible by 15, 3, 5 This also works.

    class Solution:
        def fizzBuzz(self, n: int) -> list[str]:
            result = []
            for i in range(1, n+1):
                if i%15 == 0:
                    result.append("FizzBuzz")
                elif i%3 == 0:
                    result.append("Fizz")
                elif i%5 == 0:
                    result.append("Buzz")
                else:
                    result.append(str(i))
            return result
    
  • Wrap text with tags in Notepad++

    Wrap text with tags in Notepad++

    Wrap text with tags in Notepad++ A macro can do that and it’s easier than you think. If you need to wrap the text with html tags or WordPress Gutenberg code blocks or paragraph block or a heading block.

    Start by selecting the text:

    • In Notepad++ menu Click Macro > Start Recording.
    • Ctrl+X – Cut the text as the first action.
    • Type the text that should go before the original text. for example <p>
    • Ctrl+V Paste the original text back at the cursor – goes after the <p> you just typed earlier.
    • Type the text that goes after. For example a closing tag </p>
    • In Notepad++ menu Click Macro > Stop Recording.
    • In the same menu click Save Current Recorded Macro. You can even assign a shortcut key combination to it.

    Now whenever you want to wrap text in custom tags you select the text and run the macro.

    I recorded macros to build WordPress Gutenberg blocks.

    Heading block:

    <!-- wp:heading -->
    <h2>Heading Text</h2>
    <!-- /wp:heading -->

    Paragraph block:

    <!-- wp:paragraph -->
    <p>Some text</p>
    <!-- /wp:paragraph -->

    Code block:

    <!-- wp:code -->
    <pre class="wp-block-code"><code>the codes...</code></pre>
    <!-- /wp:code -->

    You can do this trick with any text you might want to wrap around your original text. If can be anything, simple text, tags, brackets, unicorns, anything you want. This post was actually built with these shortcuts. I prefer it like this than the Visual editor Gutenberg for WordPress blocks.

  • Secret Lesser  known useful Linux commands

    Secret Lesser known useful Linux commands

    tree

    The tree command will list you directory, files and sub folders contents in an easy to see way. No need for repeated ls commands. This can be useful to get an overview of all subfolders of the target directory.

    tree /var/log/
    tree rex.red/
    rex.red/
    ├── folder-4
    ├── folder-5
    ├── folder-6
    │   ├── folder7
    │   │   ├── eeefolder_3333
    │   │   │   ├── nine
    │   │   │   │   └── testfile1
    │   │   │   └── testfile2
    │   │   ├── folder
    │   │   ├── folder_33
    │   │   │   └── nine
    │   │   ├── folder_3333
    │   │   │   └── nine
    │   │   └── folder_8
    │   │       └── nine
    │   └── testfile3
    ├── folder-one
    ├── folder-three
    └── folder-two
    
      -p            Print the protections for each file.
      -u            Displays file owner or UID number.
      -g            Displays file group owner or GID number.
      -s            Print the size in bytes of each file.
      -h            Print the size in a more human readable way.
    
    
    [dragos@localhost ~]$ tree -pughs rex.red/
    rex.red/
    ├── [drwxrwxr-x dragos   dragos       6]  folder-4
    ├── [drwxrwxr-x dragos   dragos       6]  folder-5
    ├── [drwxrwxr-x dragos   dragos      38]  folder-6
    │   ├── [drwxrwxr-x dragos   dragos      94]  folder7
    │   │   ├── [drwxrwxr-x dragos   dragos      35]  eeefolder_3333
    │   │   │   ├── [drwxrwxr-x dragos   dragos      23]  nine
    │   │   │   │   └── [-rw-rw-r-- dragos   dragos       0]  testfile1
    │   │   │   └── [-rw-rw-r-- dragos   dragos       0]  testfile2
    │   │   ├── [drwxrwxr-x dragos   dragos       6]  folder
    │   │   ├── [drwxrwxr-x dragos   dragos      18]  folder_33
    │   │   │   └── [drwxrwxr-x dragos   dragos       6]  nine
    │   │   ├── [drwxrwxr-x dragos   dragos      18]  folder_3333
    │   │   │   └── [drwxrwxr-x dragos   dragos       6]  nine
    │   │   └── [drwxrwxr-x dragos   dragos      18]  folder_8
    │   │       └── [drwxrwxr-x dragos   dragos       6]  nine
    │   └── [-rw-rw-r-- dragos   dragos       0]  testfile3
    ├── [drwxrwxr-x dragos   dragos       6]  folder-one
    ├── [drwxrwxr-x dragos   dragos       6]  folder-three
    └── [drwxrwxr-x dragos   dragos       6]  folder-two
    
    16 directories, 3 files
    [dragos@localhost ~]$
    

    pstree

    [dragos@localhost ~]$ pstree

    Tree but for precesses. Shows what processes originate from other processes.

    kill -15 SIGTERM

    Sends the SIGTERM signal to the process and allows it to exit gracefully. That process might hang so the next one is more drastic.

    sudo kill -15 PID
    [dragos@localhost ~]$ sudo kill -15 3778529
    [sudo] password for dragos:
    [dragos@localhost ~]$

    sudo kill -9 KILL

    Stop the process, end it now and don’t wait for anything.

    kill -9 PID

    [dragos@localhost ~]

    $ sudo kill -9 3778526
    

    ps -aux | grep log

    List processes piped into grep to find a hanging process. Extremely useful for finding what is happening with a process that is still running but takes much longer than expected. You can get some hints about what is wrong using this command combination.

    sudo !!

    yum update 
    sudo !!
    [dragos@localhost ~]$ yum update
    Error: This command has to be run with superuser privileges (under the root user on most systems).
    [dragos@localhost ~]$ sudo !!
    sudo yum update
    [sudo] password for dragos:
    Last metadata expiration check: 2:55:04 ago on Tue 31 Aug 2021 13:10:23 EEST.
    Dependencies resolved.
    Nothing to do.
    Complete!
    [dragos@localhost ~]$
    

    Get public ip

    curl ifconfig.io Public ip.

    [dragos@localhost ~]$ curl ifconfig.io
    111.222.333.444
    
  • Commands any Linux Sysadmin should learn first

    Commands any Linux Sysadmin should learn first

    Commands any Linux Sysadmin should learn first.

    These are the commands any Linux Sysadmin should learn first.

    These are some of the most useful commands for system administration and devops on Linux.

    They are command line tolls because most of the actions on system administration you would want to be automated and scheduled

    uptime

    Time passed since last restart and statistics about system load and users logged in since then.

    [dragos@localhost ~]$ uptime
     18:00:51 up 3 days, 20:59,  1 user,  load average: 0.01, 0.04, 0.00
    

    For a nicer look use the pretty option.

    uptime -p
    [dragos@localhost ~]$ uptime -p
    up 3 weeks, 3 days, 21 hours

    top

    Shows system statistics and resource allocation.

    CPU and RAM allocation overview list.

    top

    alias 

    alias command shortcut name = “the actual command”

    alias sayhello="echo ""Hello World!"""
    [dragos@localhost rex.red]$ alias sayhello="echo ""Hello World!"""
    [dragos@localhost rex.red]$ sayhello
    Hello World!
    [dragos@localhost rex.red]$
    This will last while you are still logged in. If you log out and logon again, the alias will be gone.

    Permanent alias

    Making the alias permanent for your user. You save it in your .bashrc file.

    vim ~/.bashrc

    Add the alias at the end of the file.

    # User specific aliases and functions
    #My Aliases
    alias sayhello="echo ""Hello World!"""

    Save the file – in vim Esc then :wq enter

    Make sure you use the file

    source ~/.bashrc

    Your alias is there even after a reboot.

    whereis

    Powerful command to locate files or directories on your drive.

    Most useful to find binaries of installed programs.

    whereis httpd

    free

    free -h

    RAM allocation and usage statistics.

    [dragos@localhost ~]$ free
                  total        used        free      shared  buff/cache   available
    Mem:        1859812      613712      453892       53532      792208     1036984
    Swap:       2158588      234220     1924368
    [dragos@localhost ~]$ free -h
                  total        used        free      shared  buff/cache   available
    Mem:          1.8Gi       599Mi       443Mi        52Mi       773Mi       1.0Gi
    Swap:         2.1Gi       228Mi       1.8Gi
    [dragos@localhost ~]$
    

    service

    service service-name action

    [dragos@localhost ~]$ service -h
    Usage: service < option > | --status-all | [ service_name [ command | --full-restart ] ]

    It’s useful to find problems with a daemon or service.

    It is also used to (start, stop, restart, try-restart, reload, force-reload, status) various services.

    service httpd status
    [dragos@localhost ~]$ service httpd status
    Redirecting to /bin/systemctl status httpd.service
    ● httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
      Drop-In: /usr/lib/systemd/system/httpd.service.d
               └─php-fpm.conf
       Active: inactive (dead)
         Docs: man:httpd.service(8)
    [dragos@localhost ~]$
    
    [dragos@localhost ~]$ sudo service httpd start
    [sudo] password for dragos:
    Redirecting to /bin/systemctl start httpd.service
    [dragos@localhost ~]$ sudo service httpd enable
    The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
    [dragos@localhost ~]$
    

    You can start a service but to enable it on startup use systemctl.

    systemctl

    sudo systemctl restart httpd
    sudo systemctl reload httpd
    sudo systemctl stop httpd
    sudo systemctl start httpd
    sudo systemctl enable httpd
    sudo systemctl status httpd
    [dragos@localhost ~]$ sudo service httpd start
    [sudo] password for dragos:
    Redirecting to /bin/systemctl start httpd.service
    [dragos@localhost ~]$ sudo service httpd enable
    The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
    [dragos@localhost ~]$ sudo systemctl restart httpd
    [dragos@localhost ~]$ sudo systemctl reload httpd
    [dragos@localhost ~]$ sudo systemctl stop httpd
    [dragos@localhost ~]$ sudo systemctl start httpd
    [dragos@localhost ~]$ sudo systemctl enable httpd
    Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
    [dragos@localhost ~]$ sudo systemctl status httpd
    ● httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
      Drop-In: /usr/lib/systemd/system/httpd.service.d
               └─php-fpm.conf
       Active: active (running) since Tue 2021-08-31 18:36:43 EEST; 11s ago
         Docs: man:httpd.service(8)
     Main PID: 3778525 (httpd)
       Status: "Running, listening on: port 80"
        Tasks: 213 (limit: 11255)
       Memory: 26.1M
       CGroup: /system.slice/httpd.service
               ├─3778525 /usr/sbin/httpd -DFOREGROUND
               ├─3778526 /usr/sbin/httpd -DFOREGROUND
               ├─3778527 /usr/sbin/httpd -DFOREGROUND
               ├─3778528 /usr/sbin/httpd -DFOREGROUND
               └─3778529 /usr/sbin/httpd -DFOREGROUND
    
    Aug 31 18:36:43 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
    Aug 31 18:36:43 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
    Aug 31 18:36:43 localhost.localdomain httpd[3778525]: Server configured, listening on: port 80
    lines 1-21/21 (END)
    

    dig

    Complete DNS query to find any record related to a domain, name server, root nameserver

    dig rex.red
    [dragos@localhost ~]$ dig rex.red
    
    ; <<>> DiG 9.11.26-RedHat-9.11.26-4.el8_4 <<>> rex.red
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29461
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
    
    ;; OPT PSEUDOSECTION:
    ; EDNS: version: 0, flags:; udp: 4000
    ;; QUESTION SECTION:
    ;rex.red.                       IN      A
    
    ;; ANSWER SECTION:
    rex.red.                299     IN      A       172.67.218.197
    rex.red.                299     IN      A       104.21.38.42
    
    ;; Query time: 347 msec
    ;; SERVER: 10.4.60.20#53(10.4.60.20)
    ;; WHEN: Tue Aug 31 10:51:06 EEST 2021
    ;; MSG SIZE  rcvd: 68
    

    The any parameter will give you all the DNS records of that domain. 

    It’s useful to get an overview of the setup of a domain.

    [dragos@localhost ~]$ dig rex.red any
    
    ; <<>> DiG 9.11.26-RedHat-9.11.26-4.el8_4 <<>> rex.red any
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28600
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 13
    
    ;; OPT PSEUDOSECTION:
    ; EDNS: version: 0, flags:; udp: 4000
    ;; QUESTION SECTION:
    ;rex.red.                       IN      ANY
    
    ;; ANSWER SECTION:
    rex.red.                243     IN      A       104.21.38.42
    rex.red.                243     IN      A       172.67.218.197
    rex.red.                3597    IN      NS      chan.ns.cloudflare.com.
    rex.red.                3597    IN      NS      alec.ns.cloudflare.com.
    rex.red.                3786    IN      HINFO   "RFC8482" ""
    
    ;; ADDITIONAL SECTION:
    chan.ns.cloudflare.com. 11396   IN      A       172.64.32.82
    chan.ns.cloudflare.com. 11396   IN      A       173.245.58.82
    chan.ns.cloudflare.com. 11396   IN      A       108.162.192.82
    chan.ns.cloudflare.com. 1707    IN      AAAA    2803:f800:50::6ca2:c052
    chan.ns.cloudflare.com. 1707    IN      AAAA    2a06:98c1:50::ac40:2052
    chan.ns.cloudflare.com. 1707    IN      AAAA    2606:4700:50::adf5:3a52
    alec.ns.cloudflare.com. 7750    IN      A       172.64.33.59
    alec.ns.cloudflare.com. 7750    IN      A       173.245.59.59
    alec.ns.cloudflare.com. 7750    IN      A       108.162.193.59
    alec.ns.cloudflare.com. 80123   IN      AAAA    2a06:98c1:50::ac40:213b
    alec.ns.cloudflare.com. 80123   IN      AAAA    2606:4700:58::adf5:3b3b
    alec.ns.cloudflare.com. 80123   IN      AAAA    2803:f800:50::6ca2:c13b
    
    ;; Query time: 3322 msec
    ;; SERVER: 10.4.60.20#53(10.4.60.20)
    ;; WHEN: Tue Aug 31 10:52:02 EEST 2021
    ;; MSG SIZE  rcvd: 408
    
    [dragos@localhost ~]$
    

    +nocomments option makes the response more compact by removing the comments of each section and giving you only the actual response.

    [dragos@localhost ~]$ dig rex.red any +nocomments
    
    ; <<>> DiG 9.11.26-RedHat-9.11.26-4.el8_4 <<>> rex.red any +nocomments
    ;; global options: +cmd
    ;rex.red.                       IN      ANY
    rex.red.                10      IN      A       172.67.218.197
    rex.red.                10      IN      A       104.21.38.42
    rex.red.                3364    IN      NS      chan.ns.cloudflare.com.
    rex.red.                3364    IN      NS      alec.ns.cloudflare.com.
    rex.red.                3553    IN      HINFO   "RFC8482" ""
    rex.red.                157     IN      TXT     "google-site-verification=C0S4gecD15hMlSjLUF0bGRNURsYoleGS-v_1zCJ6mr4"
    chan.ns.cloudflare.com. 11163   IN      A       173.245.58.82
    chan.ns.cloudflare.com. 11163   IN      A       108.162.192.82
    chan.ns.cloudflare.com. 11163   IN      A       172.64.32.82
    chan.ns.cloudflare.com. 1474    IN      AAAA    2a06:98c1:50::ac40:2052
    chan.ns.cloudflare.com. 1474    IN      AAAA    2606:4700:50::adf5:3a52
    chan.ns.cloudflare.com. 1474    IN      AAAA    2803:f800:50::6ca2:c052
    alec.ns.cloudflare.com. 7517    IN      A       173.245.59.59
    alec.ns.cloudflare.com. 7517    IN      A       108.162.193.59
    alec.ns.cloudflare.com. 7517    IN      A       172.64.33.59
    alec.ns.cloudflare.com. 79890   IN      AAAA    2606:4700:58::adf5:3b3b
    alec.ns.cloudflare.com. 79890   IN      AAAA    2803:f800:50::6ca2:c13b
    alec.ns.cloudflare.com. 79890   IN      AAAA    2a06:98c1:50::ac40:213b
    ;; Query time: 26 msec
    ;; SERVER: 10.4.60.20#53(10.4.60.20)
    ;; WHEN: Tue Aug 31 10:55:55 EEST 2021
    ;; MSG SIZE  rcvd: 489
    
    [dragos@localhost ~]$

    Looking ony at the TXT DNS records of the domain.

    [dragos@localhost ~]$ dig rex.red txt +nocomments
    
    ; <<>> DiG 9.11.26-RedHat-9.11.26-4.el8_4 <<>> rex.red txt +nocomments
    ;; global options: +cmd
    ;rex.red.                       IN      TXT
    rex.red.                26      IN      TXT     "google-site-verification=C0S4gecD15hMlSjLUF0bGRNURsYoleGS-v_1zCJ6mr4"
    ;; Query time: 0 msec
    ;; SERVER: 10.4.60.20#53(10.4.60.20)
    ;; WHEN: Tue Aug 31 10:58:06 EEST 2021
    ;; MSG SIZE  rcvd: 117
    
    [dragos@localhost ~]$
    

    The default is a which returns the IPv4 of the domain. 

    q-type   is one of (a,any,mx,ns,soa,hinfo,axfr,txt,…) [default:a]

    ifconfig

    List all interfaces

    ifconfig -a

    Enable the network card interface

    ifconfig eth0 down

    Disable the network card

    ifconfig eth0 up

    Configure the network interface

    ifconfig eth0 192.168.1.12
    ifconfig eth0 netmask 255.255.255.
    ifconfig eth0 broadcast 192.168.1.255

    netstat

    Shows active network connections 

    netstat

    Show all sockets 

    netstat -a

    Show statistics for all interfaces

    netstat -s

    Display interfaces

    netstat -i
    [dragos@localhost rex.red]$ netstat -h
    usage: netstat [-vWeenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}
           netstat [-vWnNcaeol] [<Socket> ...]
           netstat { [-vWeenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]
    
            -r, --route              display routing table
            -I, --interfaces=<Iface> display interface table for <Iface>
            -i, --interfaces         display interface table
            -g, --groups             display multicast group memberships
            -s, --statistics         display networking statistics (like SNMP)
            -M, --masquerade         display masqueraded connections
    
            -v, --verbose            be verbose
            -W, --wide               don't truncate IP addresses
            -n, --numeric            don't resolve names
            --numeric-hosts          don't resolve host names
            --numeric-ports          don't resolve port names
            --numeric-users          don't resolve user names
            -N, --symbolic           resolve hardware names
            -e, --extend             display other/more information
            -p, --programs           display PID/Program name for sockets
            -o, --timers             display timers
            -c, --continuous         continuous listing
    
            -l, --listening          display listening server sockets
            -a, --all                display all sockets (default: connected)
            -F, --fib                display Forwarding Information Base (default)
            -C, --cache              display routing cache instead of FIB
            -Z, --context            display SELinux security context for sockets
    
    

    vim

    Command line text editors. Especially useful for editing configuration files in emergency situations.

    vi file
    vim  file
    nano file
  • How to zip and unzip files and folders in Linux

    How to zip and unzip files and folders in Linux

    How to zip and unzip files and folders in Linux

    Install Zip Unzip

    Install on RHEL, Centos, Fedora, Rocky Linux, etc.

    sudo yum install zip unzip

    Install on Debian, Ubuntu, etc.

    sudo apt-get install zip unzip

    Using zip and unzip to compress and extract files and folders.

    Current directory contents, files and one sub folder.

    ls -lh /home/dragos 
    total 8.0K
    drwxrwxr-x 2 dragos dragos 23  testdir
    -rw-rw-r-- 1 dragos dragos 37  testfile
    -rw-rw-r-- 1 dragos dragos 71  testfile2
    [dragos@localhost ~]$ ls -lh /home/dragos/testdir/
    total 4.0K
    -rw-rw-r-- 1 dragos dragos 35  innerfile
    

    Zip files and directories recursively

    This creates the zip file, the .zip extension is optional you can name it anything you like but .zip makes it more clear what it is later. 

    The * wildcard character tells zip everything in that directory. 

    [dragos@localhost ~]$ zip -r diyrednumberone.zip /home/dragos/*
      adding: home/dragos/testdir/ (stored 0%)
      adding: home/dragos/testdir/innerfile (deflated 80%)
      adding: home/dragos/testfile (deflated 57%)
      adding: home/dragos/testfile2 (deflated 68%)
    [dragos@localhost ~]$
    

    Zip files only

    Zip files only in first level directory – the one you specify or the current directory.

    zip archive-name.zip /path-to-files/

    Zipping test files

    [dragos@localhost ~]$ ls -lh /home/dragos
    total 12K
    -rw-rw-r-- 1 dragos dragos 760  diyrednumberone.zip
    drwxrwxr-x 2 dragos dragos  23  testdir
    -rw-rw-r-- 1 dragos dragos  37  testfile
    -rw-rw-r-- 1 dragos dragos  71  testfile2
    
    Moving the previous zip file to avoid confusion
    
    [dragos@localhost ~]$ mv diyrednumberone.zip testdir/
    
    
    Files are ready for zip
    
    [dragos@localhost ~]$ ls -lh /home/dragos
    total 8.0K
    drwxrwxr-x 2 dragos dragos 50  testdir
    -rw-rw-r-- 1 dragos dragos 37  testfile
    -rw-rw-r-- 1 dragos dragos 71  testfile2
    
    
    Compress the files and add them to a new zip file.
    
    [dragos@localhost ~]$ zip diyrednumberone_files.zip /home/dragos/*
      adding: home/dragos/testdir/ (stored 0%)
      adding: home/dragos/testfile (deflated 57%)
      adding: home/dragos/testfile2 (deflated 68%)
    [dragos@localhost ~]$
    
    
    Zip file is created
    
    [dragos@localhost ~]$ ls -lh /home/dragos 
    total 12K
    -rw-rw-r-- 1 dragos dragos 567  diyrednumberone_files.zip
    drwxrwxr-x 2 dragos dragos  50  testdir
    -rw-rw-r-- 1 dragos dragos  37  testfile
    -rw-rw-r-- 1 dragos dragos  71  testfile2
    

    Encrypted zip

    You can encrypt the zip file so that nobody can read the file contents without a password.

    zip -e diyrednumberone_files_enc.zip /home/dragos/*

    The -e parameter specifies the zip is to be encrypted and you will have to enter the password twice after pressing enter.

    [dragos@localhost ~]$ zip -e diyrednumberone_files_enc.zip /home/dragos/*
    Enter password:
    Verify password:
      adding: home/dragos/diyrednumberone_files.zip (stored 0%)
      adding: home/dragos/testdir/ (stored 0%)
      adding: home/dragos/testfile (deflated 57%)
      adding: home/dragos/testfile2 (deflated 68%)
    
    
    Zip command options
    
    [dragos@localhost ~]$ zip -h
    Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
    Zip 3.0 (July 5th 2008). Usage:
    zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
      The default action is to add or replace zipfile entries from list, which
      can include the special name - to compress standard input.
      If zipfile and list are omitted, zip compresses stdin to stdout.
      -f   freshen: only changed files  -u   update: only changed or new files
      -d   delete entries in zipfile    -m   move into zipfile (delete OS files)
      -r   recurse into directories     -j   junk (don't record) directory names
      -0   store only                   -l   convert LF to CR LF (-ll CR LF to LF)
      -1   compress faster              -9   compress better
      -q   quiet operation              -v   verbose operation/print version info
      -c   add one-line comments        -z   add zipfile comment
      -@   read names from stdin        -o   make zipfile as old as latest entry
      -x   exclude the following names  -i   include only the following names
      -F   fix zipfile (-FF try harder) -D   do not add directory entries
      -A   adjust self-extracting exe   -J   junk zipfile prefix (unzipsfx)
      -T   test zipfile integrity       -X   eXclude eXtra file attributes
      -y   store symbolic links as the link instead of the referenced file
      -e   encrypt                      -n   don't compress these suffixes
      -h2  show more help
    
    

    Unzip

    Extract zip to current directory

    unzip zipfile.zip 

    Extract to a specific directory -d sets the destination directory where the files will be extracted.

    unzip zipfile.zip -d /directory whereto extract/

    #
    [dragos@localhost ~]$ mkdir extracted/diyrednumberone
    [dragos@localhost ~]$ mkdir extracted/diyrednumberone_files
    [dragos@localhost ~]$ mkdir extracted/diyrednumberone_files_enc
    [dragos@localhost ~]$ ls extracted/
    diyrednumberone  diyrednumberone_files  diyrednumberone_files_enc
    [dragos@localhost ~]$ unzip testdir/diyrednumberone.zip -d extracted/diyrednumberone
    Archive:  testdir/diyrednumberone.zip
       creating: extracted/diyrednumberone/home/dragos/testdir/
      inflating: extracted/diyrednumberone/home/dragos/testdir/innerfile
      inflating: extracted/diyrednumberone/home/dragos/testfile
      inflating: extracted/diyrednumberone/home/dragos/testfile2
    [dragos@localhost ~]$ unzip diyrednumberone_files.zip -d extracted/diyrednumberone_files
    Archive:  diyrednumberone_files.zip
       creating: extracted/diyrednumberone_files/home/dragos/testdir/
      inflating: extracted/diyrednumberone_files/home/dragos/testfile
      inflating: extracted/diyrednumberone_files/home/dragos/testfile2
    [dragos@localhost ~]$ unzip diyrednumberone_files_enc.zip -d extracted/diyrednumberone_files_enc/
    Archive:  diyrednumberone_files_enc.zip
    [diyrednumberone_files_enc.zip] home/dragos/diyrednumberone_files.zip password:
     extracting: extracted/diyrednumberone_files_enc/home/dragos/diyrednumberone_files.zip
       creating: extracted/diyrednumberone_files_enc/home/dragos/testdir/
      inflating: extracted/diyrednumberone_files_enc/home/dragos/testfile
      inflating: extracted/diyrednumberone_files_enc/home/dragos/testfile2
    
    [dragos@localhost ~]$ ls -h extracted/diyrednumberone
    home
    [dragos@localhost ~]$ ls extracted/diyrednumberone/home/dragos/
    testdir  testfile  testfile2
    [dragos@localhost ~]$ ls extracted/diyrednumberone_files/home/dragos/
    testdir  testfile  testfile2
    [dragos@localhost ~]$ ls extracted/diyrednumberone/home/dragos/testdir/
    innerfile
    [dragos@localhost ~]$ ls extracted/diyrednumberone_files/home/dragos/testdir/
    [dragos@localhost ~]$ ls extracted/diyrednumberone_files_enc/home/dragos/
    diyrednumberone_files.zip  testdir  testfile  testfile2
    [dragos@localhost ~]$
    
    
    Unzip command options
    
    [dragos@localhost ~]$ unzip -h
    UnZip 6.00 of 20 April 2009, by Info-ZIP.  Maintained by C. Spieler.  Send
    bug reports using http://www.info-zip.org/zip-bug.html; see README for details.
    
    Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
      Default action is to extract files in list, except those in xlist, to exdir;
      file[.zip] may be a wildcard.  -Z => ZipInfo mode ("unzip -Z" for usage).
    
      -p  extract files to pipe, no messages     -l  list files (short format)
      -f  freshen existing files, create none    -t  test compressed archive data
      -u  update files, create if necessary      -z  display archive comment only
      -v  list verbosely/show version info       -T  timestamp archive to latest
      -x  exclude files that follow (in xlist)   -d  extract files into exdir
    modifiers:
      -n  never overwrite existing files         -q  quiet mode (-qq => quieter)
      -o  overwrite files WITHOUT prompting      -a  auto-convert any text files
      -j  junk paths (do not make directories)   -aa treat ALL files as text
      -U  use escapes for all non-ASCII Unicode  -UU ignore any Unicode fields
      -C  match filenames case-insensitively     -L  make (some) names lowercase
      -X  restore UID/GID info                   -V  retain VMS version numbers
      -K  keep setuid/setgid/tacky permissions   -M  pipe through "more" pager
      -O CHARSET  specify a character encoding for DOS, Windows and OS/2 archives
      -I CHARSET  specify a character encoding for UNIX and other archives
    
    See "unzip -hh" or unzip.txt for more help.  Examples:
      unzip data1 -x joe   => extract all files except joe from zipfile data1.zip
      unzip -p foo | more  => send contents of foo.zip via pipe into program more
      unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer
    [dragos@localhost ~]$
    

  • Automate Mouse Clicks on PC record and playback

    Automate Mouse Clicks on PC record and playback

    Automate Mouse Clicks on PC record and playback mouse actions.

    Automate mouse clicks using Python in Windows 10 and this simple script.

    Python is an increasingly popular programming language for quick tasks like this one.

    My Python programs are made of 2 parts.

    one that records mouse click events, that’s all that it does.

    The second part plays back the recorded actions from a dictionary saved as a simple string.

    This can be used to automate almost any task that is done only by clicking with the mouse or dragging in a straight line such as faders on a video edition software.

    My GitHub repo: https://github.com/dragosion/RecordPlayGUI

    You can automate effects presets in most programs to speed-up your workflows.

    You can automate clicks in Excel, Word, Davinci Resolve, anything really.

    This can be extremely useful for Windows 10 Windows 11 and Linux programs that don’t have a way to record actions and replay them.

    For now it only works for mouse clicks.

    Try to avoid drag and drop for now – later if anyone is willing to contribute to the GitHub repo, you are welcomed to branch and send a pull request.

    The new version also records the timing of the clicks.

    Some menus take a bit longer to show so with those mouse clicks, the replay of the actions is in real-time, same as you did when you recorded them.

    Video demo

    Video: how to use

    A very interesting use case is Adobe Audition multi-track automation.

    At the moment there is no way to automate the process of adding filters to Adobe Premiere exported projects to Adobe Audition.

    This script allows you to record all steps of adding multi track filters and effects and master effects.

    Once recorded, the actions can be saved and when you have a new Adobe Audition project, you can automate the effects selections and presets.

    Another interesting use case is a custom program that is old or cannot be updated and has a button that needs to be clicked once every hour for whatever reason.

    Instead of you having to do it manually, this will do it for you.

    It can even be used to shut down or restart the computer.

    Any action can work as long as it’s done by clicking the mouse.