Skip to content

Instantly share code, notes, and snippets.

View erictleung's full-sized avatar
👨‍💻
Data sciencing

Eric Leung erictleung

👨‍💻
Data sciencing
View GitHub Profile
@erictleung
erictleung / update_git.sh
Created July 26, 2021 05:31
Update local git repository from master to main branch on upstream
# Sources:
# - https://www.git-tower.com/learn/git/faq/git-rename-master-to-main/
# - https://gist.github.com/kelynch/9ba595e369c304b560477f3636b41e8a
git checkout master # Assumes master is default branch
git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a
@erictleung
erictleung / xaringan_outliner.R
Created July 18, 2021 21:59
Generate outline for {xaringan} presentations
# Load relevant packages
library(purrr)
library(stringr)
library(glue)
#' Programmatically generate xaringan outline
#'
#' @param file string name of generated xaringan RMarkdown
#' @param ... list of objects containing the structure for the presentation
@erictleung
erictleung / card.R
Last active March 13, 2021 23:58
R Business Card
library(magrittr)
library(tibble)
library(cli)
#' Business Card
#'
#' @return None
#' @export
#'
#' @examples
@erictleung
erictleung / do.py
Created January 9, 2021 05:29
Apply expression on each side of SymPy expression
# Source:
# https://github.com/sympy/sympy/issues/5031#issuecomment-36996878
def do(self, e, i=None, doit=False):
"""Return a new Eq using function given or a model
model expression in which a variable represents each
side of the expression.
Examples
========
@erictleung
erictleung / default_tbls.vba
Created November 24, 2020 19:27
Automate table formatting in Microsoft Word
' Inspired by
' https://github.com/jgm/pandoc/issues/3275#issuecomment-448262352
Sub TableDefaultOptions()
Dim tbl As Table
For Each tbl In ActiveDocument.Tables
tbl.Style = wdStyleTableLightGridAccent1
tbl.ApplyStyleFirstColumn = False
tbl.ApplyStyleLastColumn = False
tbl.ApplyStyleLastRow = False
tbl.ApplyStyleRowBands = True
@erictleung
erictleung / corr_plots.R
Last active April 8, 2021 20:38
Plot examples of varying strengths of correlation
# Load libraries
library(ggplot2)
library(patchwork)
set.seed(20200616)
# Create data
n_pts <- 20
x <- round(runif(n_pts) * 10, 1)
@erictleung
erictleung / keybase.md
Created March 11, 2020 21:03
Keybase info

Keybase proof

I hereby claim:

  • I am erictleung on github.
  • I am erictleung (https://keybase.io/erictleung) on keybase.
  • I have a public key ASDKGm3xXcbmyZTmIskKJlfja4ZDDyGRsf3oQe2hHjbt9wo

To claim this, I am signing this object:

@erictleung
erictleung / README.md
Last active January 9, 2020 22:17
Setup DADA2 R environment with Anaconda

Anaconda Setup on Exacloud

  1. SSH into Exacloud

  2. Visit Conda website https://docs.conda.io/en/latest/miniconda.html

  3. Copy link to installer

    # Go to home directory and download install script
    cd
    wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
@erictleung
erictleung / find_low_activity_twitter_accts.R
Last active March 16, 2022 06:48
Identify accounts on Twitter that you follow that do not tweet frequently or are just inactive
# Script to identify Twitter accounts that have not tweeted in a while or just
# infrequent.
# Modified from:
# https://twitter.com/tomstafford/status/1160553156633174017
# Load libraries
library(rtweet)
library(dplyr)
# Set variables
@erictleung
erictleung / eapply_example.R
Created February 15, 2019 16:47
Example of eapply()
> a <- 1:10
> beta <- exp(-3:3)
> logic <- c(T, F, F, T)
> eapply(env = globalenv(), mean)
# $`a`
# [1] 5.5
#
# $logic
# [1] 0.5
#