This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# chunk array to string | |
private *arr2chunks(arr: any[], n: number) { | |
for (let i = 0; i < arr.length; i += n) { | |
const str = JSON.stringify(arr.slice(i, i + n)) | |
const open = i === 0 ? '[':''; | |
const close = n*(i+1) < arr.length ? ',' : ']'; | |
yield `${open}${str.slice(1, str.length-1)}${close}`; | |
} | |
yield null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NETWORK=$1 | |
docker network inspect $NETWORK -v | jq -r '.[0] .Services | to_entries[] | .key' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git reset --hard && git checkout master && git branch | grep -v "^..master$" | xargs git branch -D && git pull | |
# add to ~/.bash_profile | |
# alias git-reset-master='git reset --hard && git checkout master && git branch | grep -v "^..master$" | xargs git branch -D && git pull' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker run --rm -it --pid host frapsoft/htop | |
# sort by CPU: Shift + P | |
# sort by Memory: Shift + M | |
# collapse threads: Shift + H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
SERVICES=$(docker service ls --format '{{print .Name}}') | |
for SERVICE in $SERVICES; do | |
IDS=$(docker service ps $SERVICE -f "desired-state=shutdown" | grep Running | awk '{print $1;}') | |
if [ -n "$IDS" ]; then | |
echo $SERVICE | |
fi | |
for ID in $IDS; do | |
TASK=$(docker inspect $ID | sed -n 's/.*\"ID\": \"\(.*\)\".*/\1/p' | awsk '{print $1; exit}') | |
docker run --rm -v /var/run/docker/swarm/control.sock:/var/run/swarmd.sock dperny/tasknuke $TASK | sed 's/^/ - /' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# loop through services and get names | |
for SERVICE in $(docker service ls --format "{{.Name}}"); do | |
# get the full image:tag@sha used by the service | |
IMAGE=$(docker service inspect $SERVICE --format "{{.Spec.TaskTemplate.ContainerSpec.Image}}") | |
# try image pull and capture error for printing | |
ERROR="$(docker pull -q $IMAGE 2>&1 > /dev/null)" | |
if [[ ! -z $ERROR ]]; then | |
printf "$SERVICE: $IMAGE\n\t$ERROR\n" | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -a; source .env; set +a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var str = '%\\|_'; | |
var test = str.replace(/[%_\\|]/g, '\\$&'); | |
console.log(test); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.2.1/lodash.min.js" type="text/javascript" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Fibonacci 0.0.1 */ | |
/** | |
* Fibonacci | |
* | |
* @author Ryan Jones <rjchicago@gmail.com> | |
* @license The MIT license. | |
* @copyright Copyright (c) 2010 RJChicago <rjchicago@gmail.com> | |
*/ | |
// Fibonacci sequence = 0, 1, 1, 2, 3, 5, 8, 13, 21... |
NewerOlder