Skip to content

Instantly share code, notes, and snippets.

View etiennebr's full-sized avatar

Etienne B. Racine etiennebr

  • Intact Lab
  • Montreal
View GitHub Profile
@etiennebr
etiennebr / useful-alias-git.md
Created January 8, 2021 14:08
Useful fit aliases

Useful git aliases

From git book

Unstage

 git config --global alias.unstage 'reset HEAD --'

Last

@etiennebr
etiennebr / tmux.conf
Last active August 8, 2023 12:11 — forked from spicycode/tmux.conf
The best and greatest tmux.conf ever
# set -g mouse-resize-pane on
# Use Alt-arrow keys without prefix key to switch panes
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
# Shift arrow to switch windows
bind -n S-Left previous-window
# install.packages(c("tidyverse",
# "devtools",
# "testthat",
# "usethis",
# "reprex",
# "covr",
# "lintr",
# "styler",
# "fs",
# "lookup",
@etiennebr
etiennebr / local-travis-ci.sh
Created February 14, 2018 15:57
Run travis-ci locally using R-base docker image
# adapted from: https://stackoverflow.com/a/41935867/171659
# choose the image according to the language chosen in .travis.yml
mkdir -p "$PWD":/home/docker
docker run -ti --rm -v "$PWD":/home/docker -w /home/docker -u docker r-base /bin/bash
# now that you are in the docker image, switch to the travis user
sudo - travis
apt-get install ruby
@etiennebr
etiennebr / .psqlrc
Last active February 23, 2023 11:09
psql defaults
-- Adapted from http://www.craigkerstiens.com/2015/12/29/my-postgres-top-10-for-2016/
\set QUIET 1
\pset null '¤'
-- Customize prompts
\set PROMPT1 '%[%033[1;34m%][%M %n@%/] # %[%033[0m%]%'
\set PROMPT2 '... # '
-- Show how long each query takes to execute
\timing
@etiennebr
etiennebr / sf-dplyr-style.R
Created December 21, 2016 22:45
sf in dplyr style
# dplyr style
polygons %>%
mutate(value = raster::extract.sfg(geometry, r, mean)) %>%
plot()
# sp style
value = raster::extract(polygons, r, mean, df = TRUE)
# multiple values
md <- function(x) data.frame(m = mean(x), d = sd(x)
#' Multivariate mutate
#' Mutate multiple columns
#'
#' @param .df A tbl
#' @param ... Name-value pairs of expressions that return one or more columns with 1 or nrow(.df) observations
#' @param .dots A list of formulas used to work around non-standard evaluation.
#' @export
#' @aliases mutatem_
#' @examples
#' df <- tibble(x=1:5, y=5:1)
@etiennebr
etiennebr / calendar.R
Last active April 11, 2016 13:14
Create calendar (can be used to plot calendars with ggplot2)
first_day_in_month = function(x) {
day(x) = 1
hour(x) = 0
minute(x) = 0
second(x) = 0
return(x)
}
first_day_in_year = function(x) {
month(x) = 1
@etiennebr
etiennebr / zipack.R
Last active April 1, 2016 16:55
R - Pack multiple files in a zip
#' Pack multiple files in a zip
#'
#' @export
#' @param fz Complete zip filename and path
#' @param fs Named List. Names are files names and content to be passed to FUN
#' @param FUN Function for writing to disc (defautl write.csv). Has to accept content as
#' first argument and file name as second. Other arguments are passed using ...
#' @param temp.dir Temporary directory to write files and zip. Is appened to file names
#' if not NULL.
#' @param flags A character string of flags to be passed to the command. Defaults is \code{-r9Xj}
@etiennebr
etiennebr / rowcol-raster.sql
Last active February 26, 2016 20:46
Build a multiband raster from row-col data
DROP SCHEMA test CASCADE;
CREATE SCHEMA test;
CREATE TABLE test.measure AS
SELECT
r as rowy, c as colx, b as band,
round(random() * 100)::float as v
FROM
generate_series(1, 6) as r
CROSS JOIN LATERAL