Skip to content

Instantly share code, notes, and snippets.

@kylechui
kylechui / dot-repeating.md
Last active October 23, 2024 10:55
A basic overview of how to manage dot-repeating in your Neovim plugin, as well as manipulate it to "force" what action is repeated.

Adding dot-repeat to your Neovim plugin

In Neovim, the . character repeats "the most recent action"; however, this is not always respected by plugin actions. Here we will explore how to build dot-repeat support directly into your plugin, bypassing the requirement of dependencies like repeat.vim.

The Basics

When some buffer-modifying action is performed, Neovim implicitly remembers the operator (e.g. d), motion (e.g. iw), and some other miscellaneous information. When the dot-repeat command is called, Neovim repeats that operator-motion combination. For example, if we type ci"text<Esc>, then we replace the inner contents of some double quotes with text, i.e. "hello world""text". Dot-repeating from here will do the same, i.e. "more samples""text".

Using operatorfunc

@nrnrnr
nrnrnr / assoc.lua
Created February 18, 2022 21:53
Lua code for association lists on the command line (for use with fish)
#!/usr/bin/env lua5.1
-- assocation list on the command line
--
-- rep is: key1 val1 key2 val2 ...
--
local function succeed(s)
if s ~= true then
io.stdout:write(s, '\n')
@NotTheDr01ds
NotTheDr01ds / fish_load_sudo_alias.fish
Created December 27, 2021 02:46
Fish `sudo` replacement function
function fish_load_sudo_alias
function sudo
if functions -q -- "$argv[1]"
# Create a string which quotes each of the original arguments
# so that they can be safely passed into the new fish
# instance that is called by sudo.
set cmdline (
for arg in $argv
printf "\"%s\" " $arg
end
@tommyip
tommyip / venv.fish
Last active November 12, 2024 18:03
venv.fish - Automatically activate/deactivate virtualenv in fish shell
# Based on https://gist.github.com/bastibe/c0950e463ffdfdfada7adf149ae77c6f
# Changes:
# * Instead of overriding cd, we detect directory change. This allows the script to work
# for other means of cd, such as z.
# * Update syntax to work with new versions of fish.
# * Handle virtualenvs that are not located in the root of a git directory.
function __auto_source_venv --on-variable PWD --description "Activate/Deactivate virtualenv on directory change"
status --is-command-substitution; and return
@m-radzikowski
m-radzikowski / script-template.sh
Last active November 15, 2024 11:25
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
@jvanlier
jvanlier / fast.ai-vision-raspberry-pi-4.md
Last active September 8, 2022 04:45
fast.ai for vision on Raspbery pi 4 (Raspbian)

By default, PyTorch team doesn't release packages for ARM architecture. Luckily, someone is supplying unofficial builds (hats off to this person!).

Fast.ai also has a problem: it depends on spaCy, which also doesn't want to build on ARM by default. I'm not going to do NLP, so will install fast.ai without spaCy.

PyTorch

I initially tried using ARM builds from here:

https://github.com/nmilosev/pytorch-arm-builds

@3v1n0
3v1n0 / fish-shell-bash-complete-function.sh
Last active November 15, 2024 12:02
Use bash completions in Fish Shell
#!/usr/bin/fish
# You can add this to your ~/.config/fish/config.fish
function __fish_complete_bash
set cmd (commandline -cp)
bash -c "source get-bash-completions.sh; get_completions '$cmd'"
end
# Set the tool to use bash completions
@oisinmulvihill
oisinmulvihill / assert_not_raises.py
Created August 4, 2019 12:58
How to test a python exception is not raised with pytests
# Updated for python3
#
# https://stackoverflow.com/questions/20274987/how-to-use-pytest-to-check-that-error-is-not-raised/35458249#35458249
#
from contextlib import contextmanager
@contextmanager
def not_raises(ExpectedException):
try:
@santiagobasulto
santiagobasulto / README.md
Last active October 3, 2024 18:36
Download HumbleBundle books in batch with a simple Python script.

Download HumbleBundle books

This is a quick Python script I wrote to download HumbleBundle books in batch. I bought the amazing Machine Learning by O'Reilly bundle. There were 15 books to download, with 3 different file formats per book. So I scratched a quick script to download all of them in batch.

(Final Result: books downloaded)

from __future__ import division
import cv2
import numpy as np
import matplotlib.pyplot as plt
import os
os.chdir('C:/Users/gennady.nikitin/Dropbox/Coding/OpenCV')
# define variable for resize tratio
ratio = 1