Skip to content

Instantly share code, notes, and snippets.

@smrchy
Forked from mpneuried/cron.sh
Created February 10, 2016 13:31
Show Gist options
  • Save smrchy/eb2ca4388f73e4ee789b to your computer and use it in GitHub Desktop.
Save smrchy/eb2ca4388f73e4ee789b to your computer and use it in GitHub Desktop.
bash helpers
# SYSTEM: open a file as admin with a special app
sudo open -a /Applications/Utilities/Console.app/ /usr/local/mysql/data/Mathiass-iMac.log
# SYSTEM: Create a symbolic link
ln -s /Path/to/original/folder New-folder-name
# SYSTEM: show long running clock
clear; while true; do echo -e \\b\\b\\b\\b\\b\\b\\b\\b`date +%T`\\c ; sleep 1; done
# SYSTEM: Set ENV var
export FOO=42
# SYSTEM: copy files by regex pattern. E.g. copy only jpegs with odd numbers
find . -type f | grep -i "[13579].jpg" | xargs -I{} cp {} ../test_cp/{}
find ./src/folder -type f | grep -i "regexp" | xargs -I{} cp {} ../target/folder/{}
# NETWORK: find a process listening to a specific port
sudo lsof -i TCP:$PORT | grep LISTEN
# NETWORK: limit network conncetion
ipfw pipe 1 config bw 64KByte/s # Pipe erstellen, die nur 64kB/s durchlässt
ipfw add 1 pipe 1 src-port 80 # Pipe an den Sourceport 80 binden
ipfw delete 1 # Pipe wieder löschen
# CRON: crontab header to run node and grunt within a cron job
#!/bin/sh
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# SYSTEM: Run a script (eg.g imagemagick convert ) for a bunch of files by regex
PREFIX=$2
SIZE=$1
for main in `seq 1 36`; do
ls | grep -e "Uebung$main[A-C]*.jpg" | xargs echo | xargs -I "{}" sh -c "convert -delay 75 -resize $SIZE {} $PREFIX$main.gif"
echo "$PREFIX$main.gif created"
done;
# NODE: run grunt with debugger
node-debug $(which grunt) task
# REDIS: Redis delete by wildcard
~/local/redis/redis-cli KEYS "prefix:*" | xargs ~/local/redis/redis-cli DEL
# GM (GraphicsMagick): place a image inside another image.
# place it to position x:200px, y:200px with a width of 50px
gm convert -page +0+0 ./source.jpg -resize 50 -page +200+200 ./placement.png -mosaic ./output.jpg
# GIT: rename a git branch
git branch -m oldname newname
git push origin newname
git push origin :oldname
# GIT: remove a remote tag
git tag -d __tagname__
git push origin :refs/tags/__tagname__
# GIT: create github repo from folder
cd <localdir>
git init
git add .
git commit -m 'message'
git remote add origin <url>
git push -u origin master
# GIT: reset to head
git fetch origin
git reset --hard origin/master
# NODE.js: fix LIFECYLE Error
# ld: library not found for -lgcc_s.10.5
# clang: error: linker command failed with exit code 1
cd /usr/local/lib
sudo ln -s ../../lib/libSystem.B.dylib libgcc_s.10.5.dylib
# Start node with a defined obj-memory limit.
# This means a limit for the generated data inside the process.
# You have to add the used memory of the runtime and code to get the real memory usage.
# Default is 1,4GB - https://github.com/nodejs/node-v0.x-archive/wiki/FAQ#what-is-the-memory-limit-on-a-node-process
# e.g.: 100b
node --max-old-space-size=100 index.js
#NPM list the latest versions of dependencies
echo ".dependencies"; jq ".dependencies|keys|.[]" package.json -r | xargs -I{} npm info {} -j | jq "{(.name):.version}" -c -r;echo ".devDependencies"; jq ".devDependencies|keys|.[]" package.json -r | xargs -I{} npm info {} -j | jq "{(.name):.version}" -c -r;
#Docker: set machine ip to env
export DOCKERLOCALHOST=`docker-machine ip default`
# MISC: convert all m4a files to mp3 for all subfolders (brew packages: ffmpeg, rename)
# convert to mp3
find . -name "*.m4a" -exec ffmpeg -i {} -acodec libmp3lame -ab 320k "{}.mp3" \;
# rename
find . -name "*.m4a.mp3" -exec rename -s ".m4a.mp3" ".mp3" {} \;
# delete m4a files
find . -name "*.m4a" -exec rm {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment