Skip to content

Instantly share code, notes, and snippets.

View echasnovski's full-sized avatar

Evgeni Chasnovski echasnovski

View GitHub Profile
@echasnovski
echasnovski / upgraded_sideways_polynomial_tangents.R
Created February 22, 2019 09:13
Updated version of https://gist.github.com/andrewheiss/29057150cc6466f0f4d9c39236c19aa6 . It has three main changes: 1) Model variables are swapped for convenience, 2) Adding tangent line wrapped into function with extra functionality, 3) Plot is done for a new model with swapped variables and then coordinates are flipped.
library(tidyverse)
library(Deriv)
library(scales)
# Here we change variable names: x is "Work effort", y is "Wage per hour"
response_curve <- function(x) 60*x^4 + 5*x + 6
response_deriv <- Deriv(response_curve)
# Function for tangent line becomes very simple. For more information, see:
# https://en.wikipedia.org/wiki/Tangent#More_rigorous_description
@echasnovski
echasnovski / submodules.md
Created February 22, 2019 21:02 — forked from manasthakur/submodules.md
Using git submodules to version-control Vim plugins

Using git-submodules to version-control Vim plugins

If you work across many computers (and even otherwise!), it's a good idea to keep a copy of your setup on the cloud, preferably in a git repository, and clone it on another machine when you need. Thus, you should keep the .vim directory along with your .vimrc version-controlled.

But when you have plugins installed inside .vim/bundle (if you use pathogen), or inside .vim/pack (if you use Vim 8's packages), keeping a copy where you want to be able to update the plugins (individual git repositories), as well as your vim-configuration as a whole, requires you to use git submodules.

Creating the repository

Initialize a git repository inside your .vim directory, add everything (including the vimrc), commit and push to a GitHub/BitBucket/GitLab repository:

cd ~/.vim
@echasnovski
echasnovski / unsort-benchmarks.R
Created March 20, 2019 10:06
Benchmarks for different types of "unsorting"
library(tidyverse)
library(microbenchmark)
unsort_prealloc <- function(xo, ord) {
xu <- character(length(xo))
xu[ord] <- xo
xu
}
@echasnovski
echasnovski / geom_parallel_slopes.R
Last active October 29, 2019 14:18
Draft of `geom_parallel_slopes()` for {moderndive} package
library(tidyverse)
# Geom creation -----------------------------------------------------------
StatParallelSlopes <- ggproto(
"StatParallelSlopes", Stat,
required_aes = c("x", "y"),
compute_panel = function(data, scales, se = TRUE, formula = y ~ x, n = 100) {
@echasnovski
echasnovski / python-snippets-from-r.py
Last active June 17, 2020 10:18
Python snippets to mimic functionality of common R functions (mostly tidyverse)
import numpy as np
import pandas as pd
def nest(df, cols, nest_name="data", keep=False):
"""Nest non-grouping columns into a list-column of data frames
Parameters
----------
df : Data frame.
@echasnovski
echasnovski / CycleSample.py
Created April 25, 2020 10:58
Simple class for doing "cycled sampling": iterative sampling when currently sampled element is put in the beginning of sampling pool.
import random
# Used only for exploration
import numpy as np
class CycleSample:
def __init__(self, x, weights=None, preshuffle=True):
self.pool = list(x)
if preshuffle:
@echasnovski
echasnovski / startup-summary.md
Created November 15, 2021 18:43
Outputs of 'benchmarks/starter/' directory of 'echasnovski/mini.nvim' repository
init file median mean stdev minimum maximum
starter-default 69.0ms 70.8ms 4.3ms 63.6ms 82.7ms
empty 64.1ms 65.8ms 4.3ms 60.0ms 79.4ms
startify-starter 70.2ms 71.9ms 4.5ms 64.3ms 85.7ms
startify-original 80.3ms 82.2ms 4.5ms 76.4ms 107.2ms
startify-alpha 72.1ms 73.8ms 4.3ms 66.5ms 86.9ms
dashboard-starter 68.4ms 70.3ms 4.5ms 63.3ms 102.9ms
dashboard-original 70.6ms 72.3ms 4.4ms 65.5ms 99.6ms
dashboard-alpha 69.8ms 71.5ms 4.4ms 64.7ms 97.2ms
@echasnovski
echasnovski / collapse_simple_statement_ConditionalOnly.diff
Last active July 6, 2022 07:28
'mini.nvim' diffs of running different `stylua` values of possibly new "collapse_simple_statement" option.
diff --git a/.stylua.toml b/.stylua.toml
index 6601564..b865102 100644
--- a/.stylua.toml
+++ b/.stylua.toml
@@ -4,3 +4,4 @@ indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferSingle"
no_call_parentheses = false
+collapse_simple_statement = "ConditionalOnly"
diff --git a/lua/mini/base16.lua b/lua/mini/base16.lua
@echasnovski
echasnovski / random-colorscheme.lua
Created September 9, 2022 09:42
Create and apply randomly generated Base16 color scheme
-- Create and apply randomly generated Base16 color scheme
--
-- Prerequisites:
-- - Install 'mini.nvim' (https://github.com/echasnovski/mini.nvim).
-- - Put code inside a Lua file (like '~/.config/nvim/random-colorscheme.lua').
-- - Source that file. Either with `:source <file path>` or with
-- `require('<module name>')` (if put inside 'lua' subdirectory of your
-- config; won't work more than once due to caching).
-- General idea:
@echasnovski
echasnovski / neovim-options-survey.lua
Created November 22, 2022 12:48
Source code of script used for "Neovim built-in options survey"
-- Get Neovim version
local version = vim.version()
if version.major == 0 and version.minor < 7 then error('This script needs at least Neovim 0.7.') end
-- Create scratch buffer to better track options and paste output lines
local buf_id = vim.api.nvim_create_buf(true, true)
vim.api.nvim_set_current_buf(buf_id)
-- Define "bad" (non-transferable) options
--stylua: ignore