Skip to content

Instantly share code, notes, and snippets.

View gtm19's full-sized avatar

Gareth Maddock gtm19

View GitHub Profile
@gtm19
gtm19 / download_nsidc_extent_shp.R
Last active June 20, 2019 08:17
Example code to download shapefile from NSIDC website
library(tidyverse)
library(sf)
url <- "ftp://sidads.colorado.edu/DATASETS/NOAA/G02135/north/monthly/shapefiles/shp_extent/12_Dec/extent_N_201012_polygon_v3.0.zip"
tempdir <- tempdir(check = TRUE)
tempfile <- tempfile()
download.file(url, tempfile, mode = "wb")
## A short function which is effectively a wrapper around lapply, where the function is reattempted on failure
## a set number of times
repply <- function(X, FUN, ..., .max_retry = 3) {
init <- lapply(X, function(x) try(FUN(x), silent = TRUE), ...)
n <- 1
while(n <= .max_retry) {
library(shiny)
shiny::shinyApp(
ui = sidebarLayout(
sidebarPanel(
actionButton("one", "One"),
actionButton("two", "Two"),
actionButton("three", "Three"),
actionButton("four", "Four")
),
library(tidyverse)
library(googlesheets4)
library(sf)
us <-
rnaturalearth::ne_states(returnclass = "sf") %>%
filter(iso_a2 == "US" & !iso_3166_2 %in% c("US-HI", "US-AK")) %>%
sf::st_transform(102003)
monuments <-
@gtm19
gtm19 / preview_devise_mail.rb
Last active April 24, 2021 21:22 — forked from ThawanFidelis/preview_devise_mail.rb
Preview Devise Mails
# app/test/mailers/previews/devise_mailer_preview.rb
class DeviseMailerPreview < ActionMailer::Preview
def confirmation_instructions
Devise::Mailer.confirmation_instructions(User.first, {})
end
def unlock_instructions
Devise::Mailer.unlock_instructions(User.first, "faketoken")
end
@gtm19
gtm19 / setup_wsl.sh
Created January 7, 2022 14:02
WSL Setup
#!/bin/bash
set -e
# Utils
e_header() {
printf "\n$(tput setaf 3)%s$(tput sgr0)\n" "$@"
sleep 2
}
@gtm19
gtm19 / _navbar.html.erb
Last active February 1, 2022 18:43
Fixed lewagon navbar partial
<!-- app/views/layouts/shared/_navbar.html.erb -->
<div class="navbar navbar-expand-sm navbar-light navbar-lewagon">
<div class="container-fluid">
<%= link_to "#", class: "navbar-brand" do %>
<%= image_tag "https://raw.githubusercontent.com/lewagon/fullstack-images/master/uikit/logo.png" %>
<% end %>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
# ./encrypt.rb
# 1. Get an array of all the letters of the alphabet
# See: https://ruby-doc.org/core-3.0.2/Range.html
LETTERS = ("A".."Z").to_a
# Alternatively:
# LETTERS = Array ("A".."Z")
def encrypt(text, offset = -3)
# Parameter checking: -------------------------------------------------------