Skip to content

Instantly share code, notes, and snippets.

@ggandor
ggandor / fzy.lua
Created April 25, 2023 12:40
Minimal fzy integration for Neovim in ~100 lines (oldfiles, cmd history, buffers, jumplist, etc.)
-- https://github.com/jhawthorn/fzy/pull/116#issuecomment-538708329
local function fzy(a)
local saved_spk = vim.o.splitkeep
local src_winid = vim.fn.win_getid()
-- lines >= 3 is a hardcoded limit in fzy
local fzy_lines = (vim.v.count > 2 and vim.v.count) or 10
local tempfile = vim.fn.tempname()
local term_cmd = a.input .. ' | fzy -l' .. fzy_lines .. ' > ' .. tempfile
-- FIXME: terminal buffer shows in `:ls!` after exiting.
@ggandor
ggandor / leap_ast.lua
Created July 9, 2022 09:46
Jump to and operate on AST nodes via the Leap interface
local api = vim.api
-- Note: The functions used here will be upstreamed eventually.
local ts_utils = require('nvim-treesitter.ts_utils')
local function get_nodes()
local wininfo = vim.fn.getwininfo(api.nvim_get_current_win())[1]
-- Get current TS node.
local cur_node = ts_utils.get_node_at_cursor(0)
if not cur_node then return end
-- Get parent nodes recursively.
@ggandor
ggandor / leap_lines.lua
Created July 9, 2022 09:44
Use leap.nvim to jump to the beginnings of lines
local function get_targets(winid)
local wininfo = vim.fn.getwininfo(winid)[1]
local cur_line = vim.fn.line('.')
-- Get targets.
local targets = {}
local lnum = wininfo.topline
while lnum <= wininfo.botline do
-- Skip folded ranges.
local fold_end = vim.fn.foldclosedend(lnum)
if fold_end ~= -1 then
import math
import os
from PyPDF2 import PdfFileReader
from PyPDF2 import PdfFileWriter
def split_pdf_to_even_length_parts(num_of_parts, path):
reader = PdfFileReader(path)
num_of_pages = reader.getNumPages()
avg_part_length = round(num_of_pages / num_of_parts)
// Tom Duff, 1983 (trivia: for a Lucasfilm animation)
// problem: loop unrolling (reducing the #of loop tests by putting multiple copies of the
// given instruction into the body, instead of just one)
// implementation problem: given x-fold unrolling, performing the remainder of iterations,
// when count (#of original cycles) is not divisible by x
send(to, from, count)
register short *to, *from;
register count;
@ggandor
ggandor / replace_motion.vim
Last active March 16, 2021 14:58
Vim replace operator on steroids
" Replace operator that takes an additional motion
" Usage: yr{motion}{char}
" Try it together with targets.vim text objects, the possibilities are endless!
" TODO: Don't ask for input each time when dot-repeated. (Or is that a feature?)
fun! s:Replace(type)
let sel_save = &selection
let &selection = "inclusive"
let reg_save = @@
@ggandor
ggandor / ct_notes.txt
Created February 24, 2021 18:33 — forked from buzzdecafe/ct_notes.txt
Category Theory for Programmers: Notes
CATEGORY THEORY FOR PROGRAMMERS
Category Theory 1.1: Motivation and Philosophy
https://www.youtube.com/watch?v=I8LbkfSSR58&index=1&list=PLbgaMIhjbmEnaH_LTkxLI7FMa2HsnawM_
Composability, Abstraction, Reusability
Category Theory is a higher-level language.
Not a practical, executable language.