Skip to content

Instantly share code, notes, and snippets.

@mikeslattery
mikeslattery / gvim-ide-intg.md
Last active January 26, 2024 14:02
How to loosely integrate IdeaVim and gVim

This will allow you to switch between a Jetbrains IDE and gVim at the same file/line/column by hitting <leader>i. Hit <leader><leader>i to start gVim (once).

I've also done this with terminal Vim, but it's much more complex and varies depending on your environment (OS, DE, multiplexers, terminal).

Steps:

Install gVim and the IdeaVim plugin

In IDE: Settings > Build,Execution,Deployment > check "Allow unsigned requests"

@mikeslattery
mikeslattery / ssh2config.sh
Last active May 20, 2024 13:13
Convert shell history or CLI args into ~/.ssh/config format.
#!/bin/bash
ssh2append() {
ssh -G "$@" | sed -n 's/^hostname /Host /p'
comm -23 <(ssh -G "$@" 2>/dev/null | sort) <(ssh -G . 2>/dev/null | sort) | sed 's/^/ /'
# This loop+if is for remote command, -N, -W as -G lacks support
while getopts '1246AaCfGgKkMNnqsTtVvXxYyB:b:c:D:E:e:F:I:i:J:L:l:m:O:o:p:Q:R:S:W:w:' opt; do
#shellcheck disable=SC2254
case "$opt" in
@mikeslattery
mikeslattery / rt-clip.sh
Last active August 1, 2020 02:12
Markdown to Clipboard
#!/bin/bash
# Converts markdown format to clipboard in html format.
# Requres Wayland, pandoc, and wl-clipboard.
# Usage:
# rt-clip - Copy from stdin
# rt-clip <file> Copy from a file
# rt-clip Copy from clipbaord
if [[ "$1" == "-" ]]; then shift; cat
@mikeslattery
mikeslattery / alpine-chroot.sh
Created April 30, 2020 15:37
Create a temporary Alpine chroo
#!/bin/sh
# Create and launch an alpine chroot
# If /tmp is not tmpfs, change this to /dev/shm
rootfs=/tmp/alpine
set -eu
if ! [ -f $rootfs/etc/resolv.conf ]; then
if ! [ -f ~/Downloads/alpine.tar.gz ]; then
curl -Lf -o ~/Downloads/alpine.tar.gz http://dl-cdn.alpinelinux.org/alpine/v3.11/releases/x86_64/alpine-minirootfs-3.11.6-x86_64.tar.gz
@mikeslattery
mikeslattery / init.gradle
Last active May 1, 2020 19:17
Build gradle projects to RAM
// This goes in ~/.gradle/init.d/tmpfs.gradle
def ramdir='/tmp/gradle'
gradle.projectsLoaded {
rootProject.allprojects {
buildDir = "${ramdir}${project.path}/build"
//println "${project.name}.buildDir = ${buildDir}"
}
@mikeslattery
mikeslattery / gc-mon.sh
Last active May 24, 2021 15:49
Monitor memory use of all running java applications
#!/bin/bash
# Display memory useage of all running java processes
pidof java | xargs -r ps -f
echo ''
echo $'PID\t% MEM\tTMEM\tGC Time'
while true; do
for pid in $(pidof java); do
echo -n "$pid "
@mikeslattery
mikeslattery / tunic-uml.dot
Last active May 24, 2021 15:57
Tunic Design
// Usage: dot -Tpdf -o tunic-uml.pdf tunic-uml.dot; xdg-open tunic-uml.pdf
digraph G {
Presenter -> View;
View [shape=box];
Presenter -> Service;
Service -> System;
@mikeslattery
mikeslattery / notify-send.ps1
Last active February 20, 2020 18:02
Windows Notification Toast
function notify($notificationTitle) {
$app = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[void][Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
# Fetch empty template
$templateType = [Windows.UI.Notifications.ToastTemplateType]::ToastText01
$template = [xml]([Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent($templateType).getXml())
#Convert to .NET type for XML manipuration
[void]$template.GetElementsByTagName("text").AppendChild($template.CreateTextNode($notificationTitle))
@mikeslattery
mikeslattery / shlint.sh
Created January 23, 2020 16:06
Lint shell scripts
#!/bin/bash
# Thorough syntax check for #!/bin/sh scripts.
# (For bash scripts, shellcheck by itself is enough)
set -eu
for f in "$@"; do
dash -n "$f" && \
shellcheck -x "$f" && \
@mikeslattery
mikeslattery / fake_dockerfile.sh
Last active February 19, 2021 15:16
Mock Dockerfile syntax for local testing
alias FROM='docker run -it --rm'
ADD() { curl -sLf "$1" -o "$2"; }
alias RUN='' ARG='' ENV='' CMD=''
alias LABEL=: EXPOSE=: ENTRYPOINT=: VOLUME=: ONBUILD=: STOPSIGNAL=: HEALTHCHECK=: SHELL=:
SHELL() { eval "export SHELL=$1"; }
alias WORKDIR=cd
USER() { sudo -u "$1" bash --init-file fake_dockerfile.sh; }