Monday, July 14, 2014

collobrate with Cloud9 IDE ( now i know why they say "am on cloud 9")

Note sure if u have mentioned it earlier..but i am a visual person.
I have gotten myself to use vim with its basics (delete copy past navigate search) ..but i will dislike it!
I love IDEs .. except that I H8 them when they are slow but i would still take and IDE over vim unless its just painfully unworkable slow .. i push it to its limits!

BTW
I have used slick edit ...nice when its now slow
I tried bit of Eclipse.. fine
I tried RubyMine for ruby ...fine
I tried Pycharm for python...good!


and now imagine if you have to collaborate with somebody..not sure what they are comfortable in.
want to watch them /work with them .. in your or their comfortable setting!

your solution is cloud9

check it out!  it is literally code anywhere anytime with anyone!
 no learning curve at all ..almost!

great tool for conducting interviews too!

https://c9.io/


Friday, July 11, 2014

simple way to add supervisor to your project



Add a supersvisord.conf 
and start it or callit from vagrant like this:-

sudo supervisord -c /vagrant/scripts/supervisord.conf

if you get an error like "locked "
try
sudo unlink /tmp/supervisor.sock
and kill
ps -ef | grep supervisord





sample supervisord.conf
 [unix_http_server]
file=/tmp/supervisor.sock

[supervisord]
logfile = /tmp/supervisord.log
pidfile = /tmp/supervisord.pid
directory = /tmp
identifier = supervisor


[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl = unix:///tmp/supervisor.sock

[program:name]
command = python /vagrant/nameof the application
redirect_stderr=true
autorestart=true
startsecs=10
stdout_logfile=/var/log/%(program_name).out.log
priority=1




you can user supervisorctl to check the status of your programms
sudo supervisorctl -c /vagrant/scripts/supervisord.conf


more info :-
http://supervisord.org/

simple way to add vagrant to your project

Here is a simple vagrant  file ( not too fancy) to get you going.

This will basically get your virtual machine up  :-

VagrantFile


VAGRANTFILE_API_VERSION = "2"

Vagrant.configure("2") do |config|
    # Ubuntu 12.04, 64 bit
    config.vm.box = "precise64"
    config.vm.box_url = "http://files.vagrantup.com/precise64.box"

    #http://127.0.0.1:1234
    config.vm.network :forwarded_port, guest: 80, host: 1234

    # Set virtual machine size
    config.vm.provider :virtualbox do |vbox|
        vbox.customize ["modifyvm", :id, "--memory", 1024,"--cpus", "2", "--natdnshostresolver1", "on", "--natdnsproxy1", "on"]
    end

    config.ssh.forward_agent = true

    config.vm.define 'whatevernameyourprefer' do |whatevernameyourprefer_config|
        buzz_config.vm.host_name = 'whatevernameyourprefer'
    end

    config.vm.provision :shell do |shell|
        shell.path = "install_scriptyouhavetomake.sh"
    end
end





now go ahead and write whatever you want to be done on the vm after its up in yout install_script (like stand up your application):-
install_scriptyouhavetomake.sh

 #!/bin/sh
cd /vagrant

sudo apt-get update
sudo apt-get -y install rabbitmq-server python-pip python-dev build-essential git sshpass
#curl pythonbrew vim
rabbitmq-server start
rabbitmqctl start_app
rabbitmqctl status

sudo pip install --upgrade pip virtualenv



simple way to add logging to your python project

#import the relevant module 
import logging
#you can give you specific name or use the module name
logger = logging.getLogger(__name__)
#if you see duplicate logs .. this should solve the problem for you
#duplicate logs are because there is some other logger catching your logs too
logger.propagate = False
# again multiple handlers can lead to duplicate logs .. so  check before adding new handler

if not logger.handlers:
    #suit yourself and specify whatever format you want easily
    frmt = logging.Formatter('%(asctime)s  %(name)s  %(levelname)s  %(message)s')
    #console
    hdlr = logging.StreamHandler()
    hdlr.setFormatter(frmt)
    logger.addHandler(hdlr)
    #you decide what level of info you want info/dbg/criticla/warn
    logger.setLevel(logging.DEBUG)






now you are ready to publish logs .. sample :-

def test_a(logger):
    logger.debug("debug")
    logger.info("info")
    logger.warning("warning")
    logger.error("error")





for more info refer


https://docs.python.org/2/library/logging.html