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
@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 / 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 / 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"
)
> 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
> titanic_daisi <- Daisi("Titanic Statistics")
[1] "Looking for Daisi: Titanic Statistics"
[1] "https://app.daisi.io/pebble-api/daisies/connect?name=Titanic%20Statistics"
> titanic_execution <- titanic_daisi$raw(rows = 8)
> titanic_execution$value()
[1] "Fetching Result: c2395f17-44a6-459c-b17c-60e394bd4f3e"
PassengerId Sex Age SibSp Parch
1 1 male 22 1 0
2 2 female 38 1 0
> bert_daisi <- Daisi("Ask BERT")
[1] "Looking for Daisi: Ask BERT"
[1] "https://app.daisi.io/pebble-api/daisies/connect?name=Ask%20BERT"
> bert_execution <- bert_daisi$compute(context = "Daisi seamlessly integrates the immense power of cloud computing into the workspace of every data scientist. If you are writing data science, AI, or Machine Learning applications, contact us for a free sneak peak of Daisi – the cloud platform to deploy, share, and discover Python serverless functions.", query = "What are Daisies for?")
> bert_execution$value()
[1] "Fetching Result: 4715353b-9703-452d-82fa-88ca7af3fcbe"
[[1]]
[1] "to deploy, share, and discover Python serverless functions."
> gn_daisi <- Daisi("GoogleNews")
[1] "Looking for Daisi: GoogleNews"
[1] "https://app.daisi.io/pebble-api/daisies/connect?name=GoogleNews"
> gn_execution <- gn_daisi$get_news(query = "Apple", num = 6)
[1] "Executing Daisi: 4cc93acc-ac2d-4c3b-aeac-f67e96a5c658"
> gn_execution$value()[,1:3]
[1] "Fetching Result: b76e037a-7c7b-4c2f-8a22-cf561ca398aa"
title desc
@erichare
erichare / yolo_v6_pydaisi.py
Last active June 30, 2022 23:15
YOLO v6 Object Detection Implemented with Daisies
import pydaisi as pyd
from PIL import Image
yolo_object_detection = pyd.Daisi("erichare/YOLO v6 Object Detection")
img = Image.open("busystreet.png")
img.load()
yolo_result = yolo_object_detection.yolo(img, return_type=['Image']).value
@erichare
erichare / yolo_v6_daisi_sample.py
Created June 30, 2022 23:24
Sample of the YOLO v6 Daisi Code
def yolo(image: np.ndarray=None, return_type: list=["Image", "Labels"]):
...
inferer = Inferer(source, weights, device="", yaml="coco.yaml",
img_size=new_width, half=False)
inferer.infer(conf_thres=.25, iou_thres=.45, classes=None,
agnostic_nms=False, max_det=1000, save_dir=tmpdir,
save_txt=save_txt, save_img=save_img, hide_labels=False, hide_conf=False)
...
return yolo_result, label_result
@erichare
erichare / fit_pca.py
Created July 7, 2022 20:26
Fit a PCA using scikit-learn
def fit_pca(pca_data, x_component=1, y_component=2, split_by=None):
...
pca_df = df[vars]
pca = PCA(n_components=n_components)
pca.fit(pca_df)
...
pca_data = pd.DataFrame(pca.fit_transform(pca_df))