Bash
collection of hints for the easier use of cygwin
some better package-manager than via that set-up.exe: apt-cyg!
url: https://github.com/transcode-open/apt-cyg
=================================================
make shell-scripts runnable under Win (7):
add to the first line after “#!/bin/bash”
1 |
(set -o igncr) 2>/dev/null && set -o igncr; |
else you get the error message that “\r” is not a command … ha
=================================================
how to use proxy for firewalled use:
1 |
export http_proxy=http://username:password@host:port/ |
Maybe more will be added. All just small, but fixing tricky
shell-script to clean a project
I like to decorate the code with some debugging-messages, explicit variables, etc. while developing a feature or fixing a bug. Problem is that other team-members will not like that (or the amount ;)).
So, I commit the current state with Git and then remove all lines marked with the comment “// todoM”. Since this some non-creative work, why not automate it?
Code for the bash-script now on github: https://github.com/marcelpetrick/cleanMyCode 🙂
Further improvements like massive parallelization planned!
edith 20170619:
The fourth version relies now on some exported bash-function, so that GNU parallel can be used to speed up the process by parallelizing the search&replace inside the file- (-list given by find).
This helps, just I/O is now the bottleneck. CPU-speed not.
But I’ve always wanted to experiment with “parallel” and see how to use this. I should improve the “contactSheet”-script as well. Or the cat-cam-script .. endless opportunities ..
Get rid of the master-branch @ github
issue:
1 2 3 4 5 6 |
$ git push origin --delete master Username for 'https://github.com': marcelpetrick Password for 'https://marcelpetrick@github.com': To https://github.com/marcelpetrick/PiCamGifForTumblr.git ! [remote rejected] master (refusing to delete the current branch: refs/heads/master) error: failed to push some refs to 'https://github.com/marcelpetrick/PiCamGifForTumblr.git' |
solution:
- create a fake branch and push it
- go to
github > $your_repo > settings > branches > default branch
and make the fake branch the current one - delete master
- push new master
- revert the default branch
share a folder via SMB on CLI
The missing counter-part for this post.
- create new smb-user pi: “
$ sudo smbpasswd -a pi
“ - create directory: “
$ mkdir freigabeATminipc
“ - set rights: “
$ sudo chmod 770 freigabeATminipc/
“ - edit config: “
$ sudo nano /etc/samba/smb.conf
”
add at end of the file the following and save-quit (CTRL+X; y)
1 2 3 4 5 6 7 |
[freigabeATminipc] comment = for sharing path = /home/pi/Desktop/freigabeATminipc valid users = pi browseable = yes read only = no guest ok = yes |
- restart: “
$ sudo service smbd restart
“ - check if everything fits: “
$ testparm
“
mount a smb-share (not via fstab!)
Don’t know how often I did this on several systems and still always(!) have to pick the parameters.
1 2 3 |
$ sudo apt-fast install samba samba-common smbclient cifs-utils $ mkdir freigabeATminipc $ sudo mount -t cifs -o user=guest //MINIPC/freigabe freigabeATminipc/ |
Check for available shares in the network via “smbtree”.
Estimate quickly the ‘size’ of the project
Nothing in comparison to SLOCCount or other tools, but sometimes you just need a ‘value‘ 😉
1 |
find . -regex ".*\.\(h\|cpp\)" | sort | xargs wc -l |
103 ./main.cpp
90 ./map.cpp
35 ./map.h
63 ./mapitem.cpp
29 ./mapitem.h
122 ./mapprocessor.cpp
27 ./mapprocessor.h
79 ./mapreader.cpp
23 ./mapreader.h
571 total
edith 20160819: sort the result before counting for a much nicer appearance 😉
weather-forecast without annoying advertisments
1 |
curl http://wttr.in/hamburg |
Sounds from the underground
Found a one-liner which uses input from urandom to create music. And: I’ve experienced worse musical accentuation in games xD
1 |
cat /dev/urandom | hexdump -v -e '/1 "%u\n"' | awk '{ split("0,2,4,5,7,9,11,12",a,","); for (i = 0; i < 1; i+= 0.0001) printf("%08X\n", 100*sin(1382*exp((a[$1 % 8]/12)*log(2))*i)) }' | xxd -r -p | aplay -c 2 -f S32_LE -r 16000 |
Original source is that blog. Also offers explanations and how to tune the scale. Great!
Procrasticoding: annotate animated GIFs (or even add a picture/watermark)
The sun rose, the cats were watching the birds on the windowsill and at first I just wanted to take a cute picture of them sitting soo close, but then I had another inspiration ..
0. Prepared the logo from some internetsearch; stripped of colors, converted to 3-color-GIF with transparency: all done by GIMP and some magic.
1. converted the video to GIF with greyscaling and resizing
2. merged the two pictures while optimizing the layers and applying some contrast
1 2 3 |
ffmpeg -i VID_20160420_061216.mp4 -vf scale=320:180 -strict -2 -vf format=gray video_gray.mp4 && \ ffmpeg -i video_gray.mp4 -t 3 -b:v 1024k -vf scale="320x180" gray320.gif && \ convert gray320.gif -contrast -coalesce -gravity SouthWest -draw 'image Over 0,0 0,0 "leben2.gif"' -layers Optimize combined320.gif |
BTW: sometimes empty phrase-error messages spark my fury … “convert.im6: non-conforming drawing primitive definition `image’ @ error/draw.c/DrawImage/3158.
” … and what does this tell me now?!?
But at least I am not the first one who understood nothing! Thank you.
doEis.sh: convert all negatives via negfix8
reason: too lazy to call the negfix8-script for each file itself. Because conversion is fast but even with an SSD writing the ~120 MiByte files takes some time. Precious time ..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#!/bin/bash # author: Marcel Petrick (mail@marcelpetrick.it) # date: 20160415 # license: GNU General Public License, version 2 ( http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html ) echo "############################ start of the script ############################" #handle the issue with filenames with spaces SAVEIFS=$IFS IFS=$(echo -en "\n\b") #needed for the call of negfix8 SKRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) ALLFILES=`ls *.tif` #get all files inside the current folder which fit by suffix WORKINGDIR="negfix8Output" #todo: maybe add a check if the directory already existed .. mkdir $WORKINGDIR for FILE in $ALLFILES do CLEANEDNAME="${FILE// /_}" #also alter the original-input-name by replacing all spaces echo "will work now on #$FILE# and save as #$CLEANEDNAME#" #print current file name FULLPATH=$WORKINGDIR"/"$CLEANEDNAME".png" #convert /bin/bash $SKRIPTDIR/negfix8.sh -cs $FILE $FULLPATH done printf "############################ end of the script ############################\n" |
ps. ‘do eis’ is latin, not some german-english mumble jumble.