Skip to content

Instantly share code, notes, and snippets.

View erikw's full-sized avatar
💭
0b011111000110

Erik Westrup erikw

💭
0b011111000110
View GitHub Profile
@erikw
erikw / toggle_spell.vim
Created January 25, 2012 19:21
Toggle spellang in Vim.
" Toggle spell with a language. {{{
function! ToggleSpell(lang)
if !exists("b:old_spelllang")
let b:old_spelllang = &spelllang
let b:old_spellfile = &spellfile
let b:old_dictionary = &dictionary
endif
let l:newMode = ""
if !&l:spell || a:lang != &l:spelllang
@erikw
erikw / mpd_kde_notify.sh
Created February 24, 2012 22:22
NP from mpd in KDE
#!/bin/sh
# Announce current song playing in mpd in a KDE notification.
# Icon support for passivepopup is implemented in more recent versions of KDE.
#path=`mpc -f %file% | head -n1 | sed 's/\(.*\)\/.*\..\+$/~\/mult\/music\/\1/'`
#icon=`find $path -type f -iregex '.*\.\(png\|jpg\|jpeg\|gif\|bmp\)$' -print | head -n1`
#kdialog --icon "$icon" --title "Currently playing song" --passivepopup "$np" 3
#np=`mpc --format "%title%[\n%album%]\n%artist%" | head -n3`
np=`mpc --format "%title%[\n%album%]\n%artist%" | grep -Pzo '^(.|\n)*?(?=\[)'`
@erikw
erikw / bash_colors.sh
Created May 23, 2012 00:18
Bash ANSI colors
# Source this file where ANSI colors are needed. Colors in strings should be quoted with "" and echos needs to interpret backslash (echo -e).
# Reference: http://www.faqs.org/docs/Linux-HOWTO/Bash-Prompt-HOWTO.html#AEN341
function export_colors() {
# ANSI colors codes.
local DULL=0
local BRIGHT=1
local FG_NULL=00
local FG_BLACK=30
#!/usr/bin/env bash
trim_method="roll" # Can be {trim or roll).
max_len=30 # Trim output to this length.
roll_speed=2 # Roll speed in chraacters per second.
segment_path=$(dirname $0)
source "$segment_path/../lib.sh"
np="A pretty long line for a song title eh?"
np=$(roll_text "${np}" ${max_len} ${roll_speed})
@erikw
erikw / ladok_mean.sh
Created January 10, 2012 22:23
Get LADOK mean score from HTML-page(lang: en)
grep -Pzoi "(?<=>)[3-5G]&nbsp;</td>(\s*(?:\\n|<td[^>]*>[^<]*</td>))*\s*<\/tr>\s*<tr>\s*<td[^>]*>[^<]*</td>\s*<td[^>]*>examiner" < LADOK.HTML | grep -Pzoi "^[3-5G](?=&nbsp;</td>)" | sed -e 's/g/3/i' | awk 'BEGIN{sum=0;count=0}{sum+=$1;count++}END{print sum/count}'
@erikw
erikw / brew_ugprade.sh
Last active March 26, 2018 08:19
brew_upgrade.sh: interactively upgrade all local brew & cask packages for macOS
#!/usr/bin/env bash
# Interactively upgrade my homebrew system.
# Usage: brew_upgrade.sh
# Requirements:
# - Install cask upgrade command with: $ brew tap buo/cask-upgrade
# Exit script on SIGINT.
set -e
CLI_PREFIX="📦$(tput setaf 1) ======>$(tput sgr0)"

Keybase proof

I hereby claim:

  • I am erikw on github.
  • I am erikwestrup (https://keybase.io/erikwestrup) on keybase.
  • I have a public key whose fingerprint is D5EF DF01 3574 AE9B E834 3C32 7C16 B114 8E43 2F36

To claim this, I am signing this object:

@erikw
erikw / unlink_image_github_markdown.md
Last active October 12, 2021 10:22
How to prevent automatic image link in GitHub Markdown
@erikw
erikw / unimpaired-delete.vim
Last active October 17, 2021 14:06
vim-unimpaired extended with delete ([d and ]d)
" Extend vim-unimpaired with ]d and [d to delete above and below the current line.
" See https://github.com/tpope/vim-unimpaired/issues/157
"
" Installation: put this file in
" - vim: $HOME/.vim/plugin/
" - neovim: $XDG_CONFIG_HOME/nvim/plugin/
function! s:DeleteUp(count) abort
normal! m`
normal ix
@erikw
erikw / auto_dark_mode.py
Last active November 29, 2021 18:33 — forked from jamesmacfie/README.md
iTerm 2 - script to change theme depending on Mac OS dark mode
#!/usr/bin/env python3
import asyncio
import iterm2
async def main(connection):
async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.APP, "effectiveTheme", None) as mon:
while True:
# Block until theme changes
theme = await mon.async_get()