Skip to content

Instantly share code, notes, and snippets.

View erichare's full-sized avatar
🏠
Working from home

Eric Hare erichare

🏠
Working from home
View GitHub Profile
> d <- Daisi("Add Two Numbers")
[1] "Looking for Daisi: Add Two Numbers"
[1] "https://app.daisi.io/pebble-api/daisies/connect?name=Add%20Two%20Numbers"
> de <- d$compute(firstNumber = 5, secondNumber = 6)
[1] "Executing Daisi: 0a688b9a-49f7-42e9-8bab-5091b871f1a8"
> de$value()
[1] "Fetching Result: fa68ea3c-e73a-468e-8d51-a1f4ab824165"
[1] 11
@erichare
erichare / carbon_api.R
Created October 21, 2021 20:17
Use Unofficial Carbon API to Generate Image of Code
library(httr)
my_code <- paste(readLines("Downloads/text.R"), collapse = "%250A")
params <- list(
backgroundColor = "rgba(100, 20, 250, 100)",
code = my_code,
theme = "dracula",
exportSize = "3x"
)
@erichare
erichare / coingecko_api.py
Created September 10, 2021 20:35
Iteratively pull coin data from CoinGecko
import requests
import time
import pandas as pd
# Get the list of coins from the API
r = requests.get("https://api.coingecko.com/api/v3/coins/list")
coin_list = r.json()
# Get all the ids
coin_ids = [x["id"] for x in coin_list]
@erichare
erichare / live_logging_app.R
Created July 29, 2021 22:17
Asynchronous Live Logging in a Shiny Application
library(shiny)
library(shinythemes)
library(future)
library(promises)
library(tidyverse)
library(ipc)
library(future.callr)
plan(callr)
@erichare
erichare / investment_curve.R
Created December 8, 2020 15:07
Digitizing the investment curve
library(tidyverse)
library(ggrepel)
ln <- read_csv("Investment_Bubble_Cycle_Line.csv") %>%
mutate(Y = Y + 50 + 28)
cv <- read_csv("Investment_Bubble_Cycle.csv") %>%
mutate(Y = Y + 50)
mapping = tibble(
X = cv$X[c(20, 50, 70, 75, 105, 125, 138, 150, 175, 165, 185, 208, 225, 255, 280)],
@erichare
erichare / scales.R
Last active November 25, 2019 15:18
Some new features in the scales 1.1 release
library(ggplot2)
ggplot(data = diamonds, aes(x = carat, y = price, colour = clarity)) +
geom_point() +
scale_y_continuous(labels = scales::dollar,
breaks = scales::breaks_width(2000)) +
scale_x_continuous(breaks = scales::breaks_width(.5))
ggplot(data = diamonds, aes(x = carat, y = price, colour = clarity)) +
geom_point() +
@erichare
erichare / clean.R
Created August 26, 2019 18:42
clean.R
library(tidyverse)
library(clean)
unclean_tbl <- tibble(
Logical = c("Yes", "No", "Depends", "Unknown"),
Factor = c("bachelor's", "Bachelor's Degree", "Master's Degree", "PhD"),
Currency = c("$20", "$ 25", "26.02", "$27.0"),
Numeric = c("~15", "about 10", "20", "15")
)
@erichare
erichare / fable.R
Created July 17, 2019 13:26
Sample code to forecast Air Passengers using the Fable package
library(tidyverse)
library(fable)
fable_series <- AirPassengers %>%
as_tsibble() %>%
model(
ets = ETS(box_cox(value, 0.3)),
arima = ARIMA(value),
snaive = SNAIVE(value)
) %>%
library(magick)
library(tidyverse)
im <- image_read("line.jpg")
im_proc <- im %>%
image_channel("saturation") %>%
image_threshold("white", "30%") %>%
image_negate()
@erichare
erichare / droste.R
Created June 17, 2019 17:47
Drawing a Droste Effect Polygon with ggplot2 3.2.0
library(tidyverse)
polygon_values <- tibble(
id = 1:2,
value = c(-2, 2)
)
polygon_positions <- tibble(
id = c(1, 1, 1, 2, 2, 2, 2),
x = c(1, 2, 3, 5, 6, 7, 6),