Skip to content

Instantly share code, notes, and snippets.

@DavZim
DavZim / Readme.md
Last active February 13, 2020 09:08
Simple explanation how to use git-hooks to automatically deploy your code to production

How to Deploy git to a Server using git-hooks

The following script outlines how we can use git-hooks for continuous deployment (when you push your git repository, it will automatically be deployed to the server).

Note, this script is heavily based on but slightly extends this gist, see also this explanation.

Basic idea: using git-hooks to copy the files on a target machine from a remote git repository to a specific target location.

For this, we need multiple components:

  • On the target machine (the production server)
library(tidyverse) # for the plot only
# required librariers that need to be installed (not loaded!): quantmod, dplyr, tibble 
# (the latter two are in the tidyverse anyway)

#' Downloads stock data from yahoo finance etc. using quantmod::getSymbols
#' 
#' @param tickers a vector of tickers
#' @param from start date
#' @param to end date
@DavZim
DavZim / wahlleiter_data.md
Created May 28, 2019 13:27
Downloads the data from the Bundeswahlleiter and creates some quick plots
library(tidyverse) # for data manipulation
library(rvest)     # for web scraping of the bundeswahlleiter
library(GGally)    # for the correlelogram

#' Downloads the data from the Bundeswahlleiter
#' 
#' @param url the url to download, used internally only as the function calls itself recursively, the url is the url for the respective page,
#' i.e., https://www.bundeswahlleiter.de/europawahlen/2019/ergebnisse/bund-99/land-2.html or
#' https://www.bundeswahlleiter.de/europawahlen/2019/ergebnisse/bund-99/land-8/kreis-8435.html
library(imager)          # for loading and plotting of the PNG file
library(glue)            # for string parsing
library(png)             # alternative for image loading

take_screenshot <- function(file = "screenshot.png", force_imagemagick = FALSE) {
  
  if (Sys.info()[["sysname"]] == "Linux" && 
      as.numeric(system("cat /var/log/dpkg.log | grep scrot | wc -l", intern = TRUE)) > 0 &&
      !force_imagemagick) {
@DavZim
DavZim / colorTable Example
Created January 24, 2019 13:47
Julian.Rmd
``` r
library(tidyverse)
df <- data_frame(x = 1:3, y = c("A", "B", "C"))
df %>%
mutate(
new_y = case_when(
y == "A" ~ "Alice",
y == "B" ~ "Bob",
################################################################################
# Goal of this short script is to show the basic inner workings of the
# tidyAnimatedVerbs package.


library(tidyverse)
library(gganimate)

# load all functions from the tidyAnimatedVerbs package
power <- function(x, power) {
  return(x^power)
}

foo <- function(x, ...) {
  cat("You just called 'foo'\n")
  power(x, ...)
}
``` r
library(ggplot2) # data vis
library(dplyr) # data manipulation
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
# set parameters for the dataset
possible_values <- c(1:10, 99, NA)
n_rows <- 1000
n_cols <- 10
col_names <- letters[1:n_cols]
# create a matrix with the sampled data, that will be transformed into a data.frame in the next step
mwe_matrix <- matrix(sample(possible_values, n_rows * n_cols, replace = T),
nrow = n_rows, ncol = n_cols)
``` r
library(extrafont)
#> Registering fonts with R
# font_install('fontcm') # try this if its not working
suppressMessages(loadfonts())
# check that the LM Roman fonts are installed with
"CM Roman" %in% fonts()
#> [1] TRUE
# main script ============