Skip to main content

Posts

Clarify Service Repository

Clarify Service and Repository in Programming In the world of software development, the terms service and repository are often used interchangeably, yet they serve distinct purposes. Understanding the difference between these two concepts is crucial for designing clean and maintainable code. In this blog post, we will explore the roles of services and repositories, and provide a practical example to illustrate their differences. Understanding Services and Repositories Subtopic 1: Defining Services and Repositories When programming, we often use the terms service and repository to define similar things. A service is typically used for fetching or pushing data from or to various sources. It acts as a mediator between the application and the data sources, handling business logic and data transformation. On the other hand, a repository is used for getting or storing data from or to a specific data source, such as a database or an external API. It abstrac...
Recent posts

php annotation type

Annotation to indicate the type of a variable Static analysis tools are invaluable for catching errors and improving code quality. However, they sometimes struggle to infer the type of a variable, especially in complex scenarios. This can lead to false positives or missed errors. In this post, we'll explore how to use annotations to explicitly tell Intelephense (and other similar tools) the type of a variable in PHP, ensuring accurate static analysis. The Problem: Intelephense's Limitations Let's say we have a PHP controller method where we retrieve a user object: class TestAuthController extends AbstractController { #[Route('/api/test/auth', name: 'api_test_auth')] public function testAuth(): Response { $user = $this->getUser(); if ($user) { return $this->json( [ 'id' => $user->getId(), 'username' => $user->getUserIdentifier(), ...

alias neovim config

One command launch Launching Neovim configuration is usually done with 2 or 3 steps. I don't want that, I want it to be one step. Use alias In "~/.bashrc": shopt -s globstar nvim_config() { cd ~/.config/nvim nvim *.lua **/*.lua } alias nvim-config='nvim_config'

Composer Install Force PHP

Install composer dependencies ignoring PHP version When working with PHP projects, you often encounter situations where the required PHP version for a package is slightly different from the one you have installed locally. While it's generally recommended to stick to the specified version, there are cases where minor version differences might not be critical. In such scenarios, you can instruct Composer to ignore the platform requirements and proceed with the installation. Composer install ignoring PHP version Composer provides a handy flag "--ignore-platform-reqs" that allows you to bypass platform checks, including PHP version requirements. This can be particularly useful when you're confident that the minor version difference won't affect the package's functionality in your project. For instance, let's say a package you want to install requires PHP 8.2, but you have PHP 8.3 installed. In this case, you can use the following command to i...

Neovim Leader Menu

How to Make a Menu in Neovim How to Make a Menu in Neovim In Neovim leader key pull up a menu, it is the which-key plugin. I saw many videos where people use a menu in Neovim. They just press the leader key and a menu pops up. I wanted to have that too. I wondered which component of Neovim is responsible for that. I found out that it is the which-key plugin: https://github.com/folke/which-key.nvim Cases where a menu is useful in Neovim Neovim has already a bunch of "commands". Why would I need a menu? Useful when you want to group a set of commands you often use together. Also helpful when the command name is hard to remember: use the leader key and a combo of keys to get to the command. How to write a menu tree in Neovim configuration I use code-ai.nvim plugin to call AI to write code for me. I have defined a bunch of commands in my configuration fi...

ChatGPT Gemini REST API

Using direct AI REST API instead of SDK When working with large language models (LLMs) like ChatGPT and Gemini, developers often turn to Software Development Kits (SDKs) for streamlined integration. While SDKs offer convenience, there are compelling reasons to consider using the direct REST API, especially when starting new implementations like plugins or SDKs for a new language. This blog post will explore the advantages of this approach. ChatGPT and Gemini SDK SDKs simplify the process of interacting with LLMs. They provide pre-built functions and handle low-level details, making it easier to send prompts and receive responses. Let's look at examples for ChatGPT and Gemini: ChatGPT SDK The ChatGPT SDK for Node.js is available at https://github.com/openai/openai-node . Here's how to use it: import OpenAI from 'openai'; const client = new OpenAI({apiKey: process.env['OPENAI_API_KEY']}); async function main() { const chatCompletion = ...

Undefined global vim

Defining vim as global outside of Neovim When developing plugins for Neovim, particularly in Lua, developers often encounter the "Undefined global vim" warning. This warning can be a nuisance and disrupt the development workflow. However, there is a straightforward solution to this problem by configuring the Lua Language Server Protocol (LSP) to recognize 'vim' as a global variable. Getting "Undefined global vim" warning when developing Neovim plugin While developing Neovim plugins using Lua, the Lua language server might not recognize the 'vim' namespace by default. This leads to warnings about 'vim' being an undefined global variable. These warnings are not just annoying but can also clutter the development environment with unnecessary alerts, potentially hiding other important warnings or errors. Defining vim as global in Lua LSP configuration to get rid of the warning To resolve the "Undefined global vi...