Skip to content

Instantly share code, notes, and snippets.

@FerPerales
Forked from pateketrueke/.bashrc
Created May 31, 2013 02:41
Show Gist options
  • Save FerPerales/5682667 to your computer and use it in GitHub Desktop.
Save FerPerales/5682667 to your computer and use it in GitHub Desktop.
rand_port(){
port=$(( 1000+( $(od -An -N2 -i /dev/random) )%(1023+1) ))
while :
do
(echo >/dev/tcp/localhost/$port) &>/dev/null && port=$(( 1000+( $(od -An -N2 -i /dev/random) )%(1023+1) )) || break
done
echo "$port"
}
phpmin(){
for file in `find . -type f -not -path "*.git*" | grep "\\.php"`; do
php -w $file > "$file.tmp"
mv "$file.tmp" $file
done
}
phps(){
root=$1
port=$2
prefix=''
if [ ! $root ] ; then
root="$(pwd)"
fi
if [ ! $port ] ; then
port="$(rand_port)"
fi
if [ $port = 80 ]; then
prefix='sudo '
fi
server="$prefix php -S 0.0.0.0:$port -t $root"
echo "Link: http://localhost:$port/"
eval $server
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment