multiple leds_bb

int led1=13;
int led2=12;
int led3=11;
int led4=10;

void setup(){
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);

void loop(){
int i;
for (i=10; i<=13; i++)

for (i=10; i<=13; i++)



capturing environment variables is very useful when one has to do some hacks..
this is a simple bash script which shows all the environment variables when caught from STDIN


env >> ${CAPTURE_FILE}
exit 1

Equivalent Python script:

#!/usr/bin/env python

import os
import sys

def capture():

    log = os.environ
    data = open("/tmp/capture.log", "a")
    for key in log.keys():
        data.write(" : ")
        for n in log[key]:
            data.write('%s' % ((n)))

def main():


if __name__ == "__main__":

the following is a script which downloads the latest image from  one of the NASA ftp server at eol.jsc.nasa.gov and to my amazement there are new images every 5 mins!, so I sent python to grab that image….

python supports ftp by importing the ftplib module and ftplib.FTP class.

connecting to an ftp server is very straightforward…

>>>from ftplib import FTP
>>>f = FTP('my ftp server ')
>>>f.login('anonymous', 'your@email.address')

The core job inside in this script is to first dump the listing of files into a list, then reading that list line by line, split the date and convert it to a datetime object and store it in a new list, also i created another list which stores the filenames, next i combined these two lists to form a dictionary, and sorted the dictionary using the KEY(datetime object) in reverse order, and ran the loop only once as i need only the first image.

here is the full script..

#!/usr/bin/env python

import ftplib
import os
import socket
import sys
import time
import datetime

HOST = 'eol.jsc.nasa.gov'

def main():
        f = ftplib.FTP(HOST)
    except (socket.error, socket.gaierror), e:
        print 'cannot reach to %s' % HOST
    print "Connect to ftp server"

    except ftplib.error_perm:
        print 'cannot login anonymously'
    print "logged on to the ftp server"

    data = []
    datelist = []
    filelist = []
    for line in data:
        col = line.split()
        datestr = ' '.join(line.split()[0:2])
        date = time.strptime(datestr, '%m-%d-%y %H:%M%p')

    combined = zip(datelist,filelist)
    new_dict = dict(combined)
#    print who
#    for key,value in sorted(new_dict.iteritems(), key =lambda (k,v): (v,k)):

    for key in sorted(who.iterkeys(), reverse=True):
       print "%s: %s" % (key,new_dict[key])
       filename = new_dict[key]
       print "file to download is %s" % filename
           f.retrbinary('RETR %s' % filename, open(filename, 'wb').write)
       except ftplib.err_perm:
           print "Error: cannot read file %s" % filename
           print "***Downloaded*** %s " % filename


if __name__ == '__main__':

Active vs Passive Ftp

January 22, 2012 — Leave a comment

a simple diagram which shows the difference between active and passive ftp





You can create a QRcode using the python pygooglechart wrapper for Google chart API. Here i used the wrapper to generate the QRcode as a django app but right now I wont go into the specifics of how to create a django app, maybe will do later,

but this is the view i made for the qr app, i passed the form results to the QRChart and formatted the results in a Vcard format and its then rendered to the page.

You can see the script in action here


test it using an QR android/iphone app

Now the Views….

from django.template.loader import get_template
from django.template import Template, Context
from django.http import HttpResponse, Http404
from django.shortcuts import render_to_response
from django.core.mail import send_mail
from django.http import HttpResponseRedirect
from cacoos_com.qr.qr_form import QrForm
from pygooglechart import QRChart

def qr(request):
    if request.method == 'POST':
        qform = QrForm(request.POST)
        if qform.is_valid():
            qc = qform.cleaned_data
            chart = QRChart(300,300)
            mecard = "BEGIN:VCARD"+"n"+"VERSION:3.0 n"+"FN:"+qc['name']+"n"+"TEL;type=CELL:"+qc['phone']+"n"+"EMAIL;type=INTERNET;type=WORK;type=pref:"+qc['email']+"n"+"URL;type=pref:"+qc['url']+"n"
            chart.set_ec('H', 0)
            return render_to_response('qr_results.html', {'url': qc['url'] })
        qform = QrForm(initial={'url': 'type your url here'})
    return render_to_response('qr_form.html', {'form': qform})

You can use the following template to generate a Vcard, quite handy…

FN:John Doe
ORG:Example.com Inc.;
TITLE:Imaginary test person
TEL;type=WORK;type=pref:+1 617 555 1212
TEL;type=CELL:+1 781 555 1212
TEL;type=HOME:+1 202 555 1212
TEL;type=WORK:+1 (617) 555-1234
item1.ADR;type=WORK:;;2 Example Avenue;Anytown;NY;01111;USA
item2.ADR;type=HOME;type=pref:;;3 Acacia Avenue;Newtown;MA;02222;USA
NOTE:John Doe has a long and varied history, being documented on more police files that anyone else. Reports of his death are alas numerous.
item5.X-ABRELATEDNAMES;type=pref:Jane Doe
CATEGORIES:Work,Test group

A class in python is a blueprint of the instances which you can create from, for example i want to create a house and i have the description and the properties of that house, now I can spawn multiple houses using that blueprint and every instance will be a separate entity from the other but identical in properties defined in the blueprint i.e class

So we create a class house and for example will create three functions i.e one to name the house, location and third to print the properties of that house. Below is a simple class definition, you might be wondering what the hell this “self” is, well basically its a temporary place holder for the object which is created from this class, this helps the class to identify the object and its attributes within the class, in this case its the “first” and “second” object.

>>> class house:
...         def houseName(self,name):
...             self.name = name
...         def houseLocation(self,location):
...             self.location = location
...         def printName(self):
...             print "House name: %s " % self.name
...             print "Location: %s " % self.location

The next four steps creates the “first” object from the class “house()” sets the name, location and prints it.

>>> first = house()
>>> first.houseName = "Dog Villa"
>>> first.houseLocation = "Zetland Street"
>>> first.printName()
House name: Dog Villa
Location: Zetland Street

we use the same methods to create the second object “second”

>>> second = house()
>>> second.houseName('Cat street')
>>> second.houseLocation('Sherwood Way')
>>> second.printName()
House name: Cat street
Location: Sherwood Way

Next we will create a parent class and inherit it on a subclass, also see how we can manipulate the inherited variables from the parent class, Note here “pass” in the childClass means “dont do anything”

>>> class parentClass:
...        var1="i am var1"
...        var2 ="i am var2"
>>> class childClass(parentClass):
...        pass
>>> parentObject=parentClass()
>>> parentObject.var1
'i am var1'
>>> parentObject.var2
'i am var2'
>>> childObject=childClass()
>>> childObject.var1
'i am var1'
>>> childObject.var2
'i am var2'

Continue Reading…

Kyokushin Punches Tuski

December 28, 2011 — Leave a comment







Continue Reading…

Using python boto module its fairly easy to list all the attributes of an instance in the amazon EC2 cloud

you need to install the python boto package first, if you are using debian run this

root@localhost#apt-get install python-boto

or for centos

root@localhost#yum install python-boto

we start out script with first importing the boto module

from boto import ec2
import boto.ec2

to connect to the instances you need the amazon access key id and the aws secret access key which you can get from the amazon’s security settings under the amazon aws account.

to make our code simple and i created a function just to store the account information, as an example we will retrieve only the running instances

def login():
  account = "account name"
  aws_access_key = 'paste the access key here'
  aws_secret_key = 'paste the secret key here'

the function account() will return all the instances for the above account

def account(a,s):
   access_key = a
   secret_key = s
   regions = boto.ec2.regions(aws_access_key_id=access_key,aws_secret_access_key=secret_key,is_secure=False)
   eu = regions[0]
   conn_eu = eu.connect(aws_access_key_id=access_key,aws_secret_access_key=secret_key)
   inst = conn_eu.get_all_instances()
   return inst

and we pass these onto the running function..which will list the mentioned attributes

def running(a,s,h):
   host = h
   f = open("/tmp/test.txt", "a")
   sto = sys.stdout
   sys.stdout = f
   print "-----------------------------------------------------------------------------------------------------------------------------------------------------"
   print "RUNNING INSTANCES ON ", host
   print "IDttAMI-IDttArch.tTypettStatetLaunch TimetttPublic DNSttttttPrivate IPttName"
   access = a
   secret = s
   instt = account(access,secret)
   for i in instt:
      for r in i.instances:
          if 'running' in r.state:
              print "%st%st%st%st%st%st%st%st%s" % (r.id,r.image_id,r.architecture,r.instance_type,r.state,r.launch_time,r.public_dns_name,r.private_ip_address,r.tags['Name'])
   sys.stdout = sto

hope this helps…

Continue Reading...



This is a typical example on how to to create a veritas volume with concatenated plexes. The disk has two disk controllers c1&c2 with two disks eack. We will create veritas disk out of them and assign them a unique name eg. disk1,disk2,disk3 and disk4.

Before we install veritas storage foundation we should know what the different raid levels are:

raid 0 (Disk Spanning): there are two modes here:

1. Concatenation:- which means data is written to both the drives i.e. if we have two drives A and B, system will first write data to disk A and when it is full it will start writing data to B.

2. Stripping:- this means that the systems writes data in such a way that it spreads on both the disks A and B

raid 1: (Redundancy)

1. Mirroring: In this method the system copies the data to the secondary disk in the raid configuration which makes a exact replica of the first disk.

2. Resilence: This method combines two layout to build a volume:

a.) RAID 0+1: it combines Level 0 (Stripping) and Level 1 (Mirroring)
b.) RAID 1+0: it combines Level 1 (Mirroring) and Level 0 (Stripping)

Continue Reading…