Skip to content

Instantly share code, notes, and snippets.

@danielarrais
danielarrais / automatic-setting-language-for-bluetooh-keyboard.md
Last active November 1, 2024 12:24
Tutorial: How to Automatically Switch Keyboard Layout When Your Bluetooth Device Connects

Tutorial: How to Automatically Switch Keyboard Layout When Your Bluetooth Device Connects

This guide will configure a udev rule to trigger a script that changes the keyboard layout when a specific Bluetooth device is connected.

Step 1: Get the MAC Address of the Bluetooth Device

To get the MAC address of your Bluetooth device:

  1. List paired devices:
@danielarrais
danielarrais / gist:1d05d8d344568cfe4d13f686b875842f
Created September 30, 2024 12:56
Dash to panel settings.md
[/]
animate-app-switch=true
animate-appicon-hover=false
animate-appicon-hover-animation-extent={'RIPPLE': 4, 'PLANK': 4, 'SIMPLE': 1}
appicon-margin=0
appicon-padding=7
available-monitors=[0]
dot-position='BOTTOM'
hotkeys-overlay-combo='TEMPORARILY'
leftbox-padding=-1
@danielarrais
danielarrais / compose.yml
Last active April 20, 2024 21:28
Import postgresql dumps on docker composer and create multiples databases
services:
postgres:
image: postgres:latest
environment:
- 'POSTGRES_DATABASES=database_1,database_2'
- 'POSTGRES_PASSWORD=password'
- 'POSTGRES_USER=postgres'
healthcheck:
test: exit $$DUMPS_IMPORTED # Use variable created on multiple-database.sh for checke if dumps were imported
interval: 5s
@danielarrais
danielarrais / setup_ubuntu.md
Last active September 30, 2024 12:28
setup zsh

Setup Linux:

Setup ZSH

  1. Install ZSH: sudo apt install zsh
  2. Intall Oh My ZSH: https://ohmyz.sh/#install
  3. Plugins:
    • git: default
    • zsh-autosuggestions: git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  • zsh-syntax-highlighting: git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
@danielarrais
danielarrais / replace-user-and-email-of-commits.sh
Created December 1, 2023 22:33
Replace email and user of all commits of my repository
git filter-branch --env-filter '
WRONG_EMAIL="wrong@example.com"
NEW_NAME="New Name Value"
NEW_EMAIL="correct@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ]
then
export GIT_COMMITTER_NAME="$NEW_NAME"
export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi
@danielarrais
danielarrais / article.md
Last active May 22, 2023 16:24
Artigo: Criando componentes do Rabbitmq de forma dinâmica no Spring Boot

Criando componentes do Rabbitmq de forma dinâmica no Spring Boot

Esses dias me deparei com o seguinte desafio: listar no properties de um projeto Spring Boot as filas que são utilizadas no projeto e criá-las no RabbitMQ de acordo com essa lista. Até então eu criava as filas uma a uma declarando uma @Bean (Exemplo 1) e assim toda vez que a aplicação é iniciada as devidas filas são criadas, caso já não existam. O problema aqui é a necessidade de alterar código toda vez que for necessário criar uma nova fila.

Exemplo 1

@Bean  
public Queue example1Queue() {  
// This code is JSR223 PreProcessor, it's changing post data replacing variable in POST DATA of request
String variableValue = vars.get("variableName");
String bodyData = sampler.getArguments().getArgument(0).getValue();
String newBodyData = bodyData.replace("variableName", variableValue);
sampler.getArguments().getArgument(0).setValue(newBodyData);
@danielarrais
danielarrais / Date.util.ts
Created May 30, 2021 22:15
Function for calculate age
static calculateAge(birthDate: Date) {
const today = new Date();
let age = today.getFullYear() - birthDate.getFullYear();
const month = today.getMonth() - birthDate.getMonth();
if (month < 0 || (month === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
return age;
@danielarrais
danielarrais / ZipUtils.java
Last active April 22, 2021 00:51
Zipping files and folders in Java
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@danielarrais
danielarrais / CustomBeansUtils.java
Last active January 22, 2021 22:26
Copy non-null properties from one object to another in Spring
import lombok.SneakyThrows;
import org.springframework.beans.BeanUtils;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
public class CustomBeansUtils extends BeanUtils {
public static <T> void copyNonNullValues(Object input, T output) {
var ignoreProperties = nullPropertiesFromObject(input);