Skip to content

Instantly share code, notes, and snippets.

View brandonwillard's full-sized avatar

Brandon T. Willard brandonwillard

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@brandonwillard
brandonwillard / gist:dab0b21099ea88ad3545
Created May 18, 2015 20:14
glmnet work-around for a single column design matrix
local({
myglmnet = function(x, y, family = c("gaussian", "binomial", "poisson", "multinomial", "cox", "mgaussian"), weights, offset = NULL, alpha = 1, nlambda = 100, lambda.min.ratio = ifelse(nobs < nvars, 0.01, 1e-04), lambda = NULL, standardize = TRUE, intercept = TRUE, thresh = 1e-07, dfmax = nvars + 1, pmax = min(dfmax * 2 + 20, nvars), exclude, penalty.factor = rep(1, nvars), lower.limits = -Inf, upper.limits = Inf, maxit = 1e+05, type.gaussian = ifelse(nvars < 500, "covariance", "naive"), type.logistic = c("Newton", "modified.Newton"), standardize.response = FALSE, type.multinomial = c("ungrouped", "grouped")) {
family = match.arg(family)
if (alpha > 1) {
warning("alpha >1; set to 1")
alpha = 1
}
if (alpha < 0) {
warning("alpha<0; set to 0")
@brandonwillard
brandonwillard / nvim-terminal-edit.py
Last active October 6, 2017 21:35 — forked from bfredl/nvim-terminal-edit.py
Edit file in host Neovim instance from a :terminal buffer
#!/home/bwillard/apps/anaconda3/envs/neovim3/bin/python
"""Edit a file in the host nvim instance."""
from __future__ import print_function
import os
import sys
from neovim import attach
args = sys.argv[1:]
@brandonwillard
brandonwillard / sparse-matrix-fix.R
Last active March 12, 2018 14:58
Slow fix for creating large sparse matrices with interactions
library(Rcpp)
#library(RcppProgress)
#library(RcppParallel)
{
code = '
// [[Rcpp::depends(RcppProgress, RcppArmadillo, RcppParallel)]]
#define ARMA_64BIT_WORD
#include <RcppArmadillo.h>
#include <RcppParallel.h>
@brandonwillard
brandonwillard / assign_caching.py
Created April 14, 2018 17:31
Python AST-based Caching
import inspect
import shelve
import ast
from itertools import cycle
class AssignCachingVisitor(ast.NodeVisitor):
"""Slightly less naive src block caching.
@brandonwillard
brandonwillard / org-ref-use-options.el
Last active May 8, 2018 21:02
Make org-ref use org-mode options instead of links
(defun btw//org-ref-find-bibliography ()
"Find the bibliography files in the current buffer.
This function sets and returns `org-ref-bibliography-files' obtained from
#+BIBLIOGRAPHY options."
(prog1
;; When called from within a bibtex file, assume we want it; otherwise,
;; check the current file for a bibliography source.
(setq org-ref-bibliography-files (or (and (f-ext? buffer-file-name "bib")
(list buffer-file-name))
@brandonwillard
brandonwillard / Dockerfile
Created August 16, 2018 21:51
Dockerfile for Python 2.7 Tests of Hy
# -*- mode: Dockerfile -*-
#
# To build the image, in the Hy project root with this file present (and possibly renamed), run the following:
# docker build --rm -t hy-test-py27 -f Dockerfile .
#
# To launch a container, for the example image built above, and start an interactive session:
# docker run -ti --rm hy-test-py27:latest /bin/bash
#
# and to mount/expose a directory (`pwd` in this example) from the host at
# `/opt/hylang/hy` in the container: