How to Stream Movies to your iPhone or iPad

I have just found a way to successfully stream movies (avi, mkv, mp4, etc) to my iPhone. It’s via an app called AirPlayer.

First, set up a media server on your home network (for example, PS3 Media Server, like what I have explained in my previous post, “How To Share Media Between PlayStation 3 and Linux”). Then, just access your movies through the AirPlayer app. Everything just works, without much setting or config changes.

Different technology, same excuse

“Just because I didn’t send you a smoke signal doesn’t mean I don’t care”

“Just because I didn’t send you a homing pigeon doesn’t mean I don’t care”

“Just because I didn’t write you a letter doesn’t mean I don’t care”

“Just because I didn’t telegram you doesn’t mean I don’t care”

“Just because I didn’t email you doesn’t mean I don’t care”

“Just because I didn’t IRC with you doesn’t mean I don’t care”

“Just because I didn’t IM you doesn’t mean I don’t care”

“Just because I didn’t BBM you doesn’t mean I don’t care”

“Just because I didn’t post on your wall doesn’t mean I don’t care”

“Just because I’m not on G+ with you doesn’t mean I don’t care”

Create Your Own Web App to Execute Linux Command

Let say you need to run a command (which you use frequently) on your headless Linux box, such as, copying files, start/stop services, reboot, etc. However too lazy to go to the physical machine or open a ssh command from another pc.
Would it be nice if we have a web application that can easily be accessed through a web browser (even from a mobile web browser), to execute those commands. All we have to to is type the url (http://my-server-ip-address:myportnumber), and click on a link.
All these could easily be achieved using very simple service using Python.

1. Create a simple Python script. The Python script will be using WSGI to serve HTTP request/response.

vi mypythonscript.py

2. A sample of the Python script below:

import os
from cgi import parse_qs, escape

def hello_world(environ, start_response):
    parameters = parse_qs(environ.get('QUERY_STRING', ''))
    if 'type' in parameters:
        mycommand = escape(parameters['command'][0])
    else:
        mycommand = ''
    start_response('200 OK', [('Content-Type', 'text/html')])

    if mycommand == 'copyfile1':
	#your linux command here. Example below
	os.system('cp myfile1.txt mynewfile.txt')
    elif mycommand == 'copyfile2':
	os.system('cp myfile2.txt mynewfile.txt')

    return ['''Command to execute:  %(mycommand)s 
    <a href='?command=copyfile1'>Copy file 1</a>
    <a href='?command=copyfile2'>Copy file 2</a>
    ''' % {'mycommand': mycommand}]

if __name__ == '__main__':
    from wsgiref.simple_server import make_server
    #put your own server ip address and port here
    srv = make_server('127.0.0.1',81, hello_world)
    srv.serve_forever()

3. Make the Python script run on every startup. Create a bash script for this:
vi myserver

4. Here’s the script for the bash file:

#! /bin/sh
# /etc/init.d/myserver
#

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting myserver "
    python /home/username/mypythonscript.py&
    echo "[OK]"
    ;;
  stop)
    echo "Stopping myserver "
    kill -9 `pidof python`
    echo "[OK]"
    ;;
  *)
    echo "Usage: /etc/init.d/myserver {start|stop}"
    exit 1
    ;;
esac

exit 0

5. make the bash script executable.
chmod +x myserver

6. copy myserver script to /etc/init.d
sudo cp /wherever/you/saved/myserver /etc/init.d/myserver

7. update the startup folders to include the new script.
sudo update-rc.d myserver defaults

8. To test your Python web app, open a web browser, and type:
http://my-server-ip-address:81

How to Queue Torrents in Transmission

Currently there’s no queue features in Transmission. Luckily we can improvise this with the help of transmission-remote, a command based client for transmission, and along with some Linux bash scripting.

Below I have created a simple bash script:

1. Install transmission remote:
sudo apt-get install transmission-cli

2. Copy the script below, and save as my_script_name.sh , (or whatever name you prefer, but note the .sh extension).

#!/bin/sh
 
# *************
# Configuration
REMOTE="/usr/bin/transmission-remote"
USERNAME="my_username"
PASSWORD="my_password"
MAXDOWN="max_number_of_torrent_to_download"
MAXACTIVE="max_active_torrent"
CONFIG="/my_location_to_transmission_config_file/settings.json"
TRANSOPTS="127.0.0.1:my_port_number"
 
# *************
# Set-up variables
CMD="$REMOTE $TRANSOPTS --auth $USERNAME:$PASSWORD"
LOGCMD="/usr/bin/logger -t transmission-queue "
MAXRATIO=$(cat $CONFIG | grep \"ratio-limit\":)
MAXRATIO=${MAXRATIO#*\"ratio-limit\": }
MAXRATIO=${MAXRATIO%*, }
 
# *************
# deal with downloads
DOWNACTIVE="$($CMD -l | tail --lines=+2 | grep -v 100% | grep -v Sum | grep -v Stopped | grep -v Verifying | grep -v Will\ Verify | wc -l)"
if [ $MAXDOWN -lt $DOWNACTIVE ]; then
    DOWNTOSTOP="$($CMD -l | tail --lines=+2 | grep -v 100% | grep -v Sum | grep -v Stopped | grep -v Verifying | grep -v Will\ Verify | tail -n $(expr $DOWNACTIVE - $MAXDOWN) | awk '{ print $1; }')"
    for ID in $DOWNTOSTOP; do
        NAME="$($CMD --torrent $ID --info | grep Name:)"
        $LOGCMD "< << $ID: ${NAME#*Name: }"
        $CMD --torrent $ID --stop >> /dev/null 2>&1
    done
else
    [ $(expr $MAXDOWN - $DOWNACTIVE) -gt 0 ] && (
    DOWNINACTIVE="$($CMD -l | tail --lines=+2 | grep -v 100% | grep Stopped | wc -l)"
    [ $DOWNINACTIVE -gt 0 ] && (
        DOWNTOSTART="$($CMD -l | tail --lines=+2 | grep -v 100% | grep Stopped | head -n $(expr $MAXDOWN - $DOWNACTIVE) | awk '{ print $1; }')"
        for ID in $DOWNTOSTART; do
            NAME="$($CMD --torrent $ID --info | grep Name:)"
            $LOGCMD ">>> $ID: ${NAME#*Name: }"
            $CMD --torrent $ID --start >> /dev/null 2>&1
        done
        )
    )
fi
# Then deal with total active
ACTIVE="$($CMD -l | tail --lines=+2 | grep -v Sum | grep -v Stopped | grep -v Verifying | grep -v Will\ Verify | wc -l)"
if [ $MAXACTIVE -lt $ACTIVE ]; then
    TOSTOP="$($CMD -l | tail --lines=+2 | grep 100% | grep -v Stopped | grep -v Verifying | grep -v Will\ Verify | tail -n $(expr $ACTIVE - $MAXACTIVE) | awk '{ print $1; }')"
    for ID in $TOSTOP; do
        NAME="$($CMD --torrent $ID --info | grep Name:)"
        $LOGCMD "< << $ID: ${NAME#*Name: }"
        $CMD --torrent $ID --stop >> /dev/null 2>&1
    done
else
    [ $(expr $MAXACTIVE - $ACTIVE) -gt 0 ] && (
    SEEDINACTIVE="$($CMD -l | tail --lines=+2 | grep 100% | grep Stopped | awk -v ratio=$MAXRATIO '{ if (strtonum(substr($0,52,4)) < ratio) print $0 ;}' | wc -l)"
    [ $SEEDINACTIVE -gt 0 ] && (
        TOSTART="$($CMD -l | tail --lines=+2 | grep 100% | grep Stopped | awk -v ratio=$MAXRATIO '{ if (strtonum(substr($0,52,4)) < ratio) print $0 ;}' | head -n $(expr $MAXACTIVE - $ACTIVE) | awk '{ print $1; }')"
        for ID in $TOSTART; do
            NAME="$($CMD --torrent $ID --info | grep Name:)"
            $LOGCMD ">>> $ID: ${NAME#*Name: }"
            $CMD --torrent $ID --start >> /dev/null 2>&1
        done
        )
    )
fi

Save the script on any location you prefer.

3. Create a cron job to run the script. Open the entry to crontab:
crontab -e

4. Let say you want to run the script 5 minutes, the entry on your cron job should be as below:
*/5 * * * * sh /location_to_my_script/my_script_name.sh

Script courtesy of www.4geeksfromnet.com

Favourite movie quotes

These are my favourite movie quotes, which I could rattle off, anytime:

1. “Adaptation, improvization; your weakness is not your technique.”

2. “I did not choose. I was born, and I am.”

3. “A sad commentary in and of itself.”

As a software developer I’m just waiting for the chance to say the first one during peer review, but so far, not yet. Or perhaps I keep forgetting to do so because my subconscious isn’t allowing me to look stupid. There were, however, a few occasions when I had the opportunity to say the second one – without exception, they were during the “death march” stage of projects in which my colleague and I would miserably ask ourselves how we ended up in the programming profession.

What are your favourite movie quotes, and have you ever used them in real life?