Skip to content

Instantly share code, notes, and snippets.

View monteiro's full-sized avatar
🏠
Working from home

Hugo Monteiro monteiro

🏠
Working from home
View GitHub Profile
@monteiro
monteiro / ImageChecker.php
Created October 17, 2024 07:30
Check contents of the image using free gemini 1.5 turbo
<?php
namespace App\Livewire;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use Livewire\Component;
use Livewire\WithFileUploads;
class ImageChecker extends Component
@monteiro
monteiro / run-tts-google-api.php
Created May 2, 2024 08:06
Using google TTS API with PHP
<?php
require_once 'vendor/autoload.php';
// Function to convert text to speech using Google Cloud Text-to-Speech API
function textToSpeech($text, $serviceAccountPath) {
// Create and configure a new client object
$client = new Google_Client();
$client->setAuthConfig($serviceAccountPath);
$client->addScope('https://www.googleapis.com/auth/cloud-platform');
$httpClient = $client->authorize();
@monteiro
monteiro / telegram_fitness_bot.php
Last active February 26, 2024 11:08
Create a fitness coach using telegram Bot API in PHP (PULL METHOD)
<?php
require __DIR__ . '/vendor/autoload.php';
$openApiKey = 'OPEN_API_KEY";
$botToken = 'BOT_TOKEN';
$apiURL = "https://api.telegram.org/bot$botToken/";
$offset = 0;
// Function to send messages via Telegram
@monteiro
monteiro / gpt-contract-translator.php
Last active February 10, 2024 15:27
Translate legal documents to any Portuguese of Portugal
<?php
require 'vendor/autoload.php';
// use an html version of the contract exported from Microsoft Word, to avoid having to deal with word formatting issues
$html = file_get_contents(__DIR__ . '/contract.html');
// Assuming you have a function that can split the HTML content into manageable chunks
// This is a placeholder; you'd need to implement or find a suitable way to split the HTML.
$chunks = split_html_into_chunks($html, 4000); // Split HTML into chunks of up to 4000 tokens
@monteiro
monteiro / HomepageController.php
Last active March 3, 2024 14:23
Redirect to page according to the Accept-Language header using Symfony 5
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class HomepageController extends AbstractController
{
@monteiro
monteiro / AccountController.java
Last active December 11, 2015 15:19
Handle File upload and cut Image using ImageUtilities
private static Boolean handleProfilePictureUpload(User user, Request request) {
Boolean isChanged = Boolean.FALSE;
Http.MultipartFormData body = request.body().asMultipartFormData();
Http.MultipartFormData.FilePart uploadFilePart = body
.getFile("picture");
if (uploadFilePart != null) {
File file = uploadFilePart.getFile();
ImageUtilities.scale(file, 50, 50); // x = 50px y = 50px
S3File s3File = new S3File();
@monteiro
monteiro / Application.java
Last active February 14, 2017 21:54
Adding Play! Framework 2.0 (2.0.4-Java) pagination with Bootstrap (http://twitter.github.com/bootstrap/) tables using EHCache (http://ehcache.org/).
package controllers;
public class Application extends Controller {
// in cache during 1800 seconds (30 min)
@Cached(key = "pagingList", duration = 1800)
public static Result index(Integer page) {
String uuid = session("uuid");
if (uuid == null) {
uuid = java.util.UUID.randomUUID().toString();