Skip to content

Instantly share code, notes, and snippets.

View AndreiTelteu's full-sized avatar

Andrei Telteu AndreiTelteu

View GitHub Profile
@AndreiTelteu
AndreiTelteu / PHP opcache invalidate entire directory .md
Last active January 25, 2022 15:20
How to invalidate an entire directory with opcache, also in a laravel middleware
<?php
$directories = [
    'absolute/path/to/dir',
    'multiple/dirs/if/needed',
];
$extensions = [
    'php',
];
function invalidateDirectory($dir) {
@AndreiTelteu
AndreiTelteu / Manual export inline with maatwebsite excel laravel package .md
Last active February 6, 2022 12:22
How to export/import in excel format with maatwebsite/excel using inline anonymous class, without any external files #laravel

Using this plugin: maatwebsite/excel

composer require maatwebsite/excel

You can use this anywhere in your app.

<?php
@AndreiTelteu
AndreiTelteu / # - Jitsi meet - easy setup with custom config .md
Last active June 20, 2025 07:26
Jitsi meet - easy setup with custom config - customizations are: removed all branding, removed every unnecesary button
@AndreiTelteu
AndreiTelteu / Backpack export operation (excel and csv) .md
Last active October 4, 2022 17:58
Export operation for backpack admin panel, that exports the entire database table, not just the entries shown on page
  1. First install maatwebsite/excel package:
composer require maatwebsite/excel
  1. Copy export.blade.php from this gist in resources/views/vendor/backpack/crud/buttons/export.blade.php

  2. Copy ExportOperation.php from this gist in app/Traits/Operations/ExportOperation.php

@AndreiTelteu
AndreiTelteu / aapanel install mysql
Last active July 20, 2022 16:07
aapanel instal mysql
cd /www/server/panel/install
bash ./install_soft.sh 1 install mysql mariadb_10.4
bash ./install_soft.sh 1 install openlitespeed 1.7

You can follow microsoft's official instalation steps, however if you have multiple php instalations (I have php7.4 and 7.3 installed on my laravel forge server) you need to specify what version to build the extension with.

# make sure you have this installed:
sudo apt-get install -y unixodbc-dev

# elevate as root
sudo su
pecl -d php_suffix=7.3 install sqlsrv
pecl -d php_suffix=7.3 install pdo_sqlsrv
@AndreiTelteu
AndreiTelteu / Laravel stream large file with buffer .php
Created February 7, 2023 21:50
Laravel stream large file from disk with buffer.
<?php
// inspired by https://github.com/imanghafoori1/laravel-video
// if you need this for video, this does not support seek.
// laravel-video supports seek and chunks, so use that for video.
Route::get('/big-file-stream', function () {
$filePath = \Storage::disk('local')->path('video.mp4');
$fileStream = \Storage::disk('local')->readStream('video.mp4');
@AndreiTelteu
AndreiTelteu / Solidjs full year calendar .tsx
Created February 9, 2023 16:55
Solidjs full year calendar build with momentjs
import { Component, For } from "solid-js";
import moment from "moment";
import "moment/dist/locale/ro";
moment.locale("ro");
const App: Component = () => {
const weekdays = moment.weekdaysMin();
const months = moment.months();
const fullYear = Object.fromEntries(
months.map((monthName, monthIndex) => {
@AndreiTelteu
AndreiTelteu / Incremental file backup and db dumps .md
Last active November 18, 2024 02:48
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 / React useBetterState with mutable, callback, and promise .md
Last active April 7, 2023 09:15
React useBetterState with mutable state, callback after change, and promise. Just like the old this.setState() Class Component days. DEMO: https://stackblitz.com/edit/react-usebetterstate

useBetterState

I'm trying to bring back the magic of setState(value, callback) from React Class Component days, while adding more functionality on top, like promises and mutable state.

To start using it, initialize it with:

const [state, setState] = useBetterState({
  count: 0,