Skip to content

Instantly share code, notes, and snippets.

@DominikStyp
DominikStyp / README.md
Last active February 20, 2025 15:53
RasbperryPI clone SD Card

In Linux Ubuntu mount the card
Check which one is the mounted SD Card:

lsblk

Then go to the directory you want to have backup in and run:

sudo dd if=/dev/sdb of=./raspberry_backup.img bs=4M status=progress
@DominikStyp
DominikStyp / README.md
Last active February 18, 2025 16:50
qBittorrent on RasbperryPI 5

Installation

sudo apt update
sudo apt install qbittorrent-nox -y

Set it up as service

@DominikStyp
DominikStyp / README.MD
Created February 12, 2025 18:41
Xdebug in PHPUnit with Laravel

Xdebug in tests

To make sure you can step debug run: export PHP_IDE_CONFIG="serverName=dev.portal.local" in your terminal before running tests. Also make sure you have this server configured in the PHPStorm Settings -> PHP -> Servers.

To disable warnings when IDE is not listening for connections do this, for example:

export XDEBUG_MODE=off && vendor/bin/phpunit tests/Feature/Test.php

To turn it on again do this, for example:

@DominikStyp
DominikStyp / MockedRequestTest.php
Last active February 12, 2025 18:08
Laravel: Mock the request for view test
<?php
use Illuminate\Support\Facades\Request;
use Mockery as m;
use Tests\TestCase;
// this is solving the static calls for the route like:
// @if(Request::route()->getName() == 'admin.report') ........
// <li class="{{Request::is('*/admin/conversion*') ? 'active' : null }}"> .........
//
// one can mock those and test the view content only with data
@DominikStyp
DominikStyp / 99-usb-mount.rules
Last active February 10, 2025 00:36
Veracrypt and Samba installation on RaspberryPI and share encrypted drives in Windows 11 via local WiFi
# /etc/udev/rules.d/99-usb-mount.rules
# --property=KillMode=none important to NOT kill the veracrypt service when action finishes
ACTION=="add", KERNEL=="sd[a-z]*", SUBSYSTEM=="block", ENV{UDISKS_IGNORE}="1", \
RUN+="/usr/bin/systemd-run --property=KillMode=none /home/dominik/mountDisks.sh"
@DominikStyp
DominikStyp / initComposerInstall.sh
Created January 7, 2025 17:26
Docker: install laravel/sail with docker run from image PHP 7.3 CLI
docker run --rm -v $(pwd):/app -w /app php:7.3-cli bash -c "
apt-get update && \
apt-get install -y libzip-dev libpng-dev libjpeg-dev sendmail-bin && \
apt-get install -y autoconf bison re2c libxml2-dev && \
pecl install mailparse && \
docker-php-ext-enable mailparse && \
docker-php-ext-install gd zip && \
curl -sS https://getcomposer.org/installer | php && \
php composer.phar install --no-scripts && \
php composer.phar require laravel/sail --dev --no-scripts"
@DominikStyp
DominikStyp / README.md
Created November 19, 2024 11:23
Traefic with docker-compose example

Traefik Reverse Proxy Example with Docker Compose

This example demonstrates how to use Traefik as a reverse proxy for a web service defined in a Docker Compose file. Traefik routes incoming requests based on specified rules and forwards the traffic to the web service.

Prerequisites

  • Docker
  • Docker Compose
  • Traefik installed and configured (e.g., as a container service)
@DominikStyp
DominikStyp / .php-cs-fixer.php
Created November 5, 2024 09:43
PHP CS-FIXER initial setup
<?php
use PhpCsFixer\Config;
use PhpCsFixer\Finder;
$finder = Finder::create()
->in(__DIR__)
->name('*.php')
->ignoreDotFiles(true)
->ignoreVCS(true)
@DominikStyp
DominikStyp / check_cpu_load_win11_multicore_cpu.py3
Last active October 29, 2024 20:12
Python3: check correct CPU usage in Windows 11 for multicore CPU
import ctypes
import time
class CPUUsageMonitor:
"""
A class to monitor CPU usage using the Windows PDH (Performance Data Helper) API via ctypes.
"""
# PDH constants
PDH_FMT_DOUBLE = 0x00000200
@DominikStyp
DominikStyp / SynchronizeWithPivot.php
Created October 17, 2024 13:27
Laravel 10: synchronize MorphToMany relation WITH PIVOT VALUES
<?php
$roleIds = Role::whereIn('name', ['admin', 'moderator'])->pluck('id')->toArray();
// if pivot table relies on some additional value like in the example 'brand_slug' => 'some-slug'
// we need to use syncWithPivotValues() where we're gonna update pivot records with 'brand_slug' values
$user->brandRoles($brandSlug)->syncWithPivotValues(
$roleIds,
[
'brand_slug' => $brandSlug