Skip to content

Instantly share code, notes, and snippets.

View jglodek's full-sized avatar

Jacek Głodek jglodek

  • Iterators
  • Warsaw, Poland
View GitHub Profile
@jglodek
jglodek / gist:04fa484833b9c6d5a3d2be9cb43ae312
Last active March 19, 2019 17:23
How to create SSH tunnel for docker and docker for mac to private docker registry secured by SSH tunnel not TLS
//Super straightforward on Linux
sudo ssh -N -o StrictHostKeyChecking=no \
-i ./certs/output/ssh-private-key \
user@private.host \
-L 5000:127.0.0.1:5000
docker login localhost:5000 --username registry_user --password registry_password
// On Docker for Mac docker virtual machine has it's own 127.0.0.1 and can access your macbook localhost only via `host.docker.internal`
@jglodek
jglodek / gist:049143b8dd938932584507a3fde4e630
Created July 17, 2018 07:59
Generating a list of days before today in Javascript | Sequence of days in Javascript | Date Sequence
function sequence(number) { return Array.apply(null, {length: number}).map(Function.call, Number);};
const begin = moment("2018.05.05", "YYYY.MM.DD");
const today = moment();
const daysCount = moment().diff(begin, "days");
const days = sequence(daysCount + 1).map((dayNo) => {
return moment(today).subtract(dayNo, "days").format("YYYY.MM.DD");
})
@jglodek
jglodek / gist:fcdda60088e8adad51ef038872a77a1b
Created July 17, 2018 15:08
Recovering files from stopped docker containers | Docker Container Stopped | Rescue | Recovery
list files
docker ps -a
commit data to images
docker commit 91ea7799154c user/test_image1
docker commit e68f87d44923 user/test_image2
docker commit 439177e1f838 user/test_image3
docker commit 1fbf94e114ff user/test_image4
@jglodek
jglodek / gist:fd4f03601739d6567b5a50dbfefdf745
Last active August 18, 2018 11:46
lame getting project version text from build.sbt SBT file for interpolation
$(cat build.sbt | grep '[ \t]*version :=' | sed 's/.*"\(.*\)".*/\1/')
@jglodek
jglodek / gist:ea8e8ff961e1fb780499a93dfb820ba8
Last active August 17, 2018 22:37
getting project version text from package.json file for interpolation
$(cat package.json | grep "version" | sed 's/.*"\(.*\)".*/\1/')
or
$(node -p "require('./package.json').version")
if you have node (not the case for some docker images)
# ./p.bin is /opt/docker/p.bin
# 1 is the PID of java
jmap -dump:format=b,file=./p.bin 1
docker cp <containerId>:/file/path/within/container /host/path/target
docker cp <containerId>:/opt/docker/p.bin .
scp -o StrictHostKeyChecking=no -i $(echo $ssh_private_key_location) user@example.com:/home/core/p.bin .
@jglodek
jglodek / NGINX_DEBUG.sh
Last active May 20, 2020 20:00
NGINX REWRITE DEBUG SETUP
#We're creating a nginx + a ECHO SERVER
# in nginx we play around the config
# echo server will show us the WYMIWYG (WHAT YOU MEAN IS WHAT YOU GET) when we do requests to the nginx
# run containers for debug
docker run --detach --name nginx -p 80:80 nginx
docker run --detach --name echo -P jmalloc/echo-server
# enter the server
docker exec -ti nginx bash
@jglodek
jglodek / gist:f7b8abd552131fc54ed6a60e42c64a44
Last active December 2, 2020 08:36
ICLOUD NODE_MODULES .NOSYNC - Stop synchronizing node_modules Mac Documents
# find icloud files
cd $HOME/Library/Mobile Documents/com~apple~CloudDocs
# test run crontab
find $HOME/Library/Mobile\ Documents/com\~apple\~CloudDocs -type d -name node_modules -exec touch {}/.nosync \;
# add crontab with vim so it runs every couple of hours
EDITOR=vim crontab -e
0 */2 * * * find $HOME/Library/Mobile\ Documents/com\~apple\~CloudDocs -type d -name node_modules -exec touch {}/.nosync \;
@jglodek
jglodek / gist:87f6d040efbddfc2ad293f039d330365
Created December 17, 2020 20:30
Upload any file with copy paste
uploadify() {
echo "echo '"${$(cat $1 | base64)}${$(echo "' | base64 --decode > $1")}
}
#usage uploadify logo.png
#copy + paste on any terminal anywhere in the interwebs
#command that says battery low if <8%
ioreg -l |awk 'BEGIN{FS="=";max=0;cur=0;} $1~/CurrentCapacity/{cur=$2} $1~/MaxCapacity/{max=$2} END{if (cur/max*100<8) {"say battery low" | getline result} else {print "battery OK"}}'
#crontab editor
crontab -e
#crontab entry that does this once every 60s
* * * * * ioreg -l |awk 'BEGIN{FS="=";max=0;cur=0;} $1~/CurrentCapacity/{cur=$2} $1~/MaxCapacity/{max=$2} END{if (cur/max*100<8) {"say battery low" | getline result} else {print "battery OK"}}'