Skip to content

Instantly share code, notes, and snippets.

@mmrko
mmrko / repl.js
Last active June 20, 2023 08:08
Top-level await support for TypeScript REPL
// ... by wrapping the executed statement in an async IIFE
const repl = require("repl")
const wrapInAsync = (cmd) => {
if (!cmd.trim()) return ""
return `;(async () => {
return (
${cmd}
@mmrko
mmrko / slack-dark-mode.sh
Last active July 26, 2019 07:26 — forked from a7madgamal/dark.md
Dark Mode for Slack (macOS)
#!/usr/bin/env bash
# Homebaked Slack Dark Mode. After executing this script, hit refresh (⌘ + R) or restart Slack for changes to take effect.
# Adopted from https://gist.github.com/a7madgamal/c2ce04dde8520f426005e5ed28da8608
SLACK_RESOURCES_DIR="/Applications/Slack.app/Contents/Resources"
SLACK_SSB_INTEROP_FILEPATH="$SLACK_RESOURCES_DIR/app.asar.unpacked/src/static/ssb-interop.js"
THEME_FILEPATH="$SLACK_RESOURCES_DIR/dark-theme.css"
curl -o "$THEME_FILEPATH" "https://cdn.rawgit.com/laCour/slack-night-mode/master/css/raw/black.css"
@mmrko
mmrko / docker-prune.sh
Last active September 3, 2021 08:42
Prune stale Docker containers, images & volumes (Bash) (versions < 1.13.0)
#!/usr/bin/env bash
stale_images=`docker images --no-trunc --quiet --filter "dangling=true"`
stale_containers=`docker ps --no-trunc --quiet --filter "status=exited"`
stale_volumes=`docker volume ls --quiet --filter "dangling=true"`
stale_images_count=`echo "$stale_images" | sed '/^\s*$/d' | wc -l | xargs`
stale_containers_count=`echo "$stale_containers" | sed '/^\s*$/d' | wc -l | xargs`
stale_volumes_count=`echo "$stale_volumes" | sed '/^\s*$/d' | wc -l | xargs`
echo "Removing stale containers..."
@mmrko
mmrko / git-zsh-checkout-autocomplete-local-only.md
Last active July 20, 2023 08:48
List only local branches when autocompleting git checkout (Zsh)
git config --global alias.checkoutr checkout
$EDITOR /usr/local/share/zsh/site-functions/git-completion.bash

...and then modify the file as follows...

-__gitcomp_nl "$(__git_refs '' $track)"
+if [ "$command" = "checkoutr" ]; then
+    __gitcomp_nl "$(__git_refs '' $track)"
+else
@mmrko
mmrko / save-load-docker-images.sh
Last active January 30, 2023 10:23 — forked from lalyos/save-all-images.sh
Script to (selectively) save/load multiple Docker images
#!/usr/bin/env bash
# Script to (selectively) save/load multiple Docker images to/from a directory.
# Run ./save-load-docker-images.sh for help.
set -e
directory=$PWD
filter=""
compress=0
@mmrko
mmrko / git-add-no-whitespace.sh
Last active March 14, 2023 21:09
git add files ignoring whitespace
# props: https://stackoverflow.com/questions/3515597/add-only-non-whitespace-changes#answer-7149602
git diff -U0 -w --no-color | git apply --cached --ignore-whitespace --unidiff-zero
@mmrko
mmrko / ampersand-mock-sync.js
Last active August 10, 2016 08:12
Mock AmpersandJS sync for tests (Mocha & Sinon)
import BaseModel from 'ampersand-model'
import BaseCollection from 'ampersand-collection'
import sync from 'ampersand-sync'
const xhrImplementation = xhrOptions => {
xhrOptions.success && xhrOptions.success.call(null, {})
return {}
}
BaseModel.prototype.sync = BaseCollection.prototype.sync = (method, model, options = {}) => {
@mmrko
mmrko / mocha-react-css-modules.js
Last active January 1, 2024 00:15
Mocha & React & CSS Modules with Sass
// setup.js
import hook from 'css-modules-require-hook'
import sass from 'node-sass'
hook({
extensions: [ '.scss' ],
preprocessCss: data => sass.renderSync({ data }).css
})
git log -L 15,23:filename.txt # evolution of lines 15-23 in filename.txt