Full Circle Notifier for Fedora



Now i’m working in the Full Circle Magazine Notifier to run on Fedora distro’s, Full Circle is a great Ubuntu magazine that every linux dude has to read.

Some screenshots:

Full Circle Notifier Running

Full Circle Notifier Running

Full Circle i686 RPM

Full Circle i686 RPM

Currently now the project is in development, more news about this follow the blog.

Alma Common Software Component Code Generation Calendar



Webcam – OpenCV – Python



Have to explain the code ? :

# Author:Alexis Tejeda <alexis.tejeda@gmail.com>
# Copyright: Alexis Tejeda - www.backorg.com
# License: GPLv3
# Date: Sep, 17 2009
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# About to: This program is capable to connect to a DLink IP camera
# DCS-2102 through HTTP  to get the images or frame of the camera
# streaming in multipart/x-mixed-replace format.

#OpenCV Cameron Test Python Dependencies

from opencv import highgui
from opencv.highgui import cvNamedWindow, cvCreateCameraCapture, cvShowImage,\
    cvQueryFrame, cvSetCaptureProperty, cvWaitKey
from opencv.cv import cvGetSize

i = 0
win = 'OpenCVTest'

camera = cvCreateCameraCapture(0)
cvNamedWindow(win, highgui.CV_WINDOW_AUTOSIZE)
cvSetCaptureProperty(camera, highgui.CV_CAP_PROP_FRAME_WIDTH, 640)
cvSetCaptureProperty(camera, highgui.CV_CAP_PROP_FRAME_HEIGHT, 480)  

while 1:
    frame = cvQueryFrame(camera)
    cvShowImage(win, frame)
    if frame is None:
            break
    k = cvWaitKey(10)

    if k == 0x1b: # ESC
        print 'ESC pressed. Exiting ...'
        break

Python – get Multipart/x-mixed-replace in HTTP response



Working on my project, i decided to use ruby on rails or python as the system back end, for that reason i have to make a driver for the Dlink IP Camera in ruby and python that connects to the camera and get the jpg streaming frames..

Dlink Python

The usage is very simple, just create the object and connect, instantly would be downloading the images on your file system like this…

c = BaseDlinkDriver('admin','cameron1', 'http://my.url.com:80/video/mjpg.cgi')
c.get_frames
'''Driver for DLink IP Camera DCS-2102'''
# Author:Alexis Tejeda
# Copyright: Alexis Tejeda - www.backorg.com
# License: GPLv3
# Date: Sep, 17 2009
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .
#
# About to: This program is capable to connect to a DLink IP camera
# DCS-2102 through HTTP  to get the images or frame of the camera
# streaming in multipart/x-mixed-replace format.

import time
import urllib2
from urllib2 import HTTPError

class BaseDlinkDriver:
    """Class Driver for DLink IP Camera DCS-2102"""

    def __init__(self, user, password, uri):
        """Constructor"""
        self.user = user
        self.password = password
        self.uri = uri
        self.auth = None
        self.http = None
        self.setup_connection()
        self.last_frame_time = time.time()
        self.iterator = 0
        self.events = []
        self.fps = None
        self.frame = None

    def setup_connection(self):
        """Setup the initial connection"""
        self.auth = urllib2.HTTPPasswordMgrWithDefaultRealm()
        self.auth.add_password(None, self.uri, self.user, self.password)
        handler = urllib2.HTTPBasicAuthHandler(self.auth)
        opener = urllib2.build_opener(handler)
        opener.open(self.uri)
        urllib2.install_opener(opener)

    def get_frame(self):
        """Get the camera frame, return the binary data in a byte array"""
        try:
            response = urllib2.urlopen(self.uri)
            content_length = None

            #find the content length
            while 1:
                line =  response.readline()
                if line.split(':')[0] == "Content-Length":
                    content_length = line
                    response.readline()
                    break

            frame_length =  int(content_length.strip().split()[1])
            self.frame = response.read(frame_length)
            self.calculateFPS()
            return  list(bytearray(self.frame))
        except HTTPError, exception:
            print exception.code
            return None

    def calculateFPS(self):
        """Calc the fps per second"""
        self.fps =  round((1/(time.time() - self.last_frame_time)),2)
        self.last_frame_time =  time.time()

How setup OpenCV in Fedora 11-12-13



Install OpenCV devel librarys.

1
[atejeda@backorg ~]$ sudo yum install opencv-devel -y

The edit your bash profile adding this line in the end of the file (in this case edited with VI).

1
2
[atejeda@backorg ~]$ vi  ~/.bash_profile
export LD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATH

Then include in uour script the header files located in :
/usr/include/opencv/

Fedora 13 – Repositiories | Livna | Rpm-fusion



Once you have installed Fedora 13 in your computer, you will notice that they are no media support, so you will have to install some repositories (Livna, Rpm-fusion free and non free) list for download codecs, apps, etc.. etc..:
Open a terminal or console and install the RPM under superuser(su) or sudo mode :

RPM FUSION (also for F11, F12)

su -c 'rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm'
su -c 'rpm -Uvh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm'

LIVNA

su -c 'rpm -Uvh http://rpm.livna.org/repo/13/i386/livna-release-1-1.noarch.rpm'
su -c 'rpm -Uvh http://rpm.livna.org/repo/13/i386/libdvdcss-1.2.10-1.i386.rpm'

Update with : yum update, and that’s it, the repositories are for 32 or i386 machines.

Yes! you can build flash based sites using open source frameworks !



Create POSTFIX accounts using Ruby On Rails in Adobe Flex



Deploy Ruby on Rails Applications in production enviroment on Apache



Install the passenger gem in ruby:

[atejeda@backorg ~]$ sudo gem install passenger

Install the passenger apache module:

[atejeda@backorg ~]$ sudo passenger-install-apache2-module

Add this lines to httpd.conf:

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.15/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.15
PassengerRuby /usr/bin/ruby

Add a virtual host in httpd.conf (example):

<virtualhost *:80 >
        ServerName atejeda.backorg.com
        DocumentRoot /var/www/html
        # RailsEnv development
        # RailsBaseURI /atejeda
        <Directory /var/www/html>
                # AllowOverride all
                # Options -MultiViews
                Options Indexes FollowSymLinks
                Order allow,deny
                Allow from all
        </Directory>

        RailsBaseURI /atejeda
        <Directory /var/www/html/atejeda>
                Options -MultiViews
        </Directory>
</virtualhost>

Create the symbolic link

[atejeda@backorg ~]$ ln -s /home/atejeda/www/blogs/public  /var/www/html/blog

Restart the service (graceful o full restart):

[atejeda@backorg ~]$ sudo service httpd graceful

or

[atejeda@backorg ~]$ sudo service httpd restart

An important note: This only works when the ruby app is in the production enviroment !!.

And config the SELinux to Permissive or Disable, how to to this: http://www.crypt.gen.nz/selinux/disable_selinux.html

More info can be found: http://www.modrails.com/documentation/Users%20guide%20Apache.html

Symlink problem fix: http://www.zsoltmolnar.hu/blog/tech/2006/07/symbolic-link-not-allowed-or-link.html

A good syadmin, always check the log’s file, check yours in case of any errors.

Linux & Ruby & Axel, download them all … easy



Axel is a download accelerator for linux, it’s almost the same like wget, but, makes 3 or 4 connections to download a file.
So, i have a bunch URL in a text file, that i want download, so, i’ve created a ruby script to download each file with axel.

1
2
3
4
5
6
7
8
9
#!/usr/bin/env ruby
begin
file = File.new(ARGV[0], "r")
	while (line = file.gets)
		system("axel -a #{line}")
	end
rescue
	puts "Theres a problem to open the file..."
end

Easy to use :

1
./downloader.rb MyTexFileWithURL.txt