Skip to content

Instantly share code, notes, and snippets.

View kguidonimartins's full-sized avatar

Karlo Guidoni kguidonimartins

View GitHub Profile
@yegappan
yegappan / VimScriptForPythonDevelopers.MD
Last active January 12, 2024 10:51
Vim script for Python Developers

Vim Script for Python Developers

This is a guide to Vim Script development for Python developers. Sample code for the various expressions, statements, functions and programming constructs is shown in both Python and Vim Script. This is not intended to be a tutorial for developing Vim scripts. It is assumed that the reader is familiar with Python programming.

For an introduction to Vim Script development, refer to usr_41.txt, eval.txt and Learn Vimscript the Hard Way

For a guide similar to this one for JavaScript developers, refer to Vim Script for the JavaScripter

This guide only describes the programming constructs that are present in both Python and Vim. The constructs that are unique to Vim (e.g. autocommands, [key-mapping](https://vimhelp.org/map.txt.html#key-m

@noamross
noamross / criticmarkup.lua
Last active August 30, 2023 12:08
A pandoc filter for MS Word track changes to criticmarkup
-- a lua filter for panodoc
-- run pandoc your_word_doc.docx --track-change=all -t markdown --lua-filter=criticmarkup.lua
-- TODO: Detect substitutions in adjacent insertion/deletions
-- TODO: capture whole comment hightlight rather than just start point of comment
function Span(elem)
if elem.classes[1] and elem.classes[1] == "insertion" then
local opener = { pandoc.RawInline(FORMAT, "{++ ") }
local closer = { pandoc.RawInline(FORMAT, " ++}") }
return opener .. elem.content .. closer
elseif
@MaximeWack
MaximeWack / rmdtags.py
Created September 30, 2018 21:26
Tag generator for Rmarkdown files
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
help_text = """
Extracts tags from rmd files. Useful for the Tagbar plugin.
Usage:
Install Tagbar (http://majutsushi.github.io/tagbar/). Then, put this file
@Pakillo
Pakillo / repromap.R
Last active March 21, 2018 19:01
another reproducible map with Rstats
library(sf)
library(ggspatial)
library(ggthemes)
coast <- rnaturalearth::ne_coastline(scale = "small", returnclass = "sp")
forests <- st_read("data/forestmap/cfc_gen.shp")
forest.redux <- rmapshaper::ms_simplify(forests)
forest.redux.sp <- as(forest.redux, "Spatial")
library(tidyverse)
library(magrittr)
library(stringr)
library(readxl)
directory <- "bunch/of/excel/files"
# Get an overview of all the Excel files and their sheets
sheets <-
data_frame(file = list.files(directory, full.names = TRUE),
@paulrougieux
paulrougieux / scraplinks.R
Last active October 3, 2021 06:29
Extract link texts and urls from a web page into an R data frame
@sdtaylor
sdtaylor / install_old_packages.R
Last active April 24, 2017 22:29
Install all the packages that were in the prior version of R
prior_version = 3.3
library_path = .libPaths()[1]
library_path = substr(library_path, 1, nchar(library_path)-3)
old_library_path=paste0(library_path, prior_version)
old_packages = list.files(old_library_path)
install.packages(old_packages)
@conormm
conormm / r-to-python-data-wrangling-basics.md
Last active April 24, 2024 18:22
R to Python: Data wrangling with dplyr and pandas

R to python data wrangling snippets

The dplyr package in R makes data wrangling significantly easier. The beauty of dplyr is that, by design, the options available are limited. Specifically, a set of key verbs form the core of the package. Using these verbs you can solve a wide range of data problems effectively in a shorter timeframe. Whilse transitioning to Python I have greatly missed the ease with which I can think through and solve problems using dplyr in R. The purpose of this document is to demonstrate how to execute the key dplyr verbs when manipulating data using Python (with the pandas package).

dplyr is organised around six key verbs:

@jslefche
jslefche / README.md
Last active August 21, 2019 17:57
Price Equation for Diversity-Function

The Price Equation for Partitioning Diversity Effects on Ecosystem Function

This function takes a data.frame corresponding to the site-by-species "functioning" matrix (where cells contain the values of the ecosystem function), and returns the five additive components of the Price equation.

EXAMPLE

# Example 1: all species contribute equally to functioning and all occur at the baseline site
# Here, RICH_L should be negative and equal the total number of unshared species at each site
# COMP and CDE terms should be zero