Category Archives: Programming

Topics on Programming

More and more, ‘learn to code’ is looking like bad advice

An interesting article from LinkedIn on the skills of coding.

Learning to Code Yields Diminishing Returns

The premise of the article tackles a number of diverse subjects that are outside the scope of whether learning to code is good advice or not.

Fundamentally learning to code is a good skill to have. It is a skill that if you want to have a coding career must  be developed and cultivated.

The mistake is to think that simply having a skill makes you indispensable and guaranteed of gainful employment. Employment is much more complicated than just simply having the correct skills for the position.  Relationships, personality, personal drive, politics, geography, and no small amount of luck are all factors that contribute to your employment status.

Whether you utilize the skills in your daily tasks or not the understanding of logical processing is applicable to every aspect of life if you are so inclined.

 

iTextSharp

I was looking for a shortcut to avoid having to rebuild an entire document again that is currently being displayed in an ASP.net Panel  and instead just export it to PDF. This lead me to iTextSharp library which is used in Java, .NET, and Android.

First problem is that there is zero documentation for this library. Free tool but apparently they want to sell a book about it.

The concept was relatively simple to parse the panel as html and then write to the PDF, but it just starts to choke quickly. Using a grid inside the panel requires an override of the VerifyRenderingInServerForm function to avoid an exception.

Using my test environment it breaks on path access issues to images in the panel.

Then you have to remove all of the css styles that control fonts – larger, smaller, etc. You have to specify the exact point size for the parser to handle it.

Then when you see the final result it is just horribly manged by the formatting it does to the document.

This might be a decent tool in other circumstances, but today it is just not worth the effort to figure out what they want to get it to work properly without any proper documentation.

 

 

 

Excel – LDAP authentication

The beauty of Excel is the ubiquitousness of the program or support for the file formats. When adding business logic and power to these tools however it can be necessary to restrict access due to company confidential information.

Trying to accomplish this in Excel using VBA is basicly a curse due to the horrible developer environment, lack of debugging, and a fractured reference resource.

While with any programming process there are many ways to accomplish the goal and this is just one.

Assuming a userform that prompts for username and password it will add the domain name if necessary.


 

Const ADS_SECURE_AUTHENTICATION = 1

Const ADS_USE_SSL = 2

 

Dim conn As New ADODB.Connection

Dim rs As ADODB.RecordSet

Dim oRoot As Object

Dim oDomain As Object

Dim sBase As String

Dim sFilter As String

Dim sDomain As String

 

Dim sAttribs As String

Dim sDepth As String

Dim sQuery As String

Dim usern As String

 

 

On Error GoTo ErrHandler:

 

Set oRoot = GetObject(“LDAP://rootDSE”)

 

‘work in the default domain

sDomain = oRoot.Get(“defaultNamingContext”)

 

 

Set oDomain = GetObject(“LDAP://” & sDomain)

 

sBase = “<” & oDomain.ADsPath & “>”

‘Only get user name requested

sFilter = “(objectClass=*)”

sAttribs = “AdsPath, cn”

sDepth = “subTree”

 

sQuery = sBase & “;” & sFilter & “;” & sAttribs & “;” & sDepth

‘Add the domain to the user name

If InStr(1, txtUser.Text, “domainname”) = 0 Then

usern = “domainname” & txtUser.Text

Else

usern = txtUser.Text

End If

 

Set conn = CreateObject(“ADODB.Connection”)

conn.Provider = “ADsDSOObject”

conn.Properties(“User Id”) = usern

conn.Properties(“Password”) = txtPass.Text

conn.Properties(“Encrypt Password”) = True

‘Set Flags to ensure secure authentication is used instead of simple

conn.Properties(“ADSI Flag”) = ADS_SECURE_AUTHENTICTION + ADS_USE_SSL

 

conn.Open “Active Directory Provider”

 

Set rs = conn.Execute(sQuery)

GoTo ExitSub

 

ErrHandler:

 

On Error Resume Next

If Not rs Is Nothing Then

If rs.State <> 0 Then rs.Close

Set rs = Nothing

 

End If

 

If Not conn Is Nothing Then

If conn.State <> 0 Then conn.Close

Set conn = Nothing

 

End If

 

Set oRoot = Nothing

Set oDomain = Nothing

MsgBox “You are not authorized to use this application, please contact an Administrator.”

Application.Quit

 

ExitSub:

Unload Me

 

End Sub