Skip to content

Instantly share code, notes, and snippets.

View Martins6's full-sized avatar
🚀
per aspera ad astra!

Adriel Martins Martins6

🚀
per aspera ad astra!
View GitHub Profile
@Martins6
Martins6 / Dockerfile_ShinyApp_renv
Last active October 4, 2020 00:41
Dockerfile for Shiny App with renv.lock to remake the environment automatically.
# get shiny serves plus tidyverse packages image
FROM rocker/shiny-verse:latest
# system libraries of general use
RUN apt-get update && apt-get install -y \
sudo \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev \
@Martins6
Martins6 / Capture_show_query_dplyr.R
Created August 5, 2020 16:52
How to capture the output of the show_query. Modification of the answer from https://stackoverflow.com/questions/46002597/how-to-catch-a-dplyr-query-in-a-string.
# Capture
output <- capture.output(q1 %>% show_query())
# Concatenate character vector to a one length character vector
final_output <- paste(tail(output, -1), collapse=" ")
final_output
@Martins6
Martins6 / installing_tinytex_dependencies_Rnw.R
Last active October 4, 2020 00:39
When you compile a document to PDF through TinyTex LaTex, you may run into errors, especially with the .Rnw files and .tex. This is a script that automatically uses TinyTex to install the missing dependencies to compile an Rnw file..
library(tidyverse)
knitr::knit2pdf('path\to\file.Rnw')
file_log <- read_file('path\to\file.log')
error_text <-
file_log %>%
stringr::str_split('\n') %>%
unlist %>%
# Non Parametric Bootstrap Bias Correction and Confidence Interval
# Creating the Bootstrap Functions
bootstrap <- function(df, sample_prop = 1, B, stat_fun){
"Perfom a bootstrap with B samples applying the stat_fun for
calculating the Theta statistic. The prop. of sample you take
each Bootstrap step from the data is sample_prop.
stat_fun must only take one argument: df.
import numpy as np
import matplotlib.pyplot as plt
from scipy.io import wavfile
samplerate, data = wavfile.read('Data/microphone-results.wav')
n = np.arange(len(data))
N = len(n)
fhat = np.fft.fft(data, N)
PSD = fhat * np.conj(fhat) / N
@Martins6
Martins6 / settings.json
Created April 19, 2021 15:35
VSCode settings created by @marpontes.
{
"python.pythonPath": "path/to/python",
"python.formatting.provider": "autopep8",
"python.formatting.blackPath": "venv/bin/black",
"python.linting.enabled": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.formatting.autopep8Args": [
"--max-line-length",
"80",
@Martins6
Martins6 / .update_upgrade.sh
Created May 13, 2021 20:33
To update, upgrade and log all the packages for your Debian-based distribution.
#!/bin/bash
file_path=/home/adriel_martins/.update_upgrade.log
echo "** TURN ** : $(date +%d-%m-%Y)" >> $file_path
apt update >> $file_path
apt upgrade -y >> $file_path
@Martins6
Martins6 / regex_cleaning_email_and_telephone_prestodb.sql
Last active June 21, 2021 17:02
Cleaning or validating emails and telephones numbers with RegEx with SQL in Presto DB. (Portuguese Version)
SELECT *,
CASE
WHEN e.email like '%_@_%_.__%'
AND NOT regexp_like(coalesce(trim(regexp_extract(e.email, '.+?(?=@)')), '$'),
'[^a-zA-Z0-9\._-\ã\õ\ẽ\é\ó\ú]')
THEN lower(e.email)
ELSE 'N/A'
END
) AS email,
CASE
@Martins6
Martins6 / multinomial_goodness_of_fit.py
Created November 18, 2022 13:09
Calculate the multinomial goodness of fit through Log Likelihood Ratio test statistic with the null distribution calculated via Monte Carlo simulation.
def multinomial_goodness_of_fit(
f_obs,
p_exp=None,
b=1000,
delta=0
) -> list:
"""
Calculate the multinomial goodness of fit through Log Likelihood Ratio test statistic with the
null distribution calculated via Monte Carlo simulation.
@Martins6
Martins6 / M2_Mac_Docker_RStudio.sh
Last active September 2, 2023 14:01
Shell script to run RStudio on Docker on a M2 Mac.
# Three main sources for this script:
# https://github.com/rocker-org/rocker-versioned2/issues/144
# https://jsta.github.io/r-docker-tutorial/02-Launching-Docker.html
# https://stackoverflow.com/questions/65456814/docker-apple-silicon-m1-preview-mysql-no-matching-manifest-for-linux-arm64-v8
# After running the script, access the RStudio on the address http://localhost:8787/
docker run --rm \
--platform linux/x86_64 \
-p 8787:8787 \