Wednesday 28 October 2015

Python dictionary



In  python dictionary Values each key is separated from it's values by a colon {:},
each items in dictionary is separated by commas, and all items are enclosed in braces {}.
Keys of a dictionary should be unique. No duplicate. Values can be of any type but keys
should be immutable.




#!/usr/bin/python

dic = {'Code': '001', 'Name': 'Alex', 'Age': 27}
dic1 = {'Code': '001', 'Name': 'Peter', 'Age': 21}


print "dic['Code']: ", dic['Code'] # prints dic['Code']: 001
print "dic['Name']: ", dic['Name'] # prints dic['Name']: Alex
print "dic['Age']: ", dic['Age']   # prints dic['Age']: 27

#example functions and methods used with python dictionary

#compare function compares 2 dictionaries
# cmp returns 1 on mismatch and 0 on match
if cmp(dic,dic1)==1:
  print "Both dictionaries are not equal"
else:
  print "Both dictionaries are equal"

# len function prints the length of dictionaries

print "Length of dic : ",len(dic)

# Removing entry with key 'Code'
del dic['Code']

# Deleting all entries in dic
dic.clear()

# Deleting entire dictionary
del dic

# fromkeys copy keys to another dictionary.
# It has 2 parameters
# 1. seq - the list of values used for the key preparation
# 2. value - optional, if provided then entire element values will be set to this value

dic2 = dic1.fromkeys(dic1,10)

print "dic2['Code']: ", dic2.get('Code') # prints dic2['Code']: 002

# has_keys returns true if the  key exists in the dictionary

if dic1.has_keys('Name'):
 print "The kay name exits'


# keys() Returns list of dictionary keys.

print dic1.keys()

Thursday 8 October 2015

Download Microsoft Visual Studio 2015 Torrent Download.

Visual Studio 2015 Enterprise ISO - Core-X

Torrent Download Link

Magnet Link

Hash : 845B06793CAC0A6B6AF535694467BDCA04ABDF37

Using ngView in AngularJS to create multiple page view.

AngularJS is one of the leading JavaScript framework which is doing something simply awesome. Whenever we talk about ngView we have to think about routeConfig which is actually making multiple page views possible. So with routeConfig we can embed a whole website into a single webpage. In this example we have not used multiple html page but rather used template to embed html document object into div block using ngView. So you can try this code to embed as many template you like based on the key parameter you provide on your url. Route Config use a angular function config which embed html block provided in the template with .when and if any of the parameter key does not match then goes to .otherwise where it automatically redirects it to a error page which displays an error message. Template of error key is also defined in .when.

<html ng-app="app">
<head>
<script src="angular.min.js"></script>
<script src="angular-route.min.js"></script>
<script>
app = angular.module('app',['ngRoute']);
app.controller('MyCtrl',function($scope) {
});
app.config(function($routeProvider) {
  $routeProvider
  .when('/', {
     template: '<h2>You are at the Welcome page</h2>',
     controller: 'MyCtrl' }
  )
  .when('/Documents',{
     template: '<h2>Read online tutorials</h2>',
     controller: 'MyCtrl' }
  )
  .when('/Downloads',{
     template: '<h2>Download utility software</h2>',
     controller: 'MyCtrl' }
  )
  .when('/error',{
     template : '<h2>Oops you have entered a wrong url',
     controller: 'MyCtrl' }
  )
  .otherwise( {
     redirectTo: '/error'
      }
  );
});
</script>
</head>
<body ng-controller="MyCtrl">
<div ng-view></div>
</body>
</html>

Installing Apache Tomcat on MAC OSx


Apache Tomcat is one of the most used web server.
Installing Apache Tomcat on MAC is as simple at it can be.
All you need is to download it from Apache Website.
Here we are downloading Apache Tomcat 8.0 version link to 
the tar.gz is provided here.









http://www.us.apache.org/dist/tomcat/tomcat-8/v8.0.27/bin/apache-tomcat-8.0.27.tar.gz
download this and extract it. The best place to extract is /opt/.

Create a directory called Tomcat8.0 on /opt/ and extract it there. You are all ready.

To start the service manually navigate to this directory. /opt/Tomcat8.0/bin/startup.sh
and to shutdown manually /opt/Tomcat8.0/bin/shutdown.sh

To configure Tomcat to automatically start service at boot, configure launchd_wrapper.sh
or org.apache.tomcat.plist. Here is the github link for configuration of both the script.
https://gist.github.com/mystix/661713.

Remember the default port is 8080. You can change server.xml to change port number for 
both normal and SSL (https) connection. BY default for http it is 8080 and for https it 
is 8443.

Installing skype on Mac OSx Mavericks



Installing Skype in MAC OS x Mavericks.
Skype is perhaps one of the best VOIP interface
used by millions of people around the globe. Easy to
use, easily importable contact lists from facebook or
google. Making voice / video calls from Skype to skype,
from skype to phone which is actually cost you. Send
message or attach files
.



We will be installing skype in MAC OSX Mavericks.
First thing you need to do is to download disk image
from official skype website.

Here is the link to download skype for MAC OSx
http://www.skype.com/en/download-skype/skype-for-mac/downloading/


After download is complete file name will be something like this
Skype_MajorVersion.MinorVersion.MinorVersion.SubVersion.dmg
(i.e. Skype_7.13.428.dmg)
Open the file from the download location and you will find 2
icons shows side by side. One is the skype installer to be installed and another is the Application icon. Hold down and drag the skype icon
to the application icon and your installation starts. After installation completes go to the application folder and drag the skype program icon to the launcher toolbar.

Skype is ready to use.


Thursday 1 October 2015

Universal Oracle data exporter using Visual Basic.





 As soon as you click on connect the to section Export Tables  is enabled. If you select Sql from Export data for combo then right section will be enabled for custom sql. If you select Tables then list of tables for the user schema will be populated on the Combo. You can either select a single table or if you do not select any table then all tables will be exported when you click on Export, but if you select one table then that particular table will be exported.


This is the interface from where data will be exported. The project is uploaded in google drive and code is provided in tis article.

Download the Code from -  Google Drive

Option Explicit
Private con As Object
Private rs As Object
Private rs1 As Object
Private table_name As String, fieldName As String, _
recordString As String, fieldValue As String
Private Sub cmdExportType_Click()
    If cmdExportType.Text = "Tables" Then
        customExportFrame.Enabled = False
        If cmbTableList.ListCount = 0 Then
            Call populateListofTables
        End If
        cmbTableList.Enabled = True
    Else
        customExportFrame.Enabled = True
        cmbTableList.Enabled = False
    End If
End Sub

Private Sub Command1_Click()
    If cmdExportType.Text = "Tables" Then
        Call getListofTablesAndData
    Else
        Call GetSqlData
    End If
End Sub

Private Sub cmdConnect_Click()
    Call OpenConnection(txtUser.Text, txtPasswd.Text, txtHostName.Text)
    tableListFrame.Enabled = True
End Sub

Private Sub Form_Load()
    cmdExportType.Clear
    cmdExportType.AddItem "Tables"
    cmdExportType.AddItem "Sql"
    tableListFrame.Enabled = False
    customExportFrame.Enabled = False
End Sub

Private Sub populateListofTables()
    Set rs1 = CreateObject("ADODB.Recordset")
    rs1.Open "select table_name from cat where table_type = 'TABLE' order by table_name", con
    cmbTableList.Clear
    While Not rs1.EOF
        cmbTableList.AddItem VBA.IIf(IsNull(rs1(0)), "", rs1(0))
        rs1.MoveNext
        DoEvents
    Wend
    rs1.Close
    Set rs1 = Nothing
End Sub

Private Sub getListofTablesAndData()
   Call GenerateTableData(cmbTableList.Text)
End Sub

Private Sub GetSqlData()
    Dim SqlStr As String, fieldString As String
    Dim rs1 As Object
    Dim i As Integer
    SqlStr = txtSql.Text
    Set rs1 = CreateObject("ADODB.RecordSet")
    rs1.Open SqlStr, con, 2
    Open App.Path & "\csv_data\" & tblName.Text & ".csv" For Output As #1
    fieldString = ""
    For i = 0 To rs1.Fields.Count - 1
        fieldString = fieldString & rs1(i).Name & ","
        DoEvents
    Next i
    fieldString = VBA.Left(fieldString, VBA.Len(fieldString) - 1)
    Print #1, fieldString
    recordString = ""
    PBRecords.Value = 0
    If rs1.RecordCount > 0 Then
        PBRecords.Max = rs1.RecordCount
        While Not rs1.EOF
            recordString = ""
            For i = 0 To rs1.Fields.Count - 1
                fieldValue = VBA.IIf(IsNull(rs1(i)), "", rs1(i))
                fieldValue = VBA.Replace(fieldValue, ",", " ")
                recordString = recordString & fieldValue & ","
                DoEvents
            Next i
            recordString = VBA.Left$(recordString, VBA.Len(recordString) - 1)
            Print #1, recordString
            DoEvents
            rs1.MoveNext
            PBRecords.Value = PBRecords.Value + 1
            lblRecords.Caption = Round((PBRecords.Value / PBRecords.Max) * 100, 2) & "%"
        Wend
    End If
    Close #1
    rs1.Close
End Sub

Private Sub OpenConnection(user As String, pass As String, serviceName As String)
   On Error GoTo OpenConnection_Error

    If con Is Nothing Then
        Set con = CreateObject("ADODB.Connection")
        con.CursorLocation = adUseClient
        con.ConnectionString = "Provider=MSDAORA.1;User ID=" & user & ";Password=" & pass & ";Data Source=" & serviceName & ";Persist Security Info=False"
        con.Open
    End If

   On Error GoTo 0
   Exit Sub

OpenConnection_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure OpenConnection of Form Form1"
End Sub

Private Sub OpenConnections(userName As String, passwd As String, dataSource As String)
    If con Is Nothing Then
        Set con = CreateObject("ADODB.Connection")
        con.CursorLocation = adUseClient
        con.ConnectionString = "Provider=MSDAORA.1;User ID=" & userName & ";Password=" & passwd & _
        ";Data Source=" & dataSource & ";Persist Security Info=False"
        con.Open
    End If
End Sub


Private Sub GenerateTableData(Optional singleTable As String)
    Dim i As Integer
    If rs Is Nothing Then
        Set rs = CreateObject("ADODB.Recordset")
        Set rs1 = CreateObject("ADODB.Recordset")
        rs.Open "select * from cat where table_type = 'TABLE'" & VBA.IIf(singleTable <> "", _
        " and table_name = '" & singleTable & "'", ""), con
        PBTables.Value = 0
        PBTables.Max = rs.RecordCount
        While Not rs.EOF
           
            table_name = VBA.IIf(IsNull(rs(0)), "", rs(0))
            Form1.Caption = "Exporting data for " & table_name & " table "
            If VBA.Trim$(table_name) <> "" Then
                Open App.Path & "\csv_data\" & table_name & ".csv" For Output As #1
                rs1.Open "select * from " & table_name, con, 1
                fieldName = ""
                For i = 0 To rs1.Fields.Count - 1
                    fieldName = fieldName & rs1(i).Name & ","
                    DoEvents
                Next i
                fieldName = VBA.Left$(fieldName, VBA.Len(fieldName) - 1)
                Print #1, fieldName
                PBRecords.Value = 0
                If rs1.RecordCount > 0 Then
                    PBRecords.Max = rs1.RecordCount
                    While Not rs1.EOF
                        recordString = ""
                        For i = 0 To rs1.Fields.Count - 1
               '             On Error Resume Next
                            fieldValue = getValue(rs1, i, table_name, PBTables.Value + 1)
                            fieldValue = VBA.Replace(fieldValue, ",", " ")
                            recordString = recordString & fieldValue & ","
                            DoEvents
                        Next i
                        recordString = VBA.Left$(recordString, VBA.Len(recordString) - 1)
                        Print #1, recordString
                        DoEvents
                        rs1.MoveNext
                        PBRecords.Value = PBRecords.Value + 1
                        lblRecords.Caption = Round((PBRecords.Value / PBRecords.Max) * 100, 2) & "%"
                        lblRecords.Refresh
                    Wend
                    PBTables.Value = PBTables.Value + 1
                    lblTables.Caption = Round((PBTables.Value / PBTables.Max) * 100, 2) & "%"
                    lblTables.Refresh
                End If
                Close #1
                rs1.Close
            End If
            DoEvents
            rs.MoveNext
        Wend
        Set rs = Nothing
        Set rs1 = Nothing
    End If
End Sub

Private Function getValue(r As Object, ByVal idx As Long, ByVal tbl_name As String, recNo As Long) As String
    On Error GoTo Err1
    getValue = VBA.IIf(IsNull(r(idx).Value), "", r(idx).Value)
    Exit Function
Err1:
    Open App.Path & "\errLog.log" For Append As #2
    Print #2, "Error on " & tbl_name & " table on column " & VBA.IIf(IsNull(r(idx).Name), "", r(idx).Name) & ", index " & idx & " on record number " & recNo & " whose column " & VBA.IIf(IsNull(r(0).Name), "", r(0).Name) & " value is " & VBA.IIf(IsNull(r(0).Value), "", r(0).Value)
    Close #2
End Function

Private Sub GetLatLongData()
    Call OpenConnections("bckv", "bckv", "ORCL")
    Open App.Path & "\lat_long.csv" For Input As #1
    Dim newLine As String
    Dim var
    Line Input #1, newLine
    While Not EOF(1)
        Line Input #1, newLine
        var = VBA.Split(newLine, ",")
        Call con.Execute("insert into citieslatlong (City,ProvinceState,Country,Latitude,Longitude) " & _
        "values('" & VBA.Replace(var(0), "'", "''") & "','" & VBA.Replace(var(1), "'", "''") & "','" & VBA.Replace(var(2), "'", "''") & "','" & VBA.Replace(var(3), "'", "''") & "','" & VBA.Replace(var(4), "'", "''") & "')")
    Wend
    Close #1
End Sub

Private Sub txtHostName_Change()
    cmdConnect.Enabled = (txtUser.Text <> "" And txtPasswd.Text <> "" And txtHostName.Text <> "")
End Sub

Private Sub txtPasswd_Change()
    cmdConnect.Enabled = (txtUser.Text <> "" And txtPasswd.Text <> "" And txtHostName.Text <> "")
End Sub

Private Sub txtUser_Change()
    cmdConnect.Enabled = (txtUser.Text <> "" And txtPasswd.Text <> "" And txtHostName.Text <> "")
End Sub