Skip to content

Instantly share code, notes, and snippets.

View EduardoSP6's full-sized avatar

Eduardo P. Sales EduardoSP6

  • Maricá - RJ
  • 10:58 (UTC -03:00)
View GitHub Profile
@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.txt
Last active January 18, 2022 13:29
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;
- O Laravel já possui um listener chamado SendEmailVerificationNotification que é responsavel por enviar
o e-mail quando um usuario é registrado. Ele está relacionado ao evento Auth\Events\Registered.
@EduardoSP6
EduardoSP6 / custom_password_rules_laravel7.txt
Created December 2, 2021 14:04
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
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
@EduardoSP6
EduardoSP6 / password_reset_laravel7.txt
Created December 2, 2021 13:46
Password reset laravel 7
Password reset laravel 7:
- Add the traits below in model User:
Illuminate\Notifications\Notifiable;
Illuminate\Contracts\Auth\CanResetPassword;
- Install laravel/ui that contains the migration of reset token table. Commands:
@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:
@EduardoSP6
EduardoSP6 / round_number_android.java
Last active September 16, 2021 20:24
Round number Android Java
/**
* Arredonda numero
*
* @param mValue - valor a ser arredondado
* @param precision - numero de casas decimais
* @param ceilOrFloor - true para mais, false para menos
**/
public static double roundNumber(double mValue, int precision, boolean ceilOrFloor) {
double result = mValue;
@EduardoSP6
EduardoSP6 / distance_between_coordinates.java
Last active September 16, 2021 20:25
Distance between two coordinates - Java
public static double calcDistanceBetweenCoords(Double origLat, Double origLng, Double destLat, Double destLng)
{
double result = 0;
if (origLat == null || origLng == null || destLat == null || destLng == null) {
return result;
}
// converte as coordenadas para radianos
origLat = Math.toRadians(origLat);
@EduardoSP6
EduardoSP6 / leaflet_geocoding.txt
Last active June 25, 2021 17:55
Leaflet Geocoding PLugin Implementation
<!-- CSS -->
<link rel="stylesheet" href="https://unpkg.com/esri-leaflet-geocoder@2.3.3/dist/esri-leaflet-geocoder.css"
integrity="sha512-IM3Hs+feyi40yZhDH6kV8vQMg4Fh20s9OzInIIAc4nx7aMYMfo+IenRUekoYsHZqGkREUgx0VvlEsgm7nCDW9g=="
crossorigin="">
<!-- JS -->
<script src="https://unpkg.com/esri-leaflet-geocoder@2.3.3/dist/esri-leaflet-geocoder.js"
@EduardoSP6
EduardoSP6 / retrofit_basic_usage_android.java
Last active September 16, 2021 20:26
Retrofit basic usage on Java Android
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;