Skip to content

Instantly share code, notes, and snippets.

View UrsaDK's full-sized avatar

Dmytro Konstantinov UrsaDK

View GitHub Profile
@UrsaDK
UrsaDK / Terminal integration with macOS appearance.md
Last active June 2, 2023 05:35
Make command line tools respect macOS appearance

MacOS dark mode & command line tools

  1. Beta version of iTerm2 has built-in support for system appearance and will change themes in sync with macOS;
  2. Setup dark-mode-notify to launch on start and call a custom shell script (eg: appearance-change.sh) when appearance changes;
  3. Update the script as required

NOTE:

  • neovim v0.8.0+ can issue self referencing commands. For example, try putting this into your init.lua to prevent nested vim instances when using built-in terminal:
    vim.env.EDITOR = string.format('nvim --server %s --remote --', vim.api.nvim_get_vvar('servername'))
@UrsaDK
UrsaDK / Caching multi-stage builds in GA.md
Last active March 28, 2024 07:16
Speed up your multistage builds in GitHub Actions

Caching multi-stage builds in GitHub Actions

Caching Docker builds in GitHub Actions is an excellent article by @dtinth which analyses various strategies for speeding up builds in GitHub Actions. The upshot of the article is a fairly decisive conclusion that the best two ways to improve build times are:

  1. Build images via a standard docker build command, while using GitHub Packages' Docker registry as a cache = Longer initial build but fastest re-build times.

  2. Build your images via docker integrated BuildKit (DOCKER_BUILDKIT=1 docker build), while using a local registry and actions/cache to persist build caches = Fastest initial build but slightly longer re-build times.

The problem

@UrsaDK
UrsaDK / github-environment-cleaner.sh
Last active May 14, 2020 18:46
How to remove the "environment" tab from a Github repo
#!/usr/bin/env bash
#
# Remove Project Environment artefacts from a Github project: This script
# can be used to remove all "environment" artefacts from a project that,
# for example, no longer uses github-pages. Doing so would also remove the
# "environment" tab from the Github repository.
#
# The script requires for `curl` and `jq` to be in your PATH. You will also
# need to define a personal access token with `repo_deployment` scope on
# Github, and update the values of API_URL_BASE and ACCESS_TOKEN bellow.
@UrsaDK
UrsaDK / Letter to Apple.md
Last active April 16, 2020 17:40
How to set @icloud.com mail alias as your Apple ID?

Dear @Apple,

Please allow us to rename existing @icloud.com Apple IDs to a mail aliases defined on the same account (that's the additional email address defined via the Preferences pane of the Mail app on icloud.com).

An Apple account is identified by its Apple ID, which for a long standing account, has a lot of information associated with it. However, an account handle set up years ago can become irrelevant over time (people get married, change their names, etc).

We already can define Mail aliases for existing Apple IDs. These aliases are used with Mail, Messages and Facetime... but not when we share content via the share button/menu (ie: if you share a note or a reminder with someone the content will be shared using your Apple ID).

Currently, the only way to fix this is to create a brand new Apple ID, and then migrate all of your existing content to that Apple ID. However, this is not an acceptable solution to many people.

@UrsaDK
UrsaDK / How to fix macOS VirtualBox install failure.md
Last active April 16, 2020 17:35
How to recover from VirtualBox installer failure on macOS host

I find that every now and again VirtualBox glitches out and fails to install (or update) on macOS. This has happened to me a few times now, and every single time it's because Apple security policies prevent VirtualBox kernel extensions from being loaded.

Screenshot of the failed install

Attempt 1 of 2: Start with OSXDaily fix: check your "System Preferences > Security & Privacy > General". There might be a discreet note in the lower part of the window saying that kernel extensions from the developer Oracle could not be loaded and an option to whitelist them by clicking on the "Allow" button. Done! :)

@UrsaDK
UrsaDK / docker-clean.sh
Last active November 4, 2016 12:26
Reclame space used up by Docker on macOS
#!/usr/bin/env bash
echo "Removing unused containers ..."
docker ps --filter status=dead --filter status=exited -aq | xargs docker rm -v
echo
echo "Removing unused images ..."
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs docker rmi
echo
@UrsaDK
UrsaDK / unaccent.sql
Last active April 16, 2020 17:47
Replace musicbrainz_unaccent with pgsql's unaccent extension
/**
* MusicBrainz (http://musicbrainz.org) comes with a custom unaccent pgsql extension (musicbrainz_unaccent).
* However, AWS PGSQL service does not include this extension and it can not be easilly added.
*
* The following code duplicates musicbrainz_unaccent functionality using the built in unaccent extension.
*/
CREATE EXTENSION unaccent;
CREATE OR REPLACE FUNCTION musicbrainz_unaccent(txt text) RETURNS text AS $$
BEGIN
@UrsaDK
UrsaDK / Strip trailing space in Vim.md
Last active April 5, 2023 17:11
A function to remove trailing spaces from Vim buffers

I've been maintaining my own version of Strip Trailing Spaces function (attached at the bottom of this post) since I first started using vim. It grew out of a simple :%s/\s*$// and now includes a number of features:

  • it preserves search history and the last search string
  • it doesn't change editor's '', '. and '^ marks
  • it doesn't add a new jumplist and changelist record
  • it preserves editor's view and cursor position

However, over the years I've noticed that I never needed to undo the results of stripping trailing spaces from a file. In fact, I would go as far as to say that when undoing changes in a file, the function produces an understandable but somewhat undesirable cursor jump (to the top-most trailing space it strippes) which disrupts my work flow. So, I set about to exclude the results of this function from the undo history all together.

After reading [Restore the cursor position after undoing text change made by a script](http://vim.wikia.com/wiki/Restore_the_cursor_position_aft

@UrsaDK
UrsaDK / TreeFind.vim
Last active February 3, 2019 06:19
Project structure discovery with Vim & NERDTree
""
" Return project's root directory
"
" This function is used to return current projects root directory, as
" determined by GIT or SVN, without changing vim's cwd.
"
" @param string a:1 A comma seperated list of files or directories, the
" presence of which can be used to identify the root directory of a project.
"
function! UmkaDK#GetProjectRoot(...)