Goland CORS, logs and healtcheck

In this guide, weโ€™ll walk through how to create CORS (Cross-Origin Resource Sharing) and a health check endpoint in a Golang application using the Chi router. Setting Up Chi and CORS Middleware Weโ€™ll use the go-chi/chi and go-chi/cors packages to handle routing and CORS in our application. Step 1: Import Required Packages First, make sure to import the necessary packages: import ( "fmt" "net/http" "log" "github.com/go-chi/chi" "github.com/go-chi/chi/middleware" "github.com/go-chi/cors" AdminMiddleware "github.com/project/api/middleware" "github.com/project/api/services" "gorm.io/gorm" ) Step 2: Define the CORS AllowOriginFunc Weโ€™ll define a function to specify the allowed origins for CORS. This function also logs disallowed origins: ...

2024-06-01 ยท map[name:Jose Castrillo]

Python & Virtual Environments

When starting a Python 3 project in Linux, itโ€™s essential to follow best practices to ensure a clean and isolated development environment. One of the recommended approaches is to utilize virtual environments. Virtual environments allow you to create an isolated environment for each project, preventing conflicts between different packages and dependencies. In this guide, weโ€™ll walk you through the steps to set up and activate a virtual environment for your Python 3 project. ...

2023-03-15 ยท map[name:Jose Castrillo]

Fixing tags on Azure invoices

Merging two CSV files using Pandas in Python 3 on Linux is a quick and easy process that can save you a lot of time and effort, however in my case I used other script to extract specific tag values from a CSV file, converts them into a JSON object, and writes them to a new CSV file, in that way I provided a workaround for those tags wanted. ...

2023-02-21 ยท map[name:Jose Castrillo]

Java Native Memory Tracking in GNU/linux

Java provides a Native Memory Tracking feature that enables you to monitor the memory usage of your Java application. This feature is particularly useful for identifying memory leaks and optimizing the memory usage of your application. In this post, we will discuss how to activate Native Memory Tracking for a Java jar application in Linux. Step 1: Check Java Version First, you need to check the version of Java installed on your system using the following command: ...

2023-01-10 ยท map[name:Jose Castrillo]

HelloWorld Solidity

Thisโ€™s my Hello World on Solidity: // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.6 < 0.9.0; contract TaskContract { uint nextId; struct Task { uint id; string name; string description; } Task[] tasks; function createTask (string memory _name, string memory _description) public { tasks.push(Task(nextId, _name, _description)); nextId++; } function findIndex(uint _id) internal view returns (uint) { for (uint i=0;i < tasks.length; i++){ if (tasks[i].id == _id){ return i; } } revert('Task not found'); } function readTask(uint _id) public view returns (uint, string memory, string memory) { // _id ---> variable local uint index = findIndex(_id); return (tasks[index].id, tasks[index].name, tasks[index].description); } function updateTask(uint _id, string memory _name, string memory _description) public { uint index = findIndex(_id); tasks[index].name = _name; tasks[index].description = _description; } function deleteTask(uint _id) public{ uint index =findIndex(_id); delete tasks[index]; } } Tutorial followed: Solidity SCRUD

SQL some concepts & notes

SQL Structured Query Language, is a language designed to allow both technical and non-technical users query, manipulate, and transform data from a relational database. Some popular SQL databases: SQLite MySQL Postgres Oracle Microsoft SQL Server Relational database: Represents a collection of related ( two-dimensional) tables.Each of the tables are similar to an Excel spreadsheet, with a fixed number of named columns and any number of rows of data. DDL (Data Definition Language) refers to the CREATE, ALTER and DROP statements DDL allows to add / modify / delete the logical structures which contain the data or which allow users to access / maintain the data (databases, tables, keys, viewsโ€ฆ). DDL is about โ€œmetadataโ€. DML (Data Manipulation Language) refers to the INSERT, UPDATE and DELETE statements DML allows to add / modify / delete data itself. DQL (Data Query Language) refers to the SELECT, SHOW and HELP statements (queries) SELECT is the main DQL instruction. It retrieves data you need. SHOW retrieves infos about the metadata. HELPโ€ฆ is for people who need help. DCL (Data Control Language) refers to the GRANT and REVOKE statements DCL is used to grant / revoke permissions on databases and their contents. DCL is simple, but MySQLโ€™s permissions are rather complex. DCL is about security. DTL (Data Transaction Language) refers to the START TRANSACTION, SAVEPOINT, COMMIT and ROLLBACK [TO SAVEPOINT] statements DTL is used to manage transactions (operations which include more instructions none of which can be executed if one of them fails). Some SQL queries: ...

2020-02-24 ยท map[name:Jose Castrillo]

Parsing date format from .xlsx to R

Version: platform x86_64-redhat-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu version.string R version 3.5.3 (2019-03-11) Library lubridate Parse method โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€” as.factor โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€” mydata$FECHA_NACIMIENTO<-as.factor(mydata$FECHA_NACIMIENTO) โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€” variable for strptime โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€” tempo<-strptime(mydata$FECHA_NACIMIENTO,"%d/%m/%Y") mydata$FECHA_NACIMIENTO<-as.Date(tempo,"%d/%m/%Y") โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€” clean variable โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€” rm (tempo) mydata$FECHA_NACIMIENTO <- format(as.Date(mydata$FECHA_NACIMIENTO), "%d/%m/%Y") โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€” parsing data โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€” library(lubridate) mydata$FECHA_NACIMIENTO <-dmy(mydata$FECHA_NACIMIENTO)

2019-04-01 ยท map[name:Jose Castrillo]