Skip to content

Instantly share code, notes, and snippets.

View nacnudus's full-sized avatar

Duncan Garmonsway nacnudus

View GitHub Profile
@artifactsauce
artifactsauce / conv-pg_dump-tsv.pl
Last active March 13, 2024 13:17
Convert from a pg_dump data file to TSV files for LOAD DATA INFILE.
#!/usr/bin/env perl
use strict;
use warnings;
use Path::Class;
use FindBin;
my $output_dir = dir($FindBin::Bin,"data");
$output_dir->is_dir or die "[ERROR] $output_dir is not a directory.";
@cgwxyz
cgwxyz / urldecode_encode.lua
Last active June 23, 2020 14:09
lua urlencode/urldecode
function encodeURI(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
@wch
wch / multi_dispatch.R
Last active December 24, 2023 17:20
Multiple dispatch in R without S4
# ---- Multiple dispatch functions -----
multi_dispatch <- function(gen_name) {
calling_env <- parent.frame()
parent_call <- sys.call(sys.parent())
calling_fun <- sys.function(sys.parent())
arg1 <- eval(parent_call[[2]], calling_env)
arg2 <- eval(parent_call[[3]], calling_env)
@Bill
Bill / docker-compose.yml
Last active July 8, 2022 07:10
Run a local Hypothes.is annotation server (and the services it needs) via docker-compose
# This docker-compose.yml will run the Hypothes.is annotation server.
# (adapted from instructions here https://h.readthedocs.org/en/latest/INSTALL.html)
#
# Place this file in the working directory (clone of https://github.com/hypothesis/h)
# run with docker-compose up -d
#
# Now browse to Hypothes.is at http://192.168.59.103:8000/ and create an account
# You'll see the invitation email in Mailcatcher at http://192.168.59.103:1080/
# Click that invitation link and log in on your local Hypothes.is
# And you are ready to annotate!
@andrewxhill
andrewxhill / minimum_spanning_tree.sql
Created March 13, 2016 14:07
Minimum spanning tree in SQL... just because
CREATE TYPE minimum_spanning_tree_internal AS (
d NUMERIC[],
a INT[],
b INT[],
geoms GEOMETRY[],
ids TEXT[]
);
CREATE TYPE minimum_spanning_tree_unit AS (
d NUMERIC,
local char_to_hex = function(c)
return string.format("%%%02X", string.byte(c))
end
local function urlencode(url)
if url == nil then
return
end
url = url:gsub("\n", "\r\n")
url = url:gsub("([^%w ])", char_to_hex)
@bpmore
bpmore / sort-tabs.txt
Created June 9, 2016 17:41
Sort Tabs in Google Spreadsheets
1. Copy/Paste the information below to the clipboard
2. Open the spreadsheet whose sheets need to be alphabetised
3. Choose Tools > Script editor > Blank (this opens a new tab in the browser)
4. Press Control+A followed by Control+V copy and paste the script in
5. Press Control+S to save the script
6. Choose Run > sortSheets
7. Go back to the spreadsheet tab to view the new sorted tab order
--Copy everything below this line--
function sortSheets () {
@dbtek
dbtek / venv_wrapper
Last active July 2, 2024 18:26
Python 3 venv wrapper. Manages all virtual environments under ~/.venv/ .
# venv_wrapper, manage all virtual environments under ~/.venv/
# Include the following in .bashrc / .bash_profile / .zshrc
# See https://gist.github.com/dbtek/fb2ddccb18f0cf63a654ea2cc94c8f19
#
# Usage:
# $ mkvenv myvirtualenv # creates venv under ~/.venv/
# $ venv myvirtualenv # activates venv
# $ deactivate # deactivates venv
# $ rmvenv myvirtualenv # removes venv
# $ rmvenv env1 env2 # removes multiple venvs
@edavidaja
edavidaja / convert_to_xlsx.R
Created May 28, 2019 22:08
convert legacy xls files to xlsx files
library(purrr)
xls_to_xlsx <- function(file) {
if (fs::path_ext(file) != "xls") {
stop("file must have extension xls")
}
sheets <- readxl::excel_sheets(file)
insheets <- map(sheets, ~readxl::read_excel(file, .x, col_names = FALSE))
@jobdiogenes
jobdiogenes / demo-of-use-google-drive-sheets-in-r-with-google-colaboratory.ipynb
Last active November 29, 2022 02:54
Demo of use Google Drive/Sheets in R with Google Colaboratory.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.