Skip to content

Instantly share code, notes, and snippets.

View zoparga's full-sized avatar

Papp Zoltán zoparga

View GitHub Profile
@zoparga
zoparga / DeleteFolderContent.php
Created April 22, 2024 05:48
DeleteFolderContent
use Illuminate\Filesystem\Filesystem;
// 2 LINES OF MAGIC
$file = new Filesystem;
$file->cleanDirectory('storage/temp/');
@zoparga
zoparga / GenerateSafeUuidTrait.php
Created April 19, 2024 08:03
GenerateSafeUuidTrait
<?php
namespace App\Traits;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
trait GenerateSafeUuidTrait
{
public static function bootHasUuid()
@zoparga
zoparga / temp-url-for-local-files.php
Last active February 22, 2024 13:24
Laravel create temp url for files
//AppServiceProvider.php
Storage::disk('local')->buildTemporaryUrlsUsing(function ($path, $expiration, $options) {
return URL::temporarySignedRoute(
'local.temp',
$expiration,
array_merge($options, ['path' => $path])
);
});
@zoparga
zoparga / remove-meta.sh
Last active September 27, 2023 05:46
Removing meta data with the help of mat2
#!/bin/bash
# Source folder where your files are located
source_folder="/home/pappz/Downloads/metatest"
# Check if the source folder exists
if [ ! -d "$source_folder" ]; then
echo "Source folder does not exist: $source_folder"
exit 1
fi
@zoparga
zoparga / remove_from_git.sh
Created January 25, 2023 12:01
Remove from git commit history
# Remove DIRECTORY_NAME from all commits, then remove the refs to the old commits
# (repeat these two commands for as many directories that you want to remove)
git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch DIRECTORY_NAME/' --prune-empty --tag-name-filter cat -- --all
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
# Ensure all old refs are fully removed
rm -Rf .git/logs .git/refs/original
# Perform a garbage collection to remove commits with no refs
git gc --prune=all --aggressive
@zoparga
zoparga / addToAppServiceProvider.php
Created September 15, 2022 07:21
Add these to AppServiceProvider to provide proper DEV environment
if (! app()->environment('local')) {
\URL::forceScheme('https');
}
if (! app()->environment('production')) {
Mail::alwaysTo('dev@email.address');
}
Model::preventLazyLoading(! app()->isProduction());
@zoparga
zoparga / InterventionImageWatermarkStuff.php
Created November 9, 2021 13:52
Place multiple watermark on picture with a 45 degree
$divided_by = 4;
$watermark_text = "watermark text";
for ($i = 0; $i < $image_resize->getWidth(); $i = $i+($image_resize->getWidth()/$divided_by)) {
for ($j = 0; $j < $image_resize->getHeight(); $j = $j+($image_resize->getHeight()/$divided_by)) {
$image_resize->text($watermark_text, $i, $j, function ($font) use ($image_resize) {
$font->file(storage_path('fonts/DejaVuSans.ttf'));
$font->size(($image_resize->getHeight()/70));
$font->color(array(0, 0, 0, 0.2));
$font->align('center');
@zoparga
zoparga / collection-paginate.php
Created June 3, 2021 03:03
Laravel collection or array paginator.
<?php
public function paginate($items, $perPage = 15, $page = null, $options = [])
{
$page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
$items = $items instanceof Collection ? $items : Collection::make($items);
return new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(), $perPage, $page, $options);
}
@zoparga
zoparga / SetLanguage.php
Created April 6, 2021 11:49
Laravel localize middleware
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
class SetLanguage
{
@zoparga
zoparga / ftp-upload.sh
Created December 17, 2020 05:21
simple FTP file upload script
#!/bin/bash
############### Infos - Edit them accordingly ########################
DATE=`date +%Y-%m-%d_%H%M`
LOCAL_BACKUP_DIR="/home/username/path/to/db-backups"
#DB_NAME="$MYSQL_DATABASE"
#DB_USER="$MYSQL_USER"
#DB_PASSWORD="$MYSQL_PASSWORD"
FILE_NAME=db-$DATE.sql.gz