Skip to content

Instantly share code, notes, and snippets.

View pbeardshear's full-sized avatar

Peter Beardshear pbeardshear

View GitHub Profile
@pbeardshear
pbeardshear / docker-cleanup-resources.md
Created May 4, 2020 01:39 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

#!/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
@pbeardshear
pbeardshear / expand.js
Created May 17, 2015 07:27
Object expansion from string
// out => {}
// path => dot-separated property string
//
// Example:
// path = 'prop.other.name'
// out => { prop: { other: { } } }
//
// Returns the innermost nested object (the object that name would be a property of)
function expand(out, path) {
var parts = path.split('.').slice(0, -1);
@pbeardshear
pbeardshear / reset_proj.py
Created August 4, 2014 23:31
Reset all those pesky .csproj files when attaching to w3wp process..
#!/bin/python
from subprocess import call, check_output
out = check_output(['git', 'status', '-s'])
lines = [l.strip().split(' ')[1] for l in out.splitlines()]
for line in lines:
if '.csproj' in line:
@pbeardshear
pbeardshear / super_diff.py
Created August 4, 2014 23:30
Git diff with pattern matching
#!/bin/python
#
# Super Diff!
import sys
from subprocess import call, check_output
from fnmatch import fnmatch
pattern = '*'
if len(sys.argv) > 1:
@pbeardshear
pbeardshear / stream_adventure.js
Created May 31, 2014 21:05
Solution file to the stream-adventure game. (https://github.com/substack/stream-adventure)
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 1. BEEP BOOP
// console.log('beep boop');
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 2. MEET PIPE
// var fs = require('fs'),
// file = process.argv[2];
// Given a mac address, returns the IP address of the device (inverse of the arp command)
// Usage: node inversearp.js <mac_address>
//
var exec = require('child_process').exec;
var mac_address = formatAddress(process.argv[2]);
var ip_pattern = /\d+\.\d+\.\d+\.\d+/
exec('arp -a', function (error, stdout, stderr) {
var lines = stdout.split('\n');
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@pbeardshear
pbeardshear / format.js
Last active December 29, 2015 01:39
String.Format in JavaScript.
function format(template) {
var args = Array.prototype.slice.call(arguments, 1);
for (var i = 0; i < args.length; i++) {
var regex = new RegExp('\\{' + i + '\\}', 'g');
template = template.replace(regex, args[i]);
}
return template;
}