Skip to content

Instantly share code, notes, and snippets.

View kyokley's full-sized avatar

Kevin Yokley kyokley

View GitHub Profile
@kyokley
kyokley / dock.md
Last active June 13, 2024 20:32
Docking/Undocking a Lenovo laptop running xmonad

Docking/Undocking a Lenovo laptop running xmonad

Introduction

I ran into this issue while at work and came up with this solution. This gist is mostly just documentation for myself so I can remember what I did 6 months from now. I am in no way saying that this is the right way to fix things but I'll be thrilled if this is in any way helpful to others. That being said, I make no guarantees that bad things will not happen to your machine if you follow these directions. Proceed at your own risk.

Although, I mention using the following setup to resolve an issue I was having using xmonad as my windows manager, I don't think there's anything special about it. It should be possible to use the following steps with any windows manager.

Problem

Setting up multiple monitors in xmonad requires defining the screen configuration using xrandr. The problem is that xmonad does not respond to a laptop being placed or removed from a docking station. Obviously, the solution is to update the monitor configuration on the

@kyokley
kyokley / whitespace.md
Last active July 12, 2017 18:02
Trailing whitespace handling in VIM

Trailing whitespace handling in VIM (Buffer Pre-write Hook Part 1)

Introduction

It is a common coding practice to remove trailing whitespace. Below are some suggestions about how to handle it.

Highlighting

Adding the following to your .vimrc will highlight any trailing whitespace:

highlight ExtraWhitespace ctermbg=darkred guibg=darkred ctermfg=yellow guifg=yellow
match ExtraWhitespace /\s\+$/
@kyokley
kyokley / syntax.md
Last active November 13, 2024 18:56
Preventing saving for various errors in VIM

Preventing saving for various errors in VIM (Buffer Pre-write Hook Part 2)

Introduction

This is a continuation of my buffer pre-write hook series. Check out the previous gist to follow the progression.

Have you ever tried running a file only to be stopped by "<<<<<<<"?

Wouldn't it be nice to be able to automatically run your code through pyflakes before actually saving it? Maybe even raise an error for showstopping bugs in your code?

@kyokley
kyokley / bandit_hook.md
Last active June 28, 2018 06:33
Checking for Python Security Vulnerabilities with VIM

Checking for Python Security Vulnerabilities with VIM (Buffer Pre-write Hook Part 3)

Introduction

To continue my series of vim pre-write hooks, I wanted to add a new check for security static analysis failures. To see the progression of the series, please check out my other gists.

Back to security... In my office, we use OpenStack's Bandit static analysis tool. If you're not familiar with it, you should check it out. It's pretty nifty.

Getting Started

@kyokley
kyokley / vim_vcs_commands.md
Last active February 4, 2018 21:00
Useful VCS commands in VIM

Keyboard Shortcuts for Blame and Show

git blame and git show are useful commands for giving context of the code you're viewing. Since I spend the majority of my time in Vim, they become even more useful if they are executable from inside the editor. Of course, Vim makes this easy by giving a way to call external commands.

Vim (vimrc)

Git

Blame

For git blame, I wanted the ability to either blame the entire file or just part of one. By default, I blame the entire file but take advantage of Vim's visual mode to filter for only the selected lines.

nnoremap gb :!git blame =expand("%:p")  \| color_git_blame \| less +=line("w0") 
@kyokley
kyokley / git_pre_push.md
Last active May 17, 2018 18:51
Git Pre-push Hook

Since I always forget how to write a git hook to prevent pushing certain branches to remotes, I'm writing this gist to, hopefully, help my future self remember...

To prevent local branch "work" from being pushed to the github remote:

#!/bin/sh

remote="$1"
url="$2"

while read local_ref local_sha remote_ref remote_sha
@kyokley
kyokley / py23_check.md
Last active July 7, 2018 13:29
Dynamically set Python2/3 version in Syntastic

Determining Python 2/3 Version in VIM

Introduction

I am a big fan of the syntastic package. In python, it is useful for viewing both Pyflakes and Bandit errors. However, this only works if syntastic knows what python interpreter to use. Not everyone is fortunate enough to have upgraded all of their software to python3. For reasons out of my control, I end up spending most of my time writing python2 code. This means that the times when I finally get to write python3, all of my syntax checking is broken. How cool would it be to have VIM determine what version of python to use automatically? So, begins my grand experiment...

Prerequisites

For this to work, I will be using a virtualenv for python2 and one for python3. It's not absolutely necessary to use virtualenvs but I definitely recommend it. Setting up virtualenvs is out of the scope of this gist but make sure that each virtualenv

@kyokley
kyokley / dvim.sh
Last active September 24, 2022 15:22
Bash Docker VIM: Quick bash functions to support using a dockerized Vim
# Append these functions to bashrc or zshenv to get quick acccess to a dockerized neovim
# For example, using curl:
# curl https://gist.githubusercontent.com/kyokley/92703c1367abfbd86b1b575be004a688/raw/65a910d066c332fdc3e428204e6138253bec2b17/dvim.sh >> ~/.bashrc
function git-absolute-path () {
fullpath=$([[ $1 = /* ]] && echo "$1" || echo "$(pwd -P)/${1#./}")
if [ $(git rev-parse --show-superproject-working-tree) ]
then
gitroot="$(git rev-parse --show-superproject-working-tree)"
else