Skip to content

Instantly share code, notes, and snippets.

@robjbrain
robjbrain / AppServiceProvider.php
Created April 4, 2023 02:44
Improved remaining time calculation for laravel and symfony progress bar
//In order to get more accurate remaining time when using Laravel Progress Bar add this to AppServerProvider@boot
use Symfony\Component\Console\Helper\ProgressBar;
ProgressBar::setPlaceholderFormatterDefinition('remaining', function($bar) {
$remaining = $bar->getRemaining();
$hours = floor($remaining / 3600);
$minutes = floor(($remaining / 60) % 60);
$seconds = $remaining % 60;
return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
@robjbrain
robjbrain / gist:6dd5346e5844eff598639af0654d5b42
Created April 8, 2019 02:30
Simple way to optionally paginate a request
<?php
/*
This will avoid doing this all the time.
public function index(Request $request)
{
$query = Model::with(['foo, 'bar');
return ModelResource::collection($request->input('per_page')
@robjbrain
robjbrain / Fix Incorrect datetime value: '0000-00-00 00:00:00'
Created November 22, 2016 13:26
How to set datetime to null when accidentally set to '0000-00-00 00:00:00'
# If you've accidentally got '0000-00-00 00:00:00' in a datetime field you can't fix it with this:
UPDATE table SET datetime = NULL WHERE datetime = '0000-00-00 00:00:00'
# Because you'll get this error:
Incorrect datetime value: '0000-00-00 00:00:00'
# But you can fix it with this
@robjbrain
robjbrain / 0_reuse_code.js
Created August 3, 2016 10:13
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
#!/usr/bin/env bash
# Backup uploaded files
aws s3 sync ~sortitoutsi/httpdocs/public/uploads/files s3://sortitoutsi/files --size-only --storage-class 'STANDARD_IA'
# Backup uploaded images
aws s3 sync ~sortitoutsi/httpdocs/public/uploads/images s3://sortitoutsi/images --size-only --storage-class 'STANDARD_IA'
# Backup career stats
aws s3 sync ~sortitoutsi/httpdocs/public/uploads/careerstats s3://sortitoutsi/careerstats --size-only --storage-class 'STANDARD_IA'