Skip to content

Instantly share code, notes, and snippets.

View AndreiTelteu's full-sized avatar

Andrei Telteu AndreiTelteu

View GitHub Profile
@AndreiTelteu
AndreiTelteu / Custom bread field type .md
Last active February 26, 2024 09:37
Custom bread field type stored in json format. For Laravel + Voyager admin panel

1. A new file: /app/Admin/FormFields/CustomFieldHandler.php

<?php
namespace App\Admin\FormFields;

use TCG\Voyager\FormFields\AbstractHandler;

class CustomFieldHandler extends AbstractHandler
{
@AndreiTelteu
AndreiTelteu / WooCommerce make cart session functional inside an iframe .md
Last active February 20, 2024 17:40
WooCommerce make cart session functional inside an iframe .md

If you need your woocommerce cart functions to work while inside an iframe, you have to add this code in your theme's functions file (or plugin's function file):

function iframe_cookies_samesite_filter_wc_session($enabled, $name, $value, $expire, $secure)
{
    if ( ! headers_sent() ) {
        setcookie($name, $value, [
            'secure'   => true,
            'httponly' => apply_filters( 'woocommerce_cookie_httponly', $httponly, $name, $value, $expire, $secure ),
@AndreiTelteu
AndreiTelteu / ProxyController.php
Created August 3, 2020 11:53
Laravel Simple Proxy Gateway with Guzzle
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use GuzzleHttp\Client;
class ProxyController extends Controller
{
@AndreiTelteu
AndreiTelteu / Incremental file backup and db dumps .md
Last active February 13, 2024 08:12
Incremental file backup and db dumps with mysqldump and autorestic, restic, sql, gzip, weekly, daily

Incremental file backup and MySQL backup

1. Install

Install autorestic: https://autorestic.vercel.app/installation

Let's use /root/backup to store our env file and autorestic config, make a data folder inside to store the actual backups inside, and a temporary database folder for MySQL dumps.

mkdir /root/backup
@AndreiTelteu
AndreiTelteu / # - Jitsi meet - easy setup with custom config .md
Last active February 4, 2024 01:36
Jitsi meet - easy setup with custom config - customizations are: removed all branding, removed every unnecesary button

If you use a ecosystem file, add the following lines to your app:

      interpreter: '/home/forge/.fnm/fnm',
      interpreter_args: 'exec --using=14 node',

14 is the node version. You can be more specific like --using=12.22.4

Example configuration:

If you want to use bavix/laravel-wallet plugin with a one-time inline defined product, here is how to do it:

  1. Create a fake model for it

app/Models/InlineProduct.php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

demo gif

/resources/views/vendor/backpack/crud/fields/dependent_text.blade.php

{{-- dependent text input --}}
@php
    $field['wrapper'] = $field['wrapper'] ?? $field['wrapperAttributes'] ?? [];
    $field['wrapper']['data-field-name'] = $field['wrapper']['data-field-name'] ?? $field['name'];
    $field['wrapper']['data-depends-on'] = json_encode($field['depends_on'] ?? []);
    $field['wrapper']['data-init-function'] = $field['wrapper']['data-init-function'] ?? 'bpFieldInitDependentTestElement';
@AndreiTelteu
AndreiTelteu / Axiom Logger for Laravel v10 .md
Created September 20, 2023 15:46
Axiom Logger for Laravel v10

app/Logging/AxiomLogger.php

<?php

namespace App\Logging;

use Http;
use Monolog\Logger;
use Monolog\Handler\HandlerInterface;
@AndreiTelteu
AndreiTelteu / linux-create-user-if-not-exists-hook.sh
Created July 2, 2023 14:54
Linux script create user and group if not exists
#!/bin/bash
USER_NAME=app
cat /etc/passwd | grep ${USER_NAME} >/dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "user ${USER_NAME} exists"
else
groupadd -r ${USER_NAME} -g 1000 && useradd -u 1000 -r -g ${USER_NAME} -m -d /home/${USER_NAME} -s /bin/bash -c "App user" ${USER_NAME}
fi