Skip to content

Instantly share code, notes, and snippets.

@zachlipp
zachlipp / README.md
Last active October 4, 2024 18:41
Minimal exmaple of `molten.nvim` with comment-delimited cells in Python scripts

Minimal implementation of comment-delimited Jupyter cells using molten.nvim

Instructions

  1. Configure neovim to use this init.lua
  • If you aren't using neovim and you don't have a custom configuration, just plop init.lua into ~/.config/nvim/ and it should start up
  • If you don't want to overwrite an existing configuration, use the NVIM_APPNAME envvar to specify a new directory for this session. See :h NVIM_APPNAME
  • Be sure to put vim-plug somewhere this vim can see it, e.g. ~/.local/share/$NVIM_APPNAME/site/autoload
  • Open neovim with nvim, then run :PlugInstall
  1. Start a session
  • Create a new directory, for example molten-demo
from typing import Literal
class TicTacToe:
def __init__(self):
self.dim = 3
self.placements = ["-"] * self.dim**2
self.marks = ["X", "O"]
self.current_player = 0
self.moves = 0
@zachlipp
zachlipp / extremely_random_seeds.py
Last active October 29, 2019 01:15
Random seeds example for October 2019 ChiPy spooky lightning talk
import random
import numpy as np
import tensorflow as tf
import torch
class ExtremelyRandomSeed:
@staticmethod
def _get_nondeterministic():
@zachlipp
zachlipp / aus_gender_gap.R
Last active April 26, 2018 22:28
Code for my submission to week 4 of #TidyTuesday
library(readr)
library(ggplot2)
library(tidyr)
library(dplyr)
library(grid)
# Read and clean file
tb = read_csv("tidy_tuesday.csv", col_names = T, skip = 2) %>%
slice(2:nrow(.)) %>%
filter(Occupation1 != "Not listed or unknown")
@zachlipp
zachlipp / cowplot_facets.R
Last active December 28, 2017 23:12
Facet wrap vertically with relative sizing!
library(tidyverse)
df_fruit <- structure(list(person = structure(c(2L, 1L, 1L, 2L, 2L, 2L, 2L
), .Label = c("Dave", "Jane"), class = "factor"), fruit = structure(c(1L,
2L, 3L, 5L, 7L, 4L, 6L), .Label = c("apple", "banana", "carrot",
"grape", "orange", "pear", "pineapple"), class = "factor"), amount = c(12,
14, 16, 17, 18, 9, 10)), .Names = c("person", "fruit", "amount"
), row.names = c(NA, -7L), class = "data.frame")
@zachlipp
zachlipp / dplyr_error.R
Created July 18, 2017 20:23
Error in dplyr::n()
# Similar to https://stackoverflow.com/questions/22801153/dplyr-error-in-n-function-should-not-be-called-directly
library(magrittr)
set.seed(777)
df <- data.frame(value = rnorm(100))
df %>%
dplyr::summarise(total = sum(value))
@zachlipp
zachlipp / select_all_dummies.R
Last active June 13, 2018 16:18
Convert a nested "Select all that apply" question to dummy columns
library(purrr)
library(dplyr)
SeparateDelimitedColumn = function(df, col, delim) {
#' Convert a delimited column in a dataframe column to a dataframe of logicals
#'
#' This function splits a list in a dataframe to dummy columns indicating
#' whether or not an item was present in the column
#' @param df dataframe with a liscol
#' @param col the delimted column to split