Skip to content

Instantly share code, notes, and snippets.

View trinker's full-sized avatar

Tyler Rinker trinker

View GitHub Profile
@trinker
trinker / spec.json
Created May 30, 2024 14:52
Vega-Lite spec from Thu May 30 2024
{
"width": 600,
"data": {
"values": [
{
"__row__": 0,
"calendar_month_year": "Dec-23",
"concentration_risk_monthly": 0.8
},
{
@trinker
trinker / spec.json
Created May 30, 2024 03:06
Vega-Lite spec from Wed May 29 2024
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"width": 600,
"data": {
"values": [
{
"__row__": 0,
"calendar_month_year": "Dec-23",
"concentration_risk_monthly": 0.51
},
@trinker
trinker / look_and_say_sequence.R
Last active September 15, 2022 15:35
look and say sequence
# https://mathworld.wolfram.com/LookandSaySequence.html
library(ggplot2)
library(stringi)
tic <- Sys.time()
len <- 68
s <- rep(NA, len)
s[1] <- 1
tm <- rep(NA, len)
prob <- unlist(lapply(1:1000000, function(i){
candles <- sort(runif(2, 0, 1))
cut <- runif(1, 0, 1)
(cut > candles[1]) & (cut < candles[2])
}))
mean(prob)
## https://youtu.be/094y1Z2wpJg
library(tidyverse)
collatz <- function(x){
v = c(x)
i = 1
while (v[i] != 1){
@trinker
trinker / fgsub.py
Last active March 29, 2021 19:02
textread fgsub equivalent in python
text = ['df dft sdf', 'sd fdggg sd dfhhh d', 'ddd']
def dbllttrwordrev(match):
match = match.group()
return '<<{}>>'.format(match[::-1])
{
'function': [re.sub("\\b\\w*([a-z])(\\1{2,})\\w*\\b", dbllttrwordrev, x, flags = re.IGNORECASE) for x in text],
'lambda': [re.sub("\\b\\w*([a-z])(\\1{2,})\\w*\\b", lambda x: '<<{}>>'.format(x.group()[::-1]) , x, flags = re.IGNORECASE) for x in text]
@trinker
trinker / quanteda_wordcloud.R
Created July 8, 2020 19:11
Wordcloud with quanteda
## Load dependencies
library(quanteda)
library(sentimentr)
library(tidyverse)
library(lexicon)
## Data set from sentimentr package
dat <- presidential_debates_2012
dat
corp <- corpus(dat, text_field = "dialogue")
@trinker
trinker / gist:a75144f8d90738a169dc4c99f4ad3717
Last active March 24, 2020 18:18
Norah's Phoneme Question
## Norah's Question: Are there any words that start with chr (phoenetically /k/ /r/) that don't have a a short i sound following it?
library(openssl)
library(textshape)
library(tidyverse)
cmudict <- readLines('https://raw.githubusercontent.com/michelleful/ToBoldlyStress/master/stressed_spelling.txt')
cmudict7b <- readLines('http://svn.code.sf.net/p/cmusphinx/code/trunk/cmudict/cmudict-0.7b') %>% tail(-121) %>% head(-4)
@trinker
trinker / rowwise_subsets.R
Created September 9, 2019 16:39
Rowwise subsets in dplyr
library(dplyr)
dat <- tibble(
x1=c(1,0,0,NA,0,1,1,NA,0,1),
x2=c(1,1,NA,1,1,0,NA,NA,0,1),
x3=c(0,1,0,1,1,0,NA,NA,0,1),
y4=c(1,0,NA,1,0,0,NA,0,0,1),
y5=c(1,1,NA,1,1,1,NA,1,0,1),
z = LETTERS[1:10]
)
library(tidyverse)
library(gridExtra)
plot1 <- ggplot(mtcars, aes(x = hp)) +
geom_histogram(bins = 10) +
labs(
y = 'Count of Awesomeness',
title = 'Count Histogram'
)