Skip to content

Instantly share code, notes, and snippets.

View gongcastro's full-sized avatar
👁️

Gonzalo García-Castro gongcastro

👁️
View GitHub Profile
@gongcastro
gongcastro / randomization.py
Created September 3, 2025 12:03
Stimulus randomization and partial interleaving
from collections.abc import Sequence
from random import shuffle
from itertools import chain, pairwise
from warnings import warn
def has_consecutives(x: Sequence) -> bool:
"""Check if a sequence contains at least a pair of consecutive identical items.
Args:
@gongcastro
gongcastro / install-mbrola.sh
Created August 18, 2025 14:10
Install MBROLA
#! /bin/bash
# Get latest release info
REPO="numediart/MBROLA"
RELEASE=$(curl --silent "https://api.github.com/repos/${REPO}/releases/latest" | grep -Po "(?<=\"tag_name\": \").*(?=\")")
echo "Fetching latest MBROLA release $RELEASE"
# Check if MBROLA exists
DEST="/usr/bin/mbrola"
if [ -f "$DEST" ]; then
@gongcastro
gongcastro / logistic-coefs.R
Created December 23, 2022 16:28
Interpreting and playing with the coefficients of logit regression
library(ggplot2)
library(dplyr)
library(tidyr)
library(purrr)
library(scales)
library(patchwork)
theme_set(theme_minimal())
# define functions -------------------------------------------------------------
@gongcastro
gongcastro / roc-multinomial.R
Created November 10, 2022 11:53
ROC curves for multinomial and binomial Bayesian models in brms
library(dplyr) # for data wrangling
library(tidyr) # same
library(purrr) # for functional programming
library(rlang) # for tidyeval
library(ggplot2) # for dataviz
library(ggsci) # for nice colours
library(scales) # for displaying percentages
library(brms) # for Bayesian models
library(tidybayes) # for extracting posterior draws and predictions
library(yardstick) # for generating ROC curves
@gongcastro
gongcastro / pico-morse.py
Last active January 17, 2022 22:05
Code for translating character strings to ligh blinks implemented in RaspberryPi Pico. Adapted from @printnplay's code: https://www.instructables.com/Implementation-of-Morse-Code-Raspberry-Pi-Pico/.
from machine import Pin, PWM
from time import sleep
# Create a dictionary of Morse Code. s is for Short (or dots), l is for Long (or dashes)
MorseCodes = {
' ': '',
'a': 'sl',
'b': 'lsss',
'c': 'lsls',
'd': 'lss',
@gongcastro
gongcastro / CONTRIBUTING.md
Created November 16, 2021 16:10 — forked from briandk/CONTRIBUTING.md
A basic template for contributing guidelines that I adapted from Facebook's open source guidelines

Contributing to Transcriptase

We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:

  • Reporting a bug
  • Discussing the current state of the code
  • Submitting a fix
  • Proposing new features
  • Becoming a maintainer

We Develop with Github

# get audio duration
# set up ----
library(audio)
library(purrr)
library(dplyr)
library(tidyr)
library(ggplot2)
library(PraatR)
library(stringr)
# animate the Beta distribution
# parameter vectors
x = collect(0.01:0.01:0.99); # sampling space
α = collect(0.1:0.1:10);
β = collect(0.1:0.1:10);
# only β=5 is used, but I don't want to mess up the code
# extract probability densities for all combinations of parameters
y = zeros(length(x), length(α), length(β)); # pre-alocate
@gongcastro
gongcastro / get_childes_frequencies.R
Created July 7, 2021 09:02
Custom function to extract lexical frequencies from the CHILDES corpora.
# extract lexical frequencies from CHILDES
# you may need to install the following packages:
# install.packages(c("dplyr", "stringr", "tidyr", "chidesr"))
get_childes_frequency <- function(
token, # word(s) form to look up, e.g. c("table", "mesa")
languages = c("cat", "spa"), # languages in which to look up the word form
... # other arguments (see ?childesr::get_speaker_statistics)
){
@gongcastro
gongcastro / polynomials.R
Last active January 21, 2021 15:08
Wrappers to generate the data, plots and animations for the post on polynomial regression.
#### 2020-10-17-visualising-polynomial-regression -----
#### set up -------------------------------------------
# load packages
library(tidyverse)
library(gganimate)
library(data.table)
library(magick)
library(here)