Skip to content

Instantly share code, notes, and snippets.

View tweekmonster's full-sized avatar

Tommy Allen tweekmonster

View GitHub Profile
@tweekmonster
tweekmonster / pythonrc.py
Created March 2, 2023 20:24
Startup script to use ipython (if available in environment) when python is ran without arguments
import os
import sys
import site
if len(sys.argv) == 1:
del os.environ['PYTHONSTARTUP']
sys.path.append(site.USER_SITE)
try:
if 'IPython' in sys.modules:
@tweekmonster
tweekmonster / ansi_color_text.py
Created May 28, 2020 21:17
Simple colored ANSI sequence text printing
import sys
BLACK = 0
RED = 1
GREEN = 2
YELLOW = 3
BLUE = 4
MAGENTA = 5
CYAN = 6
@tweekmonster
tweekmonster / strict_types.py
Created January 4, 2020 21:40
Decorator for enforcing strict type annotations on functions
import typing
import inspect
import functools
def strict_types(func: typing.Callable):
"""Decorator for enforcing strict type annotations"""
argspec = inspect.getfullargspec(func)
ret_type = argspec.annotations.pop('return', None)
@tweekmonster
tweekmonster / relativenumber_op.vim
Created January 26, 2018 04:29
Show relative number column when using certain operator keys
" Requires 'timeoutlen' to be low enough for this to be practical:
" set timeoutlen=100
function! s:relative_number_op(key) abort
let old_rn = &l:relativenumber
let &l:relativenumber = 1
redraw
let seq = a:key
while 1
highlight default NonComment ctermfg=8 ctermbg=none cterm=none guifg=#333333 guibg=none gui=none
function! s:toggle_comments() abort
if exists('w:toggle_comments')
silent! call matchdelete(w:toggle_comments)
unlet! w:toggle_comments
else
let w:toggle_comments = matchadd('NonComment', '^\%(\s*'.split(escape(&commentstring, '^$.*/"'''), '%s')[0].'\)\@!.*')
endif
endfunction
@tweekmonster
tweekmonster / .nvimrc
Last active February 5, 2017 02:22
.nvimrc script for Neovim development using Neomake
if !has('nvim')
finish
endif
let s:path = expand('<sfile>:p:h')
let s:target = 'all'
let s:error_path = s:path.'/tmp/errors.json'
let s:errors_url = 'https://raw.githubusercontent.com/neovim/doc/gh-pages/reports/clint/errors.json'
let g:neomake_make_maker = {
@tweekmonster
tweekmonster / xtreme_python_def.py
Created July 6, 2016 05:21
I like python, but you can write some awful shit with it.
# This illustrates how ridiculous python functions can get.
# It is far from a common way to write functions.
# Though, I've seen comments inside of multiline arguments
# in the stdlib modules.
def hello \
( # This starts the hello function
arg1, # This is arg1
# I'm an extra comment
@tweekmonster
tweekmonster / gen-terminfo.sh
Created May 24, 2016 04:20
Enable italics and standout in tmux
#!/bin/bash
# Generate xterm-256color and screen-256color terminfo files that supports
# italicized text and standout display style. This will override the system's
# descriptions of xterm-256color and screen-256color for your shell.
#
# To enable in tmux:
# set -g default-terminal "xterm-256color"
#
# tmux recommends creating an `tmux-256color` terminfo file and setting the
# default-terminal to "xterm", but this causes ssh sessions to not display
@tweekmonster
tweekmonster / python-imports.vim
Created April 27, 2016 06:09
Vim script to quickly edit the top portion of Python scripts using NrrwRgn
" A little annoying becuase NrrwRgn doesn't seem to be well suited for this.
" But, it gets the job done.
" Uses <leader>i in normal mode to open the split.
function! s:nrrw_head() abort
let saved = winsaveview()
keepjumps normal! 1G
let start = 1
let end = search('^\%(def\|class\)\s', 'ncW')
if !end
@tweekmonster
tweekmonster / edit-command-line.zsh
Created April 22, 2016 05:40
zsh edit-command-line zle widget that sets the cursor position in Vim
function edit-command-line() {
tmpfile=$(mktemp -t zsheditXXXXXXXX.sh)
print -R - "$PREBUFFER$BUFFER" > $tmpfile
editor=${VISUAL:-${EDITOR:-vi}}
args=()
if [[ "$editor" =~ vim ]]; then
pb=${#PREBUFFER}
(( b=pb+CURSOR ))
args+=("-c" ":call cursor(byte2line($b), ($b - $pb) + 1)")
fi