Skip to content

Instantly share code, notes, and snippets.

View mattmills49's full-sized avatar

Matt Mills mattmills49

View GitHub Profile
@mattmills49
mattmills49 / display_hist.py
Last active February 26, 2024 07:16
A python function for printing a histogram as a unicode text string, e.g. '▁▂▄█▆▃▁▁'
import numpy as np
import functools as ft
def display_hist(x, num_bins = 8, zeros_as_blank = False):
'''Returns a histogram as a unicode text string, e.g. '▁▂▄█▆▃▁▁'
Inspired by the `precis` function from the Statistical Rethinking R package
by Richard McElreath. This function will calculate a histogram and then
returns a string displaying the histogram in unicode characters. It uses the
LOWER BLOCK group like "2584 ▄ LOWER HALF BLOCK".
@mattmills49
mattmills49 / golden_ratio_prize_payout.r
Last active March 13, 2017 18:55
golden ratio prize payout
prize_money <- function(places, entry_fee, members){
gold <- (1 + sqrt(5)) / 2
place_count <- function(prize_dist, places, place_counter){
if(place_counter == 1){
result <- place_count(c(1 - 1 / gold, 1/gold), places, place_counter + 1)
} else if(place_counter == places){
return(prize_dist)
} else {
result <- place_count(c(c(1 - 1 / gold, 1 / gold) * prize_dist[1], prize_dist[-1]), places, place_counter + 1)
}
library(devtools)
install_github("tiagomendesdantas/Rspotify")
library(Rspotify)
# https://github.com/tiagomendesdantas/Rspotify
keys <- spotifyOAuth(app_id = "Discover Mills", client_id = "1bf895600e3648b6bc3509f5df59c505", client_secret = "a2981db70b424244b14c2ff18e7b32e4")
user <- getUser("mattmills49", token = keys)
test <- httr::GET(paste0("https://api.spotify.com/v1/users/","mattmills49"), httr::config(token = keys))
json1 <- httr::content(test)
test <- getPlaylist(name = "mattmills49", offset = 0, token = keys)