bloggin' it since August '03 RSS 2.0
# Friday, June 19, 2009
Algorithm implementation/Strings/Levenshtein distance - Wikibooks, collection of open-content textbooks:

Visual Basic for Applications (no Damerau extension)

This version is identical to JavaScript and PHP implementations in this article. I had problems when I tried to use the other VBA implementation in this article, so I had to adopt the version below.

Application.WorksheetFunction.Min() method is Excel-specific. If you implement it with other VBA-enabled applications, uncomment the conditional block and comment out the Application.WorksheetFunction.Min() line. 

Function levenshtein(a As String, b As String) As Integer

Dim i As Integer
Dim j As Integer
Dim cost As Integer
Dim d() As Integer
Dim min1 As Integer
Dim min2 As Integer
Dim min3 As Integer

If Len(a) = 0 Then
levenshtein = Len(b)
Exit Function
End If

If Len(b) = 0 Then
levenshtein = Len(a)
Exit Function
End If

ReDim d(Len(a), Len(b))

For i = 0 To Len(a)
d(i, 0) = i
Next

For j = 0 To Len(b)
d(0, j) = j
Next

For i = 1 To Len(a)
For j = 1 To Len(b)
If Mid(a, i, 1) = Mid(b, j, 1) Then
cost = 0
Else
cost = 1
End If

' Since Min() function is not a part of VBA, we'll "emulate" it below
min1 = (d(i - 1, j) + 1)
min2 = (d(i, j - 1) + 1)
min3 = (d(i - 1, j - 1) + cost)

' If min1 <= min2 And min1 <= min3 Then
' d(i, j) = min1
' ElseIf min2 <= min1 And min2 <= min3 Then
' d(i, j) = min2
' Else
' d(i, j) = min3
' End If

' In Excel we can use Min() function that is included
' as a method of WorksheetFunction object
d(i, j) = Application.WorksheetFunction.Min(min1, min2, min3)
Next
Next

levenshtein = d(Len(a), Len(b))

End Function

I'm no VBA dev, and it confuses me how all of it is called, so a quick google for:

VBA Tips: Writing Your First VBA Function:

Writing Your First VBA Function in Excel

About User Defined Functions

Excel provides the user with a large collection of ready-made functions, more than enough to satisfy the average user. Many more can be added by installing the various add-ins that are available.

Most calculations can be achieved with what is provided, but it isn't long before you find yourself wishing that there was a function that did a particular job, and you can't find anything suitable in the list. You need a UDF.

A UDF (User Defined Function) is simply a function that you create yourself with VBA. UDFs are often called "Custom Functions". A UDF can remain in a code module attached to a workbook, in which case it will always be available when that workbook is open. Alternatively you can create your own add-in containing one or more functions that you can install into Excel just like a commercial add-in.

UDFs can be accessed by code modules too. Often UDFs are created by developers to work solely within the code of a VBA procedure and the user is never aware of their existence.

Like any function, the UDF can be as simple or as complex as you want. Let's start with an easy one...

And I see I have to "Insert" a "Module" to paste the code in. And then it just works. Nice.

Friday, June 19, 2009 10:52:16 AM (Eastern Standard Time, UTC-05:00)  #    Comments [3] -
work
# Wednesday, January 28, 2009
Vim documentation: usr_25:
REFORMATTING

The Vim editor is not a word processor.  In a word processor, if you delete
something at the beginning of the paragraph, the line breaks are reworked.  In
Vim they are not; so if you delete the word "programming" from the first line,
all you get is a short line:

		 1	   2	     3
	12345678901234567890123456789012345
	I taught for a 
	while. One time, I was stopped 
	by the Fort Worth police, 
	because my homework was too 
	hard. True story. 

This does not look good.  To get the paragraph into shape you use the "gq"
operator.
   Let's first use this with a Visual selection.  Starting from the first
line, type:

	v4jgq

"v" to start Visual mode, "4j' to move to the end of the paragraph and then
the "gq" operator.  The result is:

		 1	   2	     3
	12345678901234567890123456789012345
	I taught for a while. One 
	time, I was stopped by the 
	Fort Worth police, because my 
	homework was too hard. True 
	story. 

Note: there is a way to do automatic formatting for specific types of text
layouts, see |auto-format|.

Since "gq" is an operator, you can use one of the three ways to select the
text it works on: With Visual mode, with a movement and with a text object.
   The example above could also be done with "gq4j".  That's less typing, but
you have to know the line count.  A more useful motion command is "}".  This
moves to the end of a paragraph.  Thus "gq}" formats from the cursor to the
end of the current paragraph.
   A very useful text object to use with "gq" is the paragraph.  Try this:

	gqap

"ap" stands for "a-paragraph".  This formats the text of one paragraph
(separated by empty lines).  Also the part before the cursor.
   If you have your paragraphs separated by empty lines, you can format the
whole file by typing this:

	gggqG

"gg" to move to the first line, "gqG" to format until the last line.
   Warning: If your paragraphs are not properly separated, they will be joined
together.  A common mistake is to have a line with a space or Tab.  That's a
blank line, but not an empty line.

Vim is able format more than just plain text.  See |fo-table| for how to
change this.  See the 'joinspaces' option to change the number of spaces used
after a full stop.
   It is possible to use an external program for formatting.  This is useful
if your text can't be properly formatted with Vim's builtin command.  See the
'formatprg' option.
Wednesday, January 28, 2009 3:02:19 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
work
# Thursday, January 08, 2009
FogBugz - Project Management Software:
FogBugz helps teams work together by tracking, prioritizing, and coordinating the thousands of small tasks a development team has to do.
On the tip from A.San I checked out FogBugz and I'm glad he mentioned it. Much easier to get tasks in the system, much easier to group, categorize, organize, and manipulate tasks; and much easier to close them out than my previous solution of Salesforce. And I've only just scratched the surface...
Thursday, January 08, 2009 3:41:33 PM (Eastern Standard Time, UTC-05:00)  #    Comments [2] -
work
# Thursday, December 18, 2008
Perhaps I've explained it before, but we aggregate lists published by governments of "bad people" that other companies can then search via website, web services, or various batch reports to ensure that they are not doing any kind of business with said "bad people". But how often does this sort of thing make the news?

U.S. Links Iranian Bank To Fifth Avenue Building - washingtonpost.com:
Citing a series of alleged sham transactions and e-mails, Treasury and Justice write in court documents that Assa Corp., which holds the 40 percent interest, is a shell company that funnels the rental proceeds through a parent company in the Channel Islands, off the coast of France, to the Iranian bank, which is wholly owned by the Iranian government. Under various laws and presidential orders, the government of Iran and related entities are prohibited from doing business in the United States without a license from Treasury.
And yes, Assa Corp. is now designated "bad people".
Thursday, December 18, 2008 4:39:19 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
work
# Tuesday, December 16, 2008
So I'm converting an Excel Spreadsheet to a SQL script and I forgot to escape the single quotes before surrounding all of the data with single quotes, which won't run in SQL of course. Usually I just start over, today I took it upon myself to determine how I can find these offending single quotes with a vim RegEx. Voila:

/[(,']\@<!'[,')]\@!

The only ones this misses is single quotes at the beginning or end of a field, like: ''Bobby Smith'', which should be escaped '''Bobby Smith''', but these are much easier to hunt down with all other cases taken care of with a simple :g//s//''/g knowwhatimean?

Tuesday, December 16, 2008 10:34:29 AM (Eastern Standard Time, UTC-05:00)  #    Comments [2] -
work
# Monday, September 10, 2007

If you create software development tools, you’ll want to consider building on the Visual Studio 2008 Shell. A streamlined Visual Studio development environment, the Visual Studio Shell provides the core foundation so you can focus on building your application’s unique features. Flexible customization options help you deliver optimized experiences for specific markets.

[ Visual Studio 2008 Shell ]

Meaning, since you love Visual Studio and want to just get used to one IDE, you can now use the Shell and educate it for other platforms (like ColdFusion!). Previously that would have cost over $10,000 to get the rights from Microsoft to Frankenstein their IDE, but now:

Q: How much will the Visual Studio Shell cost?

The Visual Studio Shell will be freely available as part of the Visual Studio SDK starting with the release of Visual Studio 2008. Building and deploying applications based on the Visual Studio Shell will be royalty-free.

So we're ready for you to download the VS2K8 Shell SDK and build us an awesome CF editor, Gruska...

Monday, September 10, 2007 3:55:24 PM (Eastern Standard Time, UTC-05:00)  #    Comments [2] -
work
# Thursday, May 10, 2007

Alex Santantonio has started an effort to organize a gathering of all employees that ever worked for Doceus.

You should have received an email or invitation to the BackPackIT page, if not (because we have the wrong email or you are a super-lurker) please email me, or contact me through this page so I can get you in on the effort.

Thursday, May 10, 2007 2:07:01 PM (Eastern Standard Time, UTC-05:00)  #    Comments [1] -
work
# Friday, February 23, 2007

one of the questions i get quite a lot is on cable management. hiding those ugly wires is always a challenge. while you may not be able to get rid of them all, mike seymour's cable management hack for his jerker v1 desk does at least lift most of them off the floor.

[ ikea hacker: jerker desk cable management hack ]

Cool idea, but his Jerker doesn't look like mine. Mine is the Jerker computer desk, and looks like this:

Oddly enough mine doesn't have the split "hide a cable" piece, and it's just a full solid stabilization bar.

I, however, have jacked the desk part up to be comfortable to type when standing, and purchase a bar stool height chair. I then moved the little shelf below the desk part where I store all of my power strips and stuff, and when it all comes together it looks a bit more like this:

Friday, February 23, 2007 3:02:02 PM (Eastern Standard Time, UTC-05:00)  #    Comments [2] -
work
# Thursday, January 04, 2007

XML Notepad 2007 provides a simple intuitive user interface for browsing and editing XML documents.

[ Download details: XML Notepad 2007 ]

Windows only, but it appears to be a free add on to any validatable copy of Windows.

Thursday, January 04, 2007 10:35:00 AM (Eastern Standard Time, UTC-05:00)  #    Comments [1] -
work
# Friday, October 27, 2006

At Doceus, our Solutions Architects design and deliver solutions for small to midsize businesses, associations, and non-profit organizations. Duties include writing technical specifications and developing web based applications, and maintaining said applications, over their life cycle, for our clients.

Our Solutions Architects are a key part of the Doceus professional services team and are expected to provide an exceptional level of customer service, and assist in strengthening our development and service delivery processes and practices. As a member of Doceus' professional services team Solutions Architects are often required to liaise with clients, so strong written, oral communications and analytical skills are essential.

[ doceus :: accelerate success ]

And we're a telecommuting operation, so you must:

... have access to a broadband connection, have a home telephone and the ability to travel into Washignton DC or Rockville, MD for team meetings. Doceus will consider candidates outside of the Washington DC region if the candidate has access to a major metro airport.

Apply Online ]

So if you've been itching to work with me, now's the time...

Friday, October 27, 2006 3:00:20 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
.net | work | www
# Thursday, May 25, 2006

When you distribute an Office document electronically, the document might contain information that you do not want to share publicly, such as information you’ve designated as “hidden” or information that allows you to collaborate on writing and editing the document with others.

[ Download details: Office 2003/XP Add-in: Remove Hidden Data ]

I am not of the habit of typing things in documents that could cause any issues, but I will sleep more soundly (like I ever have a problem sleeping, thank God) knowing that no one else "hid" anything suspect in a Microsoft® Word™ document that I forward to a client.

Thursday, May 25, 2006 10:08:20 AM (Eastern Standard Time, UTC-05:00)  #    Comments [1] -
work
# Wednesday, March 15, 2006

The simplest way to create a glossary is to type your glossary by hand at the end of your document. Word has no built-in method of creating a glossary automatically, but you can use hyperlinks or the Table of Authorities functionality to create a glossary for one or more documents.

[ Microsoft Word Help FAQ. How to create a glossary in Microsoft Word ]

This article was certainly helpful. Why on earth is there no built-in glossary functionality in Word? What is in the bloat then?

Wednesday, March 15, 2006 11:51:39 AM (Eastern Standard Time, UTC-05:00)  #    Comments [2] -
work
# Thursday, March 02, 2006

And I know that thousands of potential candidates read my blog, so here's the quick description:

At Doceus, our Senior Interactive Designers create dynamic and exciting facades for web applications for small to midsize businesses, associations, and non-profit organizations. Duties include conducting creative workshops, devising information architecture, creating fresh websites, building flash presentations, and helping clients achieve their goals by leveraging solid design techniques.

[ doceus :: accelerate success ]

I'll rush back to my desk now, so I can handle the flood of resumes.

Thursday, March 02, 2006 2:44:49 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
work
Archive
<July 2009>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions.

© Copyright 2009
David Kearns
Sign In
Statistics
Total Posts: 1273
This Year: 39
This Month: 0
This Week: 0
Comments: 1755
Themes
Pick a theme:
All Content © 2009, David Kearns
DasBlog theme 'Business' created by Christoph De Baene (delarou)