## Minimum Distance between a Point and a Line

This has been transcribed from an earlier post of the internet. I felt as though it might be good to rewrite and also include some of the information that is part of the This note describes the technique and gives the solution to finding the shortest distance from a point to a line or line segment. The equation of a line defined through two points \(P_1\) \((x1,y1)\) and \(P_2\) \((x2,y2)\) is...

February 20, 2021 · 3 min · 621 words · Chris Ried

## Using Analytics to Determine Ideal Hashtags for Instagram

library(stringr) library(readr) library(tidyverse) library(lubridate) I have been curious on what makes an interesting post on instagram based on a larger dataset of images that have been tagged with #generativeart. Some of this is just data discovery, this could seem that there may be a correlation between the tags that have been used and the amount of likes there are. # Extract hashtags patt <- regex("#\\S+") genart <- read_csv("~/InstaCrawlR/table-generativeart-2020-10-11 13:35:33.csv") genart_db <- genart %>% select(ID, Likes, Owner, Date, Text) %>% mutate(hashtags = str_extract_all(Text,patt) ) genart_db_table <- genart_db %>% unnest(cols = "hashtags") %>% mutate(Year = year(Date), Month = month(Date), DayOfWeek = wday(Date), Day = day(Date), Hour = hour(Date)) genart_db_table %>% head() That will generate a rather large dataset...

October 18, 2020 · 2 min · 422 words · Chris Ried

## Formatting Currencies in R

Here are a few ways to format numbers in R for presentations. A few of theme can be accomplished using the paste function in R. I’ve found that there are a few different methods to do this. Using the scales package Using the scales packages from Hadley, there is a great function with various options including passing a vector. library(scales) dollar_format()(c(-100, 0.23, 1.456565, 2e3)) Formatting currency with separator Following is a simple function one can build and place in their utility function that will give formatted currency....

August 21, 2018 · 1 min · 98 words · Chris Ried

## Phillips Hue in R

The following function can be used to find and display the internal IP address needed to retrieve the IP address from Hue Bridge. You will need to generate an API key i.e. a “userkey” as I called it below. getIP <- function() { url <- paste0("https://www.meethue.com/api/nupnp") res <- httpGET(url) resJson <- fromJSON(res) res <- resJson[["internalipaddress"]] res } In order to know what light you should change the state on, one can run the following to retrieve the available lights connected on the network....

August 7, 2018 · 1 min · 204 words · Chris Ried

## Simulate Doctor Visit Resource Planning Using Simmer

Here I’ve tried to come up with a simple layout on how we might simulate doctor’s visits. Following code tries to resource plan certain doctor visits based on the vignette that was provided with the simmer package. library(simmer) set.seed(42) env <- simmer("SuperDuperSim") env patient <- trajectory("patients' path") %>% ## add an intake activity seize("nurse", 1) %>% timeout(function() rnorm(1, 15)) %>% release("nurse", 1) %>% ## add a consultation activity seize("doctor", 1) %>% timeout(function() rnorm(1, 20)) %>% release("doctor", 1) %>% ## add a planning activity seize("administration", 1) %>% timeout(function() rnorm(1, 5)) %>% release("administration", 1) env %>% add_resource("nurse", 1) %>% add_resource("doctor", 2) %>% add_resource("administration", 1) %>% add_generator("patient", patient, function() rnorm(1, 10, 2)) env %>% run(80) %>% now() env %>% peek(3) env %>% stepn() %>% # 1 step print() %>% stepn(3) # 3 steps envs <- lapply(1:100, function(i) { simmer("SuperDuperSim") %>% add_resource("nurse", 1) %>% add_resource("doctor", 2) %>% add_resource("administration", 1) %>% add_generator("patient", patient, function() rnorm(1, 10, 2)) %>% run(80) }) envs %>% get_mon_resources() %>% head() envs %>% get_mon_arrivals() %>% head()

August 7, 2018 · 1 min · 165 words · Chris Ried

## Time and Difficulty

Sometimes, seeing data in a 3 dimensional space gives us better visibility to the rest of the world. You will see that we have taken a hypothetical experiment and tried to rate different ideas by their complexity and likelihood to succeed. #Libraries to import library(tidyverse) library(plotly) # Intellectual matrix idea <- c("Build a spaceship","Create a new social platform", "Build a birdhouse","Collect 10000 friends", "Clip toenails","Build a spaceship","Create a new social platform", "Build a birdhouse","Collect 10000 friends","Build a spaceship","Create a new social platform", "Build a birdhouse","Collect 10000 friends","Build a spaceship","Create a new social platform", "Build a birdhouse","Collect 10000 friends") time <- c(5,5,2,3,1,5,5,2,3,5,5,2,3,1,5,5,2) difficulty <- c(5,4,2,3,1,5,4,2,3,5,5,2,3,1,5,5,2) favorability <- c(2,5,2,1,3,4,1,2,1,2,5,2,1,3,3,1,2) #Creates the dataframe dataset <- data....

August 7, 2018 · 1 min · 173 words · Chris Ried

## Minature Generative Art

Sometimes something simple can turn out to generate the most beautiful things. Following you will find a few lines of code that present a beautiful pattern. library(ggplot2) library(dplyr) Oval Curve n <- 300 t1 <- 1:n t0 <- seq(3,2*n+1,2) %% n t2 <- t0 + (t0 == 0)*n df <- data.frame(x = cos((t1-1)*2*pi/n), y = sin((t1-1)*2*pi/n), x2 = cos((t2-1)*2*pi/n), y2 = sin((t2-1)*2*pi/n)) ggplot(df,aes(x,y,xend = x2,yend = y2)) + geom_segment(alpha = ....

January 8, 2018 · 1 min · 94 words · CRied

## Extracting Hyperlinks from an XSLX in R

In Progress install.packages("keras") library(keras) devtools::install_github("omarwagih/ggseqlogo") devtools::install_github("leonjessen/PepTools")

January 4, 2018 · 1 min · 6 words · CRied

## Human Ingenuity and Speed

library(tidyverse) Data Building The first thing we need to understand is where we have come and where we are going. There is alot that has been done in the past couple years but we still have more. type <- c("Sound","Light","Human Travel") units <- c("mps","mps","mps") speed <- c(343,299792458,11082.569) source <- c("","","") speed_data <- data.frame(type,units, speed,source) spd <- speed_data\$speed spd %*% (t(spd)) –TODO: The following 299792458/11082.57 Human History of Speed Speed hasn’t been a

December 23, 2017 · 1 min · 72 words · Chris

## Words With Friends Musings

Words with Friends is a wonderful game full of #library(tidyverse) # IMport Data #filepath <- "~/Dropbox/Word Lists/WordsWithFriends/enable1-wwf-v4.0-wordlist.txt" #wwfList <- read_csv(filepath, col_names = FALSE) #wwfList %>% stringr::str('.ae.')

December 3, 2017 · 1 min · 26 words · Chris Ried