Skip to content

Instantly share code, notes, and snippets.

View mguilherme's full-sized avatar
🎯
Focusing

Miguel Guilherme mguilherme

🎯
Focusing
View GitHub Profile
@mguilherme
mguilherme / OrderApp.kt
Last active March 5, 2021 09:30
Polymorphic example with jsonb
package com.example
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.vladmihalcea.hibernate.type.json.JsonBinaryType
import org.hibernate.annotations.Type
import org.hibernate.annotations.TypeDef
import org.springframework.boot.CommandLineRunner
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
@mguilherme
mguilherme / app.ts
Last active December 25, 2020 23:02
Worten PS5 availability
import {DOMParser} from 'https://deno.land/x/deno_dom/deno-dom-wasm.ts';
import {brightBlue, brightGreen, brightRed, brightYellow} from 'https://deno.land/std/fmt/colors.ts';
const url = 'https://www.worten.pt/gaming/playstation/consolas/ps5/consola-ps5-825gb-7196053';
try {
const res = await fetch(url);
const html = await res.text();
const doc: any = new DOMParser().parseFromString(html, 'text/html');
@mguilherme
mguilherme / ArchUnitRulesTest.kt
Last active February 27, 2021 16:57
ArchUnit Examples
// build.gradle.kts
// testImplementation("com.tngtech.archunit:archunit-junit5-engine:0.17.0")
@AnalyzeClasses(packages = ["my.awesome.package"])
class GeneralCodingRulesTest {
@ArchTest
val `no classes should throw generic exceptions` = NO_CLASSES_SHOULD_THROW_GENERIC_EXCEPTIONS
@ArchTest
/*
plugins {
...
kotlin("plugin.serialization") version "1.4.10"
}
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.0.0")
@mguilherme
mguilherme / aws-mfa.py
Last active February 6, 2020 10:23
Automate the AWS MFA code when running an AWS command
# $ pip3 install pexpect
# $ pip3 install pyotp
import os
import sys
import pexpect
import pyotp
os.environ['AWS_DEFAULT_PROFILE'] = 'admin' # Change this if you have a different profile
version: '2'
services:
zookeeper:
image: wurstmeister/zookeeper:latest
ports:
- 2181:2181
kafka:
@mguilherme
mguilherme / postgres_table_size.sql
Last active July 23, 2018 13:15
Script to measure the size of Postgres Table row and Data page
WITH cteTableInfo AS
(
SELECT
COUNT(1) AS ct
,SUM(length(t::text)) AS TextLength
,'PUBLIC.MY_TABLE'::regclass AS TableName
FROM PUBLIC.MY_TABLE AS t
)
,cteRowSize AS
(
@mguilherme
mguilherme / application.yml
Last active May 17, 2021 03:54
spring boot 2 application.yml for oracle connection
spring:
jpa:
database-platform: org.hibernate.dialect.Oracle10gDialect
open-in-view: true
hibernate:
ddl-auto: none
# ddl-auto: create-drop
# ddl-auto: validate
datasource:
@mguilherme
mguilherme / Oracle_docker
Created July 15, 2018 22:54
Oracle XE with Docker
git clone [email protected]:oracle/docker-images.git
./buildDockerImage.sh -v 11.2.0.2 -x
docker run -d --name oracle -p 1521:1521 -p 5500:5500 -e ORACLE_PWD=mypassword --shm-size="2g" -v /opt/oracle/oradata:/opt/oracle/oradata oracle/database:11.2.0.2-xe
mvn install:install-file -Dfile=ojdbc8.jar -DgroupId=com.oracle.jdbc -DartifactId=ojdbc8 -Dversion=12.2.0.1 -Dpackaging=jar
@mguilherme
mguilherme / ProxyStatus.java
Last active June 24, 2018 21:12
Retrieves a status from a given code (match regex)
import java.util.Arrays;
import java.util.regex.Pattern;
/**
* Responsible for translating a given result code to a Proxy Status.
*
* @see <a href="https://sibs.docs.onlinepayments.pt/reference/resultCodes">Result Codes</a>
*/
public enum ProxyStatus {