Skip to content

Instantly share code, notes, and snippets.

@jdefez
jdefez / api-app-docker-compose.yml
Last active November 8, 2021 18:24
Runing two laravel apps using docker
# For more information: https://laravel.com/docs/sail
# The reciever app (the one that will recieve calls from the other laravel app)
# app-one sail up -d
# app-one_laravel.test_1 start-container
# Shutting down old Sail processes...
# Creating network "app-one_sail" with driver "bridge"
# Creating network "app-one_app-shared" with driver "bridge"
# Creating mysql_app_one
@jdefez
jdefez / php-tmp-file.php
Last active October 18, 2021 18:00
Extending SplTempFileObject with a store method
class TmpFile extends SplTempFileObject
{
public function store(string $filename): void
{
file_put_contents($filename, $this->getContents());
}
public function getContents(): ?string
{
$this->rewind();
@jdefez
jdefez / laravel-directive.php
Last active June 27, 2021 15:06
laravel-directives
// tobe inserted in AppServiceProvider@boot method
Blade::directive('selected', function ($expression) {
return "<?php echo {$expression} ? 'selected' : ''; ?>";
});
Blade::directive('checked', function ($expression) {
return "<?php echo {$expression} ? 'checked' : ''; ?>";
});
function isElementInViewport(el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Port} ^80$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Serve the file if it's actually a file on the server
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]