Skip to content

Instantly share code, notes, and snippets.

@mmrko
mmrko / repl.js
Last active Aug 20, 2020
Top-level await support for TypeScript REPL
View repl.js
// ... 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 Jul 26, 2019 — forked from a7madgamal/dark.md
Dark Mode for Slack (macOS)
View slack-dark-mode.sh
#!/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 Aug 19, 2019
Prune stale Docker containers, images & volumes (Bash) (versions < 1.13.0)
View docker-prune.sh
#!/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 Aug 31, 2020
List only local branches when autocompleting git checkout (Zsh)
View git-zsh-checkout-autocomplete-local-only.md
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 Apr 20, 2020 — forked from lalyos/save-all-images.sh
Script to (selectively) save/load multiple Docker images
View save-load-docker-images.sh
#!/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 Jun 29, 2020
git add files ignoring whitespace
View git-add-no-whitespace.sh
# 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 Aug 10, 2016
Mock AmpersandJS sync for tests (Mocha & Sinon)
View ampersand-mock-sync.js
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 Dec 28, 2018
Mocha & React & CSS Modules with Sass
View mocha-react-css-modules.js
// setup.js
import hook from 'css-modules-require-hook'
import sass from 'node-sass'
hook({
extensions: [ '.scss' ],
preprocessCss: data => sass.renderSync({ data }).css
})
View git.sh
git log -L 15,23:filename.txt # evolution of lines 15-23 in filename.txt
You can’t perform that action at this time.