Skip to content

Instantly share code, notes, and snippets.

View mgei's full-sized avatar

Martin Geissmann mgei

View GitHub Profile
@mgei
mgei / fake_addresses
Created January 14, 2019 18:00
fake addresses with realistic locations
library(tidyverse)
library(lubridate)
library(leaflet)
# https://www.fakenamegenerator.com/order.php
# go there to generate fake addresses, don't forget to select to include longitude and latitude
addresses <- read_csv("FakeNameGenerator.com_f201506b.csv")
addresses <- addresses %>% mutate(Birthday = mdy(Birthday),
@mgei
mgei / financial_taccount_ggplot
Created January 16, 2019 08:42
Create a T-account plot for a balance sheet or income statement using ggplot2 in R
library(tidyverse)
library(scales)
scrapy_stocks <- function(stock){
if ("rvest" %in% installed.packages()) {
library(rvest)
}else{
install.packages("rvest")
library(rvest)
}
# to install the latest version 0.53 of Hugo on Ubuntu:
# releases are here: https://github.com/gohugoio/hugo/releases
export VER="0.55.5"
wget https://github.com/gohugoio/hugo/releases/download/v0.55.5/hugo_${VER}_Linux-64bit.deb
sudo dpkg -i hugo_${VER}_Linux-64bit.deb
# check if right version is installed
hugo version
# make a new website (don't do that if you already have one)
@mgei
mgei / open_closing_hours.R
Created February 21, 2019 10:24
R create tibble for open close hours to be used for timevis with type = "range"
library(tidyverse)
library(lubridate)
days <- tibble(date = seq(date("2018-01-01"), by = "days", length.out = 730)) %>%
mutate(day = weekdays(date))
hours <- tibble(daytype = c("weekday", "weekday", "weekday", "weekday", "weekday", "weekend"),
time_from = c("00:00", "08:00", "12:00", "13:00", "17:00", "00:00" ),
time_to = c("08:00", "12:00", "13:00", "17:00", "23:59", "23:59" ),
state = c("closed", "open", "closed", "open", "closed", "closed"))
@mgei
mgei / localurl.R
Created April 2, 2019 10:27
R function to build a local URL for RMarkdown
library(tidyverse)
localurl <- function(document, path = ""){
path <- str_remove_all(path, "/$|^/")
document <- str_remove_all(document, "/$|^/")
path <- file.path(path, document) %>%
str_remove_all("/$|^/")
document <- last(str_split(path, pattern = "/", simplify = T))

What I've done thus far

Install QMKL

But before:

Install Py-videocore

Increase video memory!

library(shiny)
library(tidyverse)
# data <- readRDS("persistent_data/data.RDS")
data <- as_tibble(mtcars) %>% head()
ui <- fluidPage(
tableOutput("mytable"),
actionButton("go", "filter it"),
actionButton("save", "save it")
@mgei
mgei / letf.R
Created January 17, 2020 10:43
leveraged etf compounding performance lag
library(tidyverse)
library(ggplot2)
periods <- 10
trend <- 0
vola <- 0.1
leverage <- 2
@mgei
mgei / app.R
Created February 24, 2020 15:14
persistent data storage of user input in R Shiny
library(shiny)
library(shinyWidgets)
library(tidyverse)
# read persistent data or create a new file if it does not exist yet
if ("favs.csv" %in% list.files()) {
favs <- read_file("favs.csv") %>%
strsplit(", ") %>%
.[[1]] %>%
as.numeric() %>%