Skip to content

Instantly share code, notes, and snippets.

View tjdevries's full-sized avatar
🏠
Open Open Source: https://www.twitch.tv/teej_dv

TJ DeVries tjdevries

🏠
Open Open Source: https://www.twitch.tv/teej_dv
View GitHub Profile
local properties = {
showing = {
get = function(t)
print("Yoooo we're showing.")
return 5
end,
set = function(t, v)
error("This can't be ser.")
@tjdevries
tjdevries / enum.lua
Created April 14, 2021 19:43
enum example prime
local Enum = function(tbl)
return setmetatable(tbl, {
__index = function(_, key)
error(string.format("%s does not exist for this enum.", key))
end,
__newindex = function(t, key, value)
error("Enums are immutable. You are not able to set new values")
end,
})
@tjdevries
tjdevries / blindfolded.py
Created April 9, 2021 01:18
Yup, get ready begin
scores = {
"!hate": -2,
"!dislike": -1,
"!like": 1,
"!love": 2,
}
from collections import defaultdict
counts = defaultdict(int)
@tjdevries
tjdevries / counting.lua
Created March 12, 2021 19:41
This is for prime, as always.
local get_max_index = function(t)
local max = 0
for k, v in pairs(t) do
max = math.max(k, max)
end
return max
end
@tjdevries
tjdevries / example_benchmarks.md
Last active March 4, 2021 14:10
Some boring speed comparisons

Comparisons taken from bram's reasoning for vim9

let start = reltime()

function VimNew()
  let sum = 0
  for i in range(1, 2999999)
    let sum = sum + i
 endfor
{
_callbacks = {
bytes = { <function 1> },
changedtree = { <function 2> },
child_added = {},
child_removed = {}
},
_children = {
lua = {
_callbacks = {
(
(plain_value) @string
(#eq? @string "background-color")
) @matched
@tjdevries
tjdevries / aligned_virt_text.lua
Created November 6, 2020 16:16
Aligned Virt Text Example (not guaranteed to work forever)
vim.lsp.diagnostic.get_virtual_text_chunks_for_line = function(bufnr, line, line_diagnostics)
if #line_diagnostics == 0 then
return nil
end
local line_length = #(vim.api.nvim_buf_get_lines(bufnr, line, line + 1, false)[1] or '')
local get_highlight = vim.lsp.diagnostic._get_severity_highlight_name
-- Create a little more space between virtual text and contents
local virt_texts = {{string.rep(" ", 80 - line_length)}}
function x()
return 1, 2
end
function y()
local foo = {{x()}, {x()}}
return vim.tbl_flatten(foo)
end
@tjdevries
tjdevries / overlength_highlight.vim
Last active June 28, 2017 21:51
Highlight overlength
let g:highlight_overlength = v:true
let g:highlight_overlength_length = 72
let g:load_overlength = v:true
" Use :call ToggleOverlength()
" to toggle whether or not you show highlights
function! ToggleOverlength() abort
let g:highlight_overlength = !g:highlight_overlength
if g:highlight_overlength