Skip to content

Instantly share code, notes, and snippets.

View necronet's full-sized avatar
👨‍💻
Hello old friend!

Jose Ayerdis necronet

👨‍💻
Hello old friend!
View GitHub Profile
@necronet
necronet / simulate_books_per_kids_school.R
Created February 16, 2023 21:28
Randomly simulate a matrix representing books per kids on school
# Generate 10 schools
schools <- 1:10
# Sample 100 books of 20 types
books <- sample(1:20, size = 100, replace=T)
books_per_school <- length(books) / length(schools)
# Kid in school
kids_in_school <- rbinom(100, size = length(schools), prob = 0.5)
#hist(kids_in_school)
@necronet
necronet / statistical_rethininking_fig8_4.R
Created December 11, 2022 18:33
Plotting the africa and non africa model on GDP and road ruggeness. Chapter on "Coditional Manaies"
## Assuming we already have the model describe on page 246 - 247
## Here is a possible way to get the graph describe on figure 8.5 from Statistical Rethinking Figure 8.4
plot(NULL, xlim=c(0,1), ylim=c(0.5, 1.5), xlab="rudgeness", ylab="gdp log std")
points(dd$rugged_std[dd$cont_africa==1], dd$log_gdp_std[dd$cont_africa==1], col="blue")
points(dd$rugged_std[!dd$cont_africa], dd$log_gdp_std[!dd$cont_africa], col="black")
lines(rudge_seq, mu.NotAfrica_mu)
shade(mu.NotAfrica_ci, rudge_seq)
@necronet
necronet / KL-divergence.R
Created December 5, 2022 01:23
Understanding KL divergence as explained on statistical rethinking from Prof Mcelreath
p <- c(0.3, 0.7 )
N = 1000
qs <- cbind( seq(0, 1, length.out = N), seq(1, 0, length.out = N) )
kldivergence <- function(q1, q2) {p <- c(0.3, 0.7 ); sum( p*log(p/c(q1,q2)))}
kldivergence_results <- mapply(kldivergence, qs[,1], qs[,2])
plot(qs[,1], kldivergence_results, pch=20, col='blue')
@necronet
necronet / Metropolis-King-Example.R
Created August 5, 2022 20:07
Statistical Rethinking example for MCMC
num_weeks <- 1e5
position <- rep(0, num_weeks)
current <- 10
for (i in 1:num_weeks) {
position[i] <- current
proposal <- current + sample( c(-1, 1), size = 1)
if (proposal < 1) proposal <- 10
if (proposal > 10) proposal <- 1
prob_move <- proposal/current
@necronet
necronet / open_pr_by_commit.sh
Created March 31, 2021 00:01
Open PR for a specific commit
# Get PR number for a specific commit
local pr_number=$(git log --reverse --ancestry-path <commit_id>..master --grep="Merge pull request" --oneline | head -n 1 | awk '{print $5}' | sed -E 's/#//g')
# Open PR in the browser
open "https://github.tumblr.net/TumblrMobile/android2/pull/$pr_number"
@necronet
necronet / getMergedManifest.sh
Created March 30, 2021 23:56
Get Merged Manifest android and copy to clipboard
cat <module_name>/build/intermediates/merged_manifest/celrayDebug/out/AndroidManifest.xml | pbcopy
@necronet
necronet / aws_dynamo_101.sh
Created January 2, 2021 23:58
An easy example of some aws console operation for dynamodb
# List all the tables using a profile
aws dynamodb list-tables --profile <profile_name> | jq
# Get all item in a table using a profile (expensive)
aws dynamodb scan --table-name <table_name> --profile <profile_name> | jq
# Get an specific item based on id using a profile
aws dynamodb get-item --key '{"id":{"S":"009871"}}' --table-name <table_name> --profile <profile_name> | jq
# Create an item using a profile
@necronet
necronet / residual.R
Created July 13, 2020 04:05
Find the largest residual of 2 digits number that can be divided by the sum of itself
# Find the largest residual of 2 digits number that can be divided by the sum of itself
# maxres(ab/(a+b))
library(tidyr)
count <- 0
max_index <- 0
for( i in 10:99) {
digits <- as.integer(substring(i, seq(nchar(i)), seq(nchar(i))))
aplusb <- digits[1] + digits[2]
@necronet
necronet / variation.R
Created July 4, 2020 02:53
Get all numbers 3 digits, divisible by 3 that follow this formula, a + 3b + c where a != 0
# Get all numbers 3 digits, divisible by 3 that follow this formula
# a + 3b + c where a != 0
library(tidyr)
count <- 0
n <- c()
for( i in 100:999) {
digits <- as.integer(substring(i, seq(nchar(i)), seq(nchar(i))))
formula <- (digits[1] + 3*digits[2] + digits[3])
@necronet
necronet / ptf_data_extraction.R
Last active June 27, 2020 21:56
Quickly filtering data for PTF
library(readr)
library(skimr)
library(dplyr)
library(stringr)
data <- readr::read_csv('data.csv')
skimr::skim(data)
data_cleaned <- data %>% filter(!stringr::str_detect(Page, "@powertofly\\.com")) %>%
mutate(Registrations =