Skip to content

Instantly share code, notes, and snippets.

View EduardoSP6's full-sized avatar

Eduardo P. Sales EduardoSP6

  • Maricá - RJ
  • 01:54 (UTC -03:00)
View GitHub Profile
@EduardoSP6
EduardoSP6 / implementing_pagination_php_and_spatie_query_builder.md
Last active February 28, 2025 21:54
Implementing pagination in PHP with Spatie Query Builder + React Tanstack Table

Implementing pagination in PHP with library Spatie Query Builder + React Tanstack Table

Tested with:

Back-end implementation:

@EduardoSP6
EduardoSP6 / prevent-pull-to-refresh.md
Last active January 14, 2025 21:42
Prevent pull to refresh - React.js | Javascript

How to Prevent Page Refresh When Swiping Down on Mobile

In many mobile browsers, a "pull down" gesture at the top of the page can trigger the "pull-to-refresh" functionality. While useful in some scenarios, this behavior can be undesirable in web applications that utilize touch elements or where the page should not be reloaded.

We can use touch events (touchstart and touchmove) to detect when the user tries to "pull down" from the top of the page. In this case, we can prevent the default refresh action, ensuring that normal scrolling continues to work.

To do this, I created the component below:

@EduardoSP6
EduardoSP6 / PdfToText.php
Last active January 8, 2025 16:14
How to convert PDF to Text with Tesseract OCR
<?php
namespace Infrastructure\Utils\OCR;
use Exception;
use Imagick;
use ImagickException;
use RuntimeException;
use thiagoalessio\TesseractOCR\TesseractOCR;
@EduardoSP6
EduardoSP6 / object_props_to_array.php
Last active January 8, 2025 16:23
Method to convert object properties to array in PHP
<?php
public function __toArray(): array
{
return call_user_func('get_object_vars', $this);
}
@EduardoSP6
EduardoSP6 / csv_to_array.php
Last active January 28, 2022 16:04
PHP function to convert CSV file content to array
<?php
function csvToArray($filename = '', $delimiter = '\t')
{
if (!file_exists($filename) || !is_readable($filename))
return [];
$row = 0;
$fileContent = [];
if (($handle = fopen($filename, "r")) !== FALSE) {
@EduardoSP6
EduardoSP6 / verify_email_laravel_7.md
Last active January 8, 2025 18:26
Custom e-mail verification Laravel 7

Implementação de rotina de verificação da conta de e-mail

  • Criar migração do model User adicionando o campo:
$table->timestamp('email_verified_at')->nullable();
  • Implementar a interface MustVerifyEmail no model User;
@EduardoSP6
EduardoSP6 / custom_password_rules_laravel7.md
Last active January 8, 2025 18:31
Custom password validation laravel 7

Custom password validation laravel 7:

For create a custom password rule for laravel you should run a command: php artisan make:rule PasswordRule. The class will be created in App\Rules folder.

Example:

<?php
@EduardoSP6
EduardoSP6 / password_reset_laravel7.md
Last active January 8, 2025 18:41
Password reset laravel 7

Password reset in Laravel v7.x:

  • Add the traits below in model User:
Illuminate\Notifications\Notifiable;
Illuminate\Contracts\Auth\CanResetPassword;
@EduardoSP6
EduardoSP6 / realmobject_to_json.java
Last active November 19, 2021 16:08
Convert realm object to json
import org.json.JSONException;
import org.json.JSONObject;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import io.realm.RealmObject;
@EduardoSP6
EduardoSP6 / vscode_snippet.txt
Created October 22, 2021 11:06
Custom react and react native snippets for VSCode
### Snippet para o VS Code
- Dentro do VS Code tecle `Ctrl + Shift + P`, digite `snippet` e escolha a opção `Preferences: Configure User Snippets`;
- Clicar em New Global Snippets file...
- Digite um nome para o arquivo;
- Apagar o conteudo do arquivo e inserir o json abaixo: