May 16, 2013

Python Modules and Packages

python module
- module __name__
- a module can contain executable statements as well as functional statements
- those are executed only once
- modules has its private symbol table
- modules can import other modules
- if you include __name__ == __main__ -> then, it will execute
- otherwise, module can be imported too

python module search path
- module is first searched into module path
- then, module is searched in sys.path
- sys.path same as PATH variable in shell


what is python compiled file
- byte compiled.
- modification time

python standard modules
- python comes up with standard modules
- that is called python library reference
- dependant of system implementation

python packages:
- module namespace - by using dotted module names i.e. A.B
- import * = must be in __init__.py file  : 

Python: Dynamic and Strongly Typed Language


Python is both dynamically and strongly typed language.

Dynamic:
- i.e. Types are checked at run-time

Strongly:
- i.e. We can't intermingle variables with different type
         Javascript: var b = 'x' + 3, This will assign 'x3' into b
         While in python, you it would throw an exception



More into Dynamic Nature of Language:

When we declare a variable, we usually associate a type with that.
i.e. integer, float

For Example:

int a
float b

In STATICALLY typed language, variable type is fixed through out life cycle of program execution.

Assigning a = 's', ( integer typed variable to string would throw compile time error )

But, in python, it's dynamic nature.

Variable can hold any type of data through-out the life-cycle of program execution.

a = {'key':'value'} # first as dictionary
a = 'a' # now as String


So, during compile-time, type checks are skipped, Although, as its strongly typed language,
we can't intermingle two different type of variables.

It is up-to programmers test-suite to detect type errors.








Python Basics


Why Python ?

 - Efficient High-Level Data-structures.
    - Tupples
    -  Lists
    - Dictionaries
    - Sets


- Simple Object Oriented Approach

- Elegant Syntax
   a = "hi %s" % "Dave"

- Dynamic Typing
  - i.e. type-checks are performed at run time


sys.exit(0)

March 29, 2013

Bootstrap modal in center

Showing up bootstrap.js modal dialog into center, when we dont use default width.
 
here is the hack:
 

        $("#headerPreview").modal('show').css(
        {
            'margin-top': function () {
                return -($(this).height() / 2);
            },
            'margin-left': function () {
                return -($(this).width() / 2);
            }
        })



Source: https://github.com/twitter/bootstrap/issues/374


Cheers!

March 23, 2013

Zend Framework Basics

Zend Framework, is basically, collection of component,
when put together, we can build web-app relatively faster and stronger.

While, we can use indiviual component too.



Comes up with basic componanents:

Zend_Controller
Zend_Layout
Zend_Config
Zend_Db
Zend_Db_Table
Zend_Registry