Skip to content

Instantly share code, notes, and snippets.

View DarwinAwardWinner's full-sized avatar

Ryan C. Thompson DarwinAwardWinner

View GitHub Profile
@DarwinAwardWinner
DarwinAwardWinner / analyze_pkg_usage.R
Last active July 8, 2023 10:08
Script for finding loaded but unused packages in R scripts
#!/usr/bin/env Rscript
suppressPackageStartupMessages({
library(globals)
library(readr)
library(stringr)
library(rex)
library(magrittr)
library(rlang)
library(knitr)
@DarwinAwardWinner
DarwinAwardWinner / argprint.py
Created August 25, 2011 15:26
Print a Python function's arguments every time it is called
# This file defines a decorator '@log_to()' that logs every call to a
# function, along with the arguments that function was called with. It
# takes a logging function, which is any function that accepts a
# string and does something with it. A good choice is the debug
# function from the logging module. A second decorator '@logdebug' is
# provided that uses 'logging.debug' as the logger.
from __future__ import print_function
from functools import wraps
from inspect import getcallargs, getargspec
@DarwinAwardWinner
DarwinAwardWinner / .home-rsync-filter
Created April 29, 2011 08:12
Example rsync filter file for excluding temp files and stuff
## Rsync Filter for $HOME
# Universal excludes -- These apply to all subdirs
- [Cc]ache
- temp
- tmp
- octave-core
# Emacs temp files
- .#*
@DarwinAwardWinner
DarwinAwardWinner / wrapdoc.py
Created August 25, 2011 19:30
Fix the line breaks in a Python functions's doc string
import textwrap
def refill_docstring(func, *args, **kwargs):
"""Fix the text wrapping in a function's docstring.
This can be useful when creating doc strings dynamically.
Additional args are options to textwrap.TextWrapper."""
wrapper = textwrap.TextWrapper(*args, **kwargs)
# Remove trailing whitespace from all lines
@DarwinAwardWinner
DarwinAwardWinner / shortsleep-unlock.py
Last active November 12, 2021 02:51
Script to auto-unlock GNOME after short sleeps
#!/usr/bin/env python3
# shortsleep-unlock.py - Keep GNOME unlocked on short lid closes
# Copyright (C) 2021 Ryan C. Thompson <rct@thompsonclan.org>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
@DarwinAwardWinner
DarwinAwardWinner / python-bash-wrapper.py
Last active November 9, 2020 20:43
Put bash cluster setup code and python script in a single file
#!/bin/bash
# -*- mode:python -*-
#PBS -l nodes=1:ppn=8,mem=30gb
''''/bin/true
# This is bash code to set up the environment
echo "Hello from bash!"
echo "Args are: $@"
# Bash setup code ends here
python - "$@" <<EOF
''' # Python starts here '''
#!/bin/sh
# -*- mode:R -*-
#PBS -l nodes=1:ppn=8,mem=30gb
'\' >/dev/null 2>&1 || true
# This is bash code to set up the environment
echo "Hello from bash!"
echo "Args are: $@"
#!/bin/bash
#$ -cwd
#$ -l jabba,mem_free=10G,h_vmem=2G,h_fsize=1G
#$ -N approach1b
#$ -pe local 20
#$ -m e
echo "**** Job starts ****"
date
library(ggplot2)
library(ggrepel)
library(dplyr)
library(stringr)
library(scales)
## https://github.com/tidyverse/ggplot2/issues/980
mysqrt_trans <- function() {
trans_new("mysqrt",
transform = base::sqrt,
inverse = function(x) ifelse(x<0, 0, x^2),
## License: WTFPL
library(reshape2)
library(matrixStats)
library(ggplot2)
library(magrittr)
library(dplyr)
## You also need the Hmisc package installed, but I don't load it
## because of namespace clashes with dplyr
## Enumerate all possible 4d6 rolls, then order each row from high to