Skip to content

Instantly share code, notes, and snippets.

View leonardopinho's full-sized avatar

Leonardo Pinho leonardopinho

View GitHub Profile
import 'dart:io';
import 'package:device_info/device_info.dart';
static Future<String> getDeviceId() async {
String result;
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
if (Platform.isAndroid) {
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
result = androidInfo.id;
}
static Future<Uint8List> convertToUint8List({@required String url}) async {
Uint8List result;
try {
Response response = await client.get(url);
result = response.bodyBytes;
} on Exception catch (e) {
Helper.log(e);
}
return result;
}
public function __invoke(User $user){
$token = app('auth.password.broker')->createToken($user);
$user->sendPasswordResetNotification($token);
return {
'status' => 'success',
'message' => 'Email enviado com sucesso'
};
}
using System;
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
public static string GenerateSlug(this string phrase)
{
string str = phrase.RemoveAccent().ToLower();
// invalid chars
str = Regex.Replace(str, @"[^a-z0-9\s-]", "");
// convert multiple spaces into one space
str = Regex.Replace(str, @"\s+", " ").Trim();
// cut and trim
str = str.Substring(0, str.Length <= 45 ? str.Length : 45).Trim();
str = Regex.Replace(str, @"\s", "-"); // hyphens
/**
* saveOriginalPhoto
* @param Request $request
* @param $sub_path
* @return string
*/
public static function saveOriginalPhoto(Request $request, $sub_path)
{
$File = $request->file('image');
$real_name = md5(rand(11111, 99999)) . '_' . time() . '.jpg';
@leonardopinho
leonardopinho / base64ToFile.php
Last active June 19, 2022 11:42
Laravel: Convert base64 to file and resize the final size.
/**
* base64ToFile
* @param $base64
* @param $path
* @param int $width
* @param int $height
* @return string
* @info usage 'Image' => Intervention\Image\Facades\Image::class
*/
public static function base64ToFile($base64, $path, $width = 400, $height = 400)
/**
* getIpInfo
* @param null $ip
* @return mixed
*/
public static function getIpInfo($ip = null)
{
if (!empty($ip) && !is_null($ip)) {
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
return $details;
@leonardopinho
leonardopinho / GoogleUtils.cs
Last active August 22, 2018 14:53
Useful class for Youtube integration
using System.Net;
using Newtonsoft.Json;
namespace Utils
{
public class GoogleUtils
{
private string _apiKey = "";
private string _shortUrl = "https://www.googleapis.com/urlshortener/v1/url?fields=id%2ClongUrl%2Cstatus&key=";
private string _urlYoutubeLastVideos = "https://www.googleapis.com/youtube/v3/search?key=";
/**
* Convert one simple date in Carbon instance object
* @param $date
* @param string $delimiter
* @return Carbon
*/
public static function convertToCarbonInstance($date, $delimiter = '-')
{
$sp_date = explode($delimiter, $date);
return Carbon::parse($sp_date[2] . '-' . $sp_date[1] . '-' . $sp_date[0]);