Skip to content

Instantly share code, notes, and snippets.

``` r
A <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), nrow = 3, ncol = 4)
B <- matrix(c(13, 14, 15, 16, 17, 18, 19, 20), nrow = 4, ncol = 2)
dot_product <- function(x, y) {
mapply(\(x, y) sum(x * y), x, y)
}
rows_of <- function(m) purrr::array_tree(m, 1)
cols_of <- function(m) purrr::array_tree(m, 2)
@krlmlr
krlmlr / check_installed.R
Created October 23, 2023 04:03
Demo for rlang::check_installed()
my_fun <- function() {
rlang::local_interactive()
rlang::check_installed(c("DiagrammeR (>= 1.0.9)", "DiagrammeRsvg"))
stopifnot(requireNamespace("DiagrammeR", quietly = TRUE))
stopifnot(requireNamespace("DiagrammeRsvg", quietly = TRUE))
}
my_fun()
#> ℹ The packages "DiagrammeR" (>= 1.0.9) and "DiagrammeRsvg" are required.
#> ✖ Would you like to install them?
@mikemahoney218
mikemahoney218 / stack_rasters.R
Created July 28, 2023 17:43
Combine multiple multi-band rasters into a single VRT
stack_rasters <- function(rasters,
raster_path,
...,
reference_layer = 1,
resampling_method = "bilinear") {
check_type_and_length(
reference_layer = integer(1)
)
@primus852
primus852 / cuda_11.7_installation_on_Ubuntu_22.04
Last active June 19, 2024 05:51 — forked from Mahedi-61/cuda_11.8_installation_on_Ubuntu_22.04
Instructions for CUDA v11.7 and cuDNN 8.5 installation on Ubuntu 22.04 for PyTorch 1.12.1
#!/bin/bash
### steps ####
# verify the system has a cuda-capable gpu
# download and install the nvidia cuda toolkit and cudnn
# setup environmental variables
# verify the installation
###
### to verify your gpu is cuda enable check
@leeolney3
leeolney3 / 06_OWID
Last active April 7, 2022 22:03
#30DayChartChallenge
#30DayChartChallenge 06 data day OWID
# South America Cereal Yield (t/ha)
# Data source: OWID and FAO, available at https://ourworldindata.org/africa-yields-problem
library(tidyverse)
library(ggtext)
library(countrycode)
library(showtext)
showtext_opts(dpi = 300)
showtext_auto(enable = TRUE)
# devtools::install_dev("rsample")
library(tidymodels)
set.seed(252)
first_split <- initial_split(iris, p = 8/10)
test <- testing(first_split)
nrow(test)
others <- training(first_split)
{%- comment -%}
Google Tag Manager scripts for checkout.liquid
Note: This script must run after {{ checkout_scripts }}
{%- endcomment -%}
{% assign order_data = checkout.order %}
{% assign customer_data = checkout.customer %}
<script type="text/javascript">
window.dataLayer = window.dataLayer || [];
@howyay
howyay / Setting up Postfix on Debian.md
Last active May 31, 2024 08:20
A guide to set up a Postfix + Dovecot IMAP server with complete spf, dkim and dmarc support.

An ultimate guide to Postfix + Dovecot IMAP server with complete SPF, DKIM and DMARC support and additional instructions for a multi-domain setup

In this guide, domain.com will be your root domain and mail.domain.com will be the hostname of your mail server

# Disallow all crawlers access to certain pages.
# Block Yandex from crawling site
User-agent: Yandex
Disallow: /
# Block Yeti
User-agent: Yeti
Disallow: /
@sco-tt
sco-tt / GA-sort-two-columns.js
Last active August 5, 2022 05:44
This Google Apps Script sorts two columns. Variables can be modified to define what two columns should be sorted, and whether they should be ascending or descending.
/** Build a menu item
From https://developers.google.com/apps-script/guides/menus#menus_for_add-ons_in_google_docs_or_sheets
**/
function onOpen(e) {
var menu = SpreadsheetApp.getUi().createMenu('Sort');
if (e && e.authMode == ScriptApp.AuthMode.NONE) {
// Add a normal menu item (works in all authorization modes).
menu.addItem('Sort Sheet', 'sort');
} else {