Skip to content

Instantly share code, notes, and snippets.

@j-dexx
j-dexx / DatabaseMacroProvider.php
Created November 22, 2022 13:21
Using mysql native types that are not supported in laravel's schema builder
<?php
namespace App\Providers;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\Type;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Grammars\Grammar;
use Illuminate\Support\ServiceProvider;
@j-dexx
j-dexx / UpdateAlreadyRunMigrations.php
Created December 7, 2021 12:40
Update already ran laravel migrations
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class UpdateAlreadyRunMigrations extends Command
{
/**
@j-dexx
j-dexx / ResponsiveImageUrlsGenerator.php
Created June 24, 2020 17:11
Replacing Upload URLs in WYSIWYG Content
<?php
namespace App\Services\Wysiwyg;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Spatie\MediaLibrary\ResponsiveImages\ResponsiveImage;
class ResponsiveImageUrlsGenerator
{
private Media $media;
@j-dexx
j-dexx / calculate-paperclip-attachment-url.php
Created June 18, 2020 13:25
Calculating paperclip attachment url
/**
* https://www.rubydoc.info/github/thoughtbot/paperclip/Paperclip%2FInterpolations:id_partition
*/
protected function calculateIdPartition(int $modelId): string
{
$idString = $this->convertIntegerToString($modelId);
$zeroPaddedString = str_pad($idString, 9, "0", STR_PAD_LEFT);
$parts = str_split($zeroPaddedString, 3);
return implode('/', $parts);
}
@j-dexx
j-dexx / AuthyToOtherAuthenticator.md
Created January 23, 2020 19:44 — forked from gboudreau/AuthyToOtherAuthenticator.md
Export TOTP tokens from Authy

Generating Authy passwords on other authenticators


There is an increasing count of applications which use Authy for two-factor authentication. However many users who aren't using Authy, have their own authenticator setup up already and do not wish to use two applications for generating passwords.

Since I use 1Password for all of my password storing/generating needs, I was looking for a solution to use Authy passwords on that. I couldn't find any completely working solutions, however I stumbled upon a gist by Brian Hartvigsen. His post had a neat code with it to generate QR codes (beware, through Google) for you to use on your favorite authenticator.

His method is to extract the secret keys using Authy's Google Chrome app via Developer Tools. If this was not possible, I guess people would be reverse engineering the Android app or something like that. But when I tried that code, nothing appeared on the screen. My gues

@j-dexx
j-dexx / googlemaps.js
Created January 10, 2020 14:58
Google Maps Bounding Box
var markers = [];
var map;
var locations;
var latlngbounds;
var infoWindows = [];
var lastMarker;
function initialize() {
locations = $('#map-canvas').data('locations')
var mapOptions = {
@j-dexx
j-dexx / journal.php
Created July 31, 2019 09:44
Journal
class Journal
{
// journals this journal references
public function references()
{
return $this->belongsToMany(Journal::class, 'references', 'journal_id', 'reference_id');
}
// inverse the keys to retrieve journals this is referenced by
public function referencedByJournals()
@j-dexx
j-dexx / MyTest.php
Last active July 22, 2019 10:45
Testing File Uploads in Laravel
class MyTest extends TestCase
{
public function test_successful()
{
$type = factory(Type::class)->create([
'type' => Type::TYPE_CHECK_IN,
]);
$admin = $this->createAdmin();
$client = factory(Client::class)->create();
$user = factory(User::class)->create([
@j-dexx
j-dexx / Crontab
Last active March 9, 2022 14:17
Back Ups To S3
0 1 * * * /var/www/automated_backups/site-backup.sh >/dev/null 2>&1
0 5 * * * /var/www/automated_backups/sync-with-s3.sh >> /var/log/s3-backup.log
@j-dexx
j-dexx / Ingredient.php
Created February 23, 2018 10:30
Has many through belongs to
class Ingredient
{
public function section()
{
return $this->belongsTo(Section::class);
}
}