Skip to content

Instantly share code, notes, and snippets.

View zipizap's full-sized avatar

zipizap

View GitHub Profile
@zipizap
zipizap / gist:7947933
Last active December 31, 2015 06:29
Understanding better strace, in order to write up a good reply to C Evans comment :)
#
# This gist is related to C Evan's comment on
# http://zipizap.wordpress.com/2012/10/15/xkl-ubuntu-install-resizing-ntfs-partition-takes-too-long-check-ntfsresize-from-console-with-strace/
#
# Hi Evans :)
#
# I see what you mean: only strace the writes to stdout, and not all writes that
# also contain moved data of the resize... And it got me interested in better understanding
# the strace options, so I did a little "man strace" study and then a little program in C
red@ownc:/tmp$ cat a.sh
#!/bin/bash
# Activate debug
set -x
echo "hi"
ls
pwd
@zipizap
zipizap / du_sort.sh
Created December 10, 2013 10:04
Solaris "du" does not have the option "--max-depth=1", and this simple script eases a little bit of that pain... Output is shown in Kb and sorted by size
du -k . | egrep -v '\/.*\/' | sort -n
#!/bin/bash
[[ -r $1 ]] || { echo "Usage: $0 <videofile-to-be-resized> [<videofile2> ...]"; exit 1; }
for INPUT_FILE in $@; do
OUTPUT_MP4_FILE=$(echo $INPUT_FILE | sed 's/\.[^.]*$/.mp4/g')
#See https://trac.ffmpeg.org/wiki/x264EncodingGuide
avconv -y -i $INPUT_FILE -threads auto -c:v libx264 -preset medium -b:v 988k -pass 1 -an -f mp4 /dev/null && \
avconv -i $INPUT_FILE -threads auto -c:v libx264 -preset medium -b:v 988k -pass 2 -c:a libmp3lame -b:a 192k $OUTPUT_MP4_FILE
rm -f av2pass* &>/dev/null
@zipizap
zipizap / check_files_integrity.sh
Created December 4, 2013 15:25
Check that all files under current dir are readable. I use it to check the decrypted-version of files ofan EncFs dir... to check that the decrypted files are all ok... if the EncFs dir is in Dropbox and the upload/sync fails, then the decrypted-version will have errors, which can be spoted with this simple script
#!/bin/bash
function shw_grey { echo -e '\033[1;30m'"$1"'\033[0m'; }
function shw_norm { echo "$1"; }
function shw_info { echo -e '\033[1;34m'"$1"'\033[0m'; }
function shw_warn { echo -e '\033[1;33m'"$1"'\033[0m'; }
function shw_err { echo -e '\033[1;31mERROR: '"$1"'\033[0m'; }
shw_info "Check starting..."
find . -type f -exec wc -l \{\} 2>&1 \; | grep error
shw_info "Check finished"
@zipizap
zipizap / gist:7489927
Last active December 28, 2015 10:59
Detect ssh login from ~/.bashrc
# If you put this check inside ~/.bashrc you can detect bash session opened by ssh-logins :)
[ "$SSH_CONNECTION" -a "$SSH_TTY" == $(tty) ] && echo "This bash session was opened from an ssh login :)"
@zipizap
zipizap / resize_jpegs.sh
Last active December 28, 2015 01:59
Resize all JPEG files in current directory, to <GEOMETRY> size
#!/bin/bash
function shw_grey { echo -e '\033[1;30m'"$1"'\033[0m'; }
function shw_norm { echo "$1"; }
function shw_info { echo -e '\033[1;34m'"$1"'\033[0m'; }
function shw_warn { echo -e '\033[1;33m'"$1"'\033[0m'; }
function shw_err { echo -e '\033[1;31mERROR: '"$1"'\033[0m'; }
function shw_usage {
cat <<EOT
Resize all JPEG files in current directory, to <GEOMETRY> size
#Download the script OpenDns_setup_dhclient.conf.sh
wget "http://gist.github.com/raw/565137/0ac98870256cbdb53eb8c16ccb69008a95c20127/OpenDns_setup_dhclient.conf.sh"
#Run it once as root
sudo bash OpenDns_setup_dhclient.conf.sh
#download the script into the Dropbox folder
cd $HOME/Dropbox && wget "http://gist.github.com/raw/564419/35634bc7a13e22dd58b5b0db645c2620b5aedc20/bckpDir2home.sh"
#and run it whenever you want to make a new backup.
cd $HOME/Dropbox
bash bckpDir2home.sh
puts "\e[1;30msome color text\e[0m"