Skip to content

Instantly share code, notes, and snippets.

@flaviu-chelaru
flaviu-chelaru / axios.ts
Last active August 6, 2021 08:12
This will allow AXIOS to retry the same request a number of times
// this will make use of axios interceptors
// and allow axios to retry SERVER errors
// on the initial request we initialize attempt count to 1
// then on each retry we increment the attempt number
// we send the attempt number to the server as a custom header (x-attempt)
axios.interceptors.request.use((request: AxiosRequestConfig) => {
request.headers.common = {
'x-attempt': request.headers.common['x-attempt'] || 1
};
// @todo add aditional stuff: add random user agent, add proxy, etc
@flaviu-chelaru
flaviu-chelaru / ExceptionHandler.php
Created October 1, 2019 06:44
Retry exception handler
<?php
class ExceptionHandler {
public static function retry(\Closure $main, ?\Closure $onFailure = null, $tries = 10) {
$throwable = null;
try {
call_user_func($main);
} catch(\Throwable $throwable) {
// i would advise catching only specfic exceptions here

Backup crons

These can be used to setup backups in a shared hosting with CPANEL (for example)

Backup a public web directory to a ftp directory

cd ~/public_html && tar -zcvf ~/public_ftp/bkp$(date +\%F).tar.gz .

Dump a database to a ftp directory