Monday, December 10, 2012

Google Apps Alternative

Don't be evil company is not so good anymore. There is no Google apps for free anymore (this was good application for families domain names).

Check domains.live.com as an alternative.

And please post your experiences here.

Tuesday, September 04, 2012

Python script for deleting VM using Nova API

This is sample python script that delete virtual machines, keys and security groups where security group has a same name as keypair



import os, sys, time
from pprint import pprint
from novaclient.v1_1 import client

nt = client.Client("username", "pwd", "test", "http://192.168.0.155:1111/v1.1/", service_type="compute")
a = nt.servers.list()
for s in a:
        print s.name + " | "  + s.key_name  + " | " + str(s.addresses)
        varDelete = raw_input("Delete machine, keys and groups (y/n): ")
        if varDelete == "y":

                print "deleting"
                print
                print "checking if there is an IP for release"

                for nets in s.addresses:
                        pprint (s.addresses[nets])
                        for a in s.addresses[nets]:
                                address = str(a["addr"])
                                print "checking address " + address
                                existInFloating=[checked for checked in nt.floating_ips.list() if checked.ip == address]
                                if len(existInFloating) > 0:
                                        print "exist"
                                        s.remove_floating_ip(address)
                                        existInFloating[0].delete()
                                        print "ip address released"
                                else:
                                        print "not exist"

                nt.servers.delete(s)

                keyname = s.key_name
                if keyname != "":
                        print "deleting keyname and group: " + keyname
                        selectedKeyPairs = [k for k in nt.keypairs.list() if k.name == keyname]
                        if len(selectedKeyPairs) > 0:
                                selectedKeyPairs[0].delete()

                        selectedGroups = [k for k in nt.security_groups.list() if k.name == keyname]
                        if len(selectedGroups) > 0:
                                time.sleep(5)
                                selectedGroups[0].delete()

                print "deleted"
        else:
                print "skipping"



Print all object attributes in python

In case of lack of documentation for some API you may need, for example, list of attributes for some object. You can do that using:


from pprint import pprint
pprint (vars(myobject))


or...



pprint (dir(obj))


or....


import inspect
inspect.getmembers(obj, predicate=inspect.ismethod)


Sunday, September 02, 2012

Universal Android Remote Control

Beta version of AndroRemoteControl application for Android is a live and can be found here: http://goo.gl/oywzP

More info soon. 

Friday, August 03, 2012

Lookbehind assertion is not fixed length

I am using grep for extracting string from file.
If my regular expression looks like:


grep -P -o -z '(?<=^ManagementCidr\s*=\s*).*'

I will get an error "Lookbehind assertion is not fixed length". Problem is in \s*. (?<=) works only if match if fixed size.

Regular expression

(?<=^ManagementCidr\s*=\s*).*
is OK in C# (you can test it using this great tool).


Fortunately, after hours of googling I found that if you put in regular expressing for grep \K it will reset matched text at this point. So grep command that do what I want will be:


grep -P -o -z '^ManagementCidr\s*=\s*\K(.*)




Thursday, March 22, 2012

List number of opened transaction in SQL server

Sometimes when you work in SQL Server management studio you open transaction and forgot to commit or rollback. To check how many transactions are opened execute:

print @@trancount

Friday, February 03, 2012

Cloudfoundry installation problem

Installation of Cloudfoundry described at https://github.com/cloudfoundry/vcap currently (2012-03-02) does not work.
I found that following steps can help to install cloudfoundry:


echo "------------installing ruby---------"
apt-get -y install ruby1.9.1-full build-essential
ln -sf /usr/bin/ruby1.9.1 /usr/bin/ruby
apt-get -y install rubygems rubygems1.9.1

echo "------------installing rvm---------"
apt-get -y install build-essential
apt-get -y install curl
apt-get -y install zlib1g-dev libreadline5-dev libssl-dev libxml2-dev
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
source /home/CurrentUsername/.profile


#change CurrentUsername with your username in prev command

echo "------------installing cloudfoudry---------"
bash < <(curl -s -k -B https://raw.github.com/cloudfoundry/vcap/master/setup/install)

gem uninstall rake -v 0.9.2.2



Total Commander and SVN folders synchronization


  • Add button to show ignore list
  • Fill ignore list and turn it on.


  • Synchronize folders





Monday, January 09, 2012

Add Item to collection if item not exist

Tnx to Miroslav

So, this is extension methods that enables you to add item in collection if item does not exist already


 public static class CollectionsExtensions
    {
        /// 
        /// Adds item to collection if not exist already.
        /// 
        /// The type of the source.
        /// 
The collection.
        /// 
The element.
        /// 
The comparer.
        /// true if item is added to collection.
        public static bool AddIfNotExist(this ICollection collection, TSource element, Func comparer)
        {
            if (collection == null)
            {
                return false;
            }

            if (collection.Any(comparer))
            {
                return false;
            }
            else
            {
                collection.Add(element);
                return true;
            }
        }

        /// 
        /// Adds item to collection if not exist already.
        /// 
        /// The type of the source.
        /// 
The collection.
        /// 
The element.
        /// true if item is added to collection
        public static bool AddIfNotExist(this ICollection collection, TSource element)
        {
            if (collection == null)
            {
                return false;
            }

            if (collection.Contains(element))
            {
                return false;
            }
            else
            {
                collection.Add(element);
                return true;
            }
        }
    }