Archive for the 'Code' Category

Remove a Folder from Git

Remove a given folder from a Git repository…


git rm -r cache/

Remove SVN Info from a Folder

This command removes the SVN data from a folder.


find -name .svn -exec rm -rf {} \;

Zero Padding In Linux Commands

This is how you zero pad a numerical variable in bash.


for ((x=1;x< =31;x+=1)); do echo `printf "%02d" $x`; done

Original Article

Script to Convert FLV to AVI

This will convert a flv file to a avi file. I got this off linux.com. It uses mencoder - so make sure you have that.


#!/bin/sh

if [ -z "$1" ]; then
  echo "Usage: $0 {-divx|-xvid} list_of_flv_files"
  exit 1
fi

# video encoding bit rate
V_BITRATE=1000

while [ "$1" ]; do
  case "$1" in
    -divx)
      MENC_OPTS="-ovc lavc -lavcopts \
        vcodec=mpeg4:vbitrate=$V_BITRATE:mbd=2:v4mv:autoaspect"
      ;;
    -xvid)
      MENC_OPTS="-ovc xvid -xvidencopts bitrate=$V_BITRATE:autoaspect"
      ;;
    *)
      if file "$1" | grep -q "Macromedia Flash Video"; then
        mencoder "$1" $MENC_OPTS -vf pp=lb -oac mp3lame \
          -lameopts fast:preset=standard -o \
          "`basename $1 .flv`.avi"
      else
        echo "$1 is not Flash Video. Skipping"
      fi
      ;;
  esac
  shift
done

Building an RPM from a Spec File

Use this command to build an RPM if you have a Spec File


rpmbuild -ba SPEC_FILE

Installing Rails

You can install Rails in a Fedora system with these commands…


yum -y install ruby ruby-devel ruby-irb ruby-libs ruby-rdoc ruby-ri rubygems
sudo gem update
sudo gem install rails --include-dependencies

Get the Plain Text Version of a Web Page

This command fetches a web page, converts it to text and shows it.


lynx -dump http://www.example.com/

Share Current Folder over the Web

Want to show something on your machine to someone over the web? Don’t copy it or upload it somewhere. Just run “webshare” and the current directory and everything beneath it will be served from a new web server listening on port 8000. When your pal is finished, hit control-c.


python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"

For a slightly more advanced version of this server, see this article(Warning: German Article - but code is self explaining)

Perl Joke

Just a joke - no offense intended…


perl -e '$a="etbjxntqrdke";$a=~s/(.)/chr(ord($1)+1)/eg;print $a'

A Shell Script to Create a Build of Firefox Extension

This shell script will create a build of a firefox extension in linux. This is created according to my details(eg, the guid has @binnyva.com in it) - but you can modify it and use it yourself.


app=$1
folder=$2

if [ $# -eq 0 ] ; then
	echo "Useage: sh build.sh  []"

elif [ $# -eq 1 ] ; then
	folder="$1@binnyva.com/"
fi

rm $app.xpi
cp -r $folder temp
cd temp
rm -rf .git

zip -r $app.xpi .>/dev/null
mv $app.xpi ..
cd ..
rm -rf temp
echo "Built $app successfully"