Monday, 25 October 2010

Set up virtualenv and start a django project

This has been a headacke for me. At last I figured out that the best practice is to set up projcets through a virtualenv. So let's first install it

easy_install virtualenv


Afterwards, you must decide where you want to store your virtual environments, Then, we will create our actual new virtual environment.

mkdir ~/djenv
virtualenv ~/djenv/env1

Then you need to activate the environment:

source ~/djenv/env1/bin/activate

You should see '(env1)' comes at the left of the terminal.

So now you can install Django in this environment:

pip install Django


Set up django project wherever you like, e.g.:

mkdir -p ~/sites
cd ~/sites
django-admin.py startproject proj1


To get out of the environment:

deactivate env1


That's it. enjoy!

For mor info...

Friday, 22 October 2010

Split video file using ffmpeg and mencoder

Example:

ffmpeg -i input.flv -ss hh:mm:ss -t hh:mm:ss output.flv

Where:

-ss :  Buration
-t : Start time
hh: hours
mm: minutes
ss: seconds

If this does not work try mencoder:

 mencoder -ss 00:00:00 -endpos 00:35:20 -oac pcm  -ovc copy input.mp4 -o output.mp4

Wednesday, 20 October 2010

script to set drupal permissions

#! /bin/bash
cd /var/www/drupal
chown -R drupmin:www-data .
find . -type d -exec chmod u=rwx,g=rx,o= {} \;
find . -type f -exec chmod u=rw,g=r,o= {} \;

cd sites
find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
find . -name files -type d -exec find '{}' -type f \; | while read FILE; do chm$
find . -name files -type d -exec find '{}' -type d \; | while read DIR; do chmo$


echo "Permission rebuildng is done!"

Saturday, 16 October 2010

Compress/Decompress commands: Zip, TAR, TAR.GZ, TAR.BZ2

ZIP

To compress a directory with zip do the following:

# zip -r archive_name.zip directory_to_compress

Here’s how you extract a zip archive:

# unzip archive_name.zip

TAR

# tar -cvf archive_name.tar directory_to_compress

And to extract the archive:

# tar -xvf archive_name.tar.gz

This will extract the files in the archive_name.tar archive in the current directory. Like with the tar format you can optionally extract the files to a different directory:

# tar -xvf archive_name.tar -C /tmp/extract_here/

TAR.GZ

This format is my weapon of choice for most compression. It gives very good compression while not utilizing too much of the CPU while it is compressing the data. To compress a directory use the following syntax:

# tar -zcvf archive_name.tar.gz directory_to_compress

To decompress an archive use the following syntax:

# tar -zxvf archive_name.tar.gz

This will extract the files in the archive_name.tar.gz archive in the current directory. Like with the tar format you can optionally extract the files to a different directory:

# tar -zxvf archive_name.tar.gz -C /tmp/extract_here/


TAR.BZ2

This format has the best level of compression among all of the formats I’ve mentioned here. But this comes at a cost – in time and in CPU. Here’s how you compress a directory using tar.bz2:

# tar -jcvf archive_name.tar.bz2 directory_to_compress

This will extract the files in the archive_name.tar.bz2 archive in the current directory. To extract the files to a different directory use:

# tar -jxvf archive_name.tar.bz2 -C /tmp/extract_here/

source

create or delete mysql databases

- To backup mysql database
mysqldump -u username -p databasename > /path/to/dbfile.sql
- To restore a backed up mysql databas

mysql -u username -p databasename < /path/to/dbfile.sql

Convert avi files to mp4 using ffmpeg

ffmpeg -i input.avi -f mp4 -strict experimental -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ab 192 -s 320x240 -aspect 4:3 output.mp4





--