Usefull traits

Get class_basename trait

trait ClassBasename {
  public static function class_basename() {
        return substr(strrchr('\\' . static::class, '\\'), 1);

This trait returns class basename. If you have e.g. class something\\class\\path\\MyClass it will returns only MyClass.

Get class_namespace trait

trait ClassNamespace {
  public static function class_namespace() {
        return trim(substr(static::class, 0, strrpos('\\' . static::class, '\\')), '\\');

This trait returns class namespace. If you have e.g. class something\\class\\path\\MyClass it will returns only something\\class\\path.


Convert video for iMovie with ffmpeg

You need to include the argument -pix_fmt yuv420p to generate H.264 content for Apple software/devices, and a bunch of other decoders that don't handle yuv444p.

ffmpeg -i input.avi -pix_fmt yuv420p output.mp4

Apple added ProRes support sometime in late 2014 since iMovie 10 you can use follow code:

ffmpeg -i input.avi -c:v prores -c:a pcm_s16le

Formats compatible with macOS Catalina:

Video formats:

  • Apple Animation Codec
  • Apple Intermediate Codec
  • Apple ProRes
  • AVCHD (including AVCCAM, AVCHD Lite, and NXCAM)
  • DV (including DVCAM, DVCPRO, and DVCPRO50)
  • H.264
  • HDV
  • HEVC
  • iFrame
  • Motion JPEG (OpenDML only)
  • MPEG-4 SP
  • Photo JPEG
  • XAVC-S

Container formats

  • 3GP
  • AVI
  • M4V
  • MOV (QuickTime)
  • MP4

Audio formats

  • AAC
  • AIFF
  • BWF
  • CAF
  • MP3
  • MP4
  • RF64
  • WAV

More information about incompatible media in iMovie for macOS


Add copy to clipboard button to all preformat code in pure Javascript

document.onreadystatechange = function () {
  if (document.readyState == 'complete') {

    // for all pre > code
    document.querySelectorAll('pre > code').forEach(function (codeBlock) {

      // create anchor element
      let copy = document.createElement('a');
      copy.className = 'btn-copy';
      copy.innerText = 'Copy';
      copy.title = 'Copy to Clipboard!';
      copy.href = '#';

      // add click event
      copy.addEventListener('click', function (e) {
        copy.innerText = 'Copied!';

        // copy innerText of preformat
        navigator.clipboard.writeText(codeBlock.innerText).then(function () {
          setTimeout(function () {
            copy.innerText = 'Copy';
          }, 500);
        }, function (err) {
          copy.innerText = 'ERROR';

        // do nothing else...

      }, false);

      // insert before codeBlock <pre><a><code>
      codeBlock.parentNode.insertBefore(copy, codeBlock);
a.btn-copy:hover {
  color: black;
  user-select: none;
  position: absolute;
  padding: 8px;
  font-size: smaller;
  right: 0;
  top: 0;

As with many new APIs, navigator.clipboard is only supported for pages served over HTTPS. To help prevent abuse, clipboard access is only allowed when a page is the active tab. Pages in active tabs can write to the clipboard without requesting permission, but reading from the clipboard always requires permission.


Docker cleanup guide

Docker doesn't remove unused objects such as containers, images, volumes, and networks unless you explicitly tell it to do so. How To Remove them?

Removing All Unused Objects

Remove stopped containers, all dangling images, and all unused networks:

docker system prune
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - all dangling build cache

Are you sure you want to continue? [y/N] 

You can also include all unused volumes, then add --volumes:

docker system prune --volumes

Docker Containers

docker container ls -a

Remove selected container

docker container rm [CONTAINER ID]

Remove all stopped containers

To remove all stopped containers use:

docker container prune

You can also list what will be removed:

docker container ls -a --filter status=exited --filter status=created 

Stop and remove all containers

docker container stop $(docker container ls -aq)
docker container rm $(docker container ls -aq)

Docker Images

You can list them:

docker image ls

Remove selected image

docker image rm [IMAGE ID]

Remove dangling images

A dangling image is an image that is not tagged and is not used by any container. You can remove them by:

docker image prune

Remove all unused images

To remove all images which are not referenced by any existing container, not just the dangling ones, use the prune command with the -a flag:

docker image prune -a

Docker Networks

You can list them with:

docker network ls

Remove selected network

docker network rm [NETWORK ID]

Remove all unused networks

Use the docker network prune command to remove all unused networks. Remove all networks that are created more than 12 hours ago:

docker network prune -a --filter "until=12h"

Docker Volumes

docker volume ls

Remove selected Volume

docker volume rm [VOLUME NAME]

Remove all unused volumes

docker volume prune


Create image slideshow with ffmpeg

Following will take all *.jpg images from current folder and create mp4 image slideshow. Images can have different sizes, ffmpeg will rescale or pad them.

ffmpeg -framerate 1/3 \
       -pattern_type glob -i '*.jpg' \
       -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1" \
       -c:v libx264 -crf 14 -r 25 -pix_fmt yuv422p \
  • -framerate 1/3 image will be change each 3 sec
  • -pattern_type glob -i '*.jpg' will use all *.jpg images from current folder
  • -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1" rescale or pad image to 1280x720
  • -c:v libx264 use H.264 codec
  • -crf 14 CFR (Constant Rate Factor) is betweemn 0–51, where 0 is lossless, 23 is the default, and 51 is worst quality possible.
  • -r 25 set frame rate.
  • -pix_fmt pixel output format

With background music:

ffmpeg -framerate 1/3 \
       -pattern_type glob -i '*.jpg' \
       -i audiofile.mp3 \
       -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1" \
       -c:v libx264 -crf 14 -r 25 -pix_fmt yuv422p \
       -shortest \
  • -shortest will take shorten source images or mp3 as length limit for video


Convert MYSQL HEX to string with PHP

Hexadecimal literal values are written using X'string' or 0xstring notation, where string contains hexadecimal digits (0..9, A..F).

SELECT HEX('EXAMPLE'), X'4558414D504C45';
| HEX('EXAMPLE') | X'4558414D504C45' |
| 4558414D504C45 | EXAMPLE           |

You can also transform this value HEX value also with PHP instead of SELECT *, HEX(column) as column_name ... SQL.

function hexToString($hex) {
    $string = '';
    for ($i = 0; $i < strlen($hex); $i++) {
        $string .= dechex(ord($hex[$i]));
    return $string;

Inserting string to the table will be easy just "INSERT INTO table (column) VALUES HEX(?)" or with Hexadecimal Literal string starting with 0x or X'string'.