Skip to content

Instantly share code, notes, and snippets.

View mgei's full-sized avatar

Martin Geissmann mgei

View GitHub Profile
@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))
@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"))
# 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 / 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)
}
@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),