Instantly share code, notes, and snippets.

View shape.txt
(defn shape-with [shape xs]
(->> (reductions (fn [[a b] n]
((juxt take drop) n b))
[xs xs]
(map first)))
(defun shape-with (shape xs)
(loop for n in shape
View reactwidget.R
#' @export
React <- structure(list(), class = "react.component.builder")
isUpper <- function(s) {
grepl("^[[:upper:]]+$", s)
#' @export
`$.react.component.builder` <- function(x, name) {
if (length(name) == 0 || !isUpper(substring(name, 1, 1))) {

Recently I had a dream about Pete Davidson, the SNL cast member. In the dream, Pete and I were in the checkout line together at a supermarket. We started to chat, but very shortly I realized I could not make any sense of what Pete was saying.

He was gesturing with his hands, making faces, laughing, and was otherwise highly animated. The longer he went on without my understanding, the more awkward the situation became for me. I did my best to appear like I understood him, smiling and nodding.

View collector.lisp
(defun collector ()
(let ((tail nil)
(head nil))
(lambda (&optional (item nil item?))
((not item?) head)
((null tail) (setq tail (cons item nil)
head tail))
(t (let ((new-tail (cons item nil)))
(rplacd tail new-tail)
View bm.js
View fizzbuzz.R
for (i in 1:100) print(
i %% 3 == 0 ~ "Fizz",
i %% 5 == 0 ~ "Buzz",
TRUE ~ toString(i)
View tree_df.R
# Like Map but expects f to return a list and concatenates results.
Mapcan <- function(f, xs) Reduce(append, Map(f, xs))
# Returns a list of named lists, each with `name` and `value` values, for the
# given named list.
as_entries <- function(named_list) {
Map(function(name) list(key = name, val = named_list[[name]]), names(named_list))
# Returns a list of lists, each starting with the leaf value and followed by the path to that leaf.
View deepMerge.R
# "Deep"-merges named lists, preferring values from y
deepMerge <- function(x, y) {
if (is.null(y)) return(x)
if (is.null(x)) return(y)
if (is.list(x) && is.list(y)) {
Reduce(function(merged, name) {
merged[[name]] <- deepMerge(x[[name]], y[[name]])
}, union(names(x), names(y)), init = x)
} else y
View fruitExplorer.R
fruits <- c("Banana", "Blueberry", "Cherry", "Coconut", "Grapefruit", "Kiwi", "Lemon", "Lime", "Mango", "Orange", "Papaya")
pickerMaker <- function(selected = c(), selectedText = "{0}/{1} fruits") {
inputId = "picker",
label = "Choices :",
choices = fruits,
View cond.lisp
(defmacro my-cond (&body lists)
(loop for (test . exprs) in lists
collect `(if ,test (return (progn ,@exprs))) into ifs
finally (return `(block nil ,@ifs))))