Using ColdFusion to parse a list with empty values

I was parsing through a csv file today and having issues with empty values. The data I’m receiving is in a format the 3rd party cannot update, so my data looked something like this

1,,abc,32,,gef

Dumping the list provides the expected list, but looping through the list it skips over values

<cfoutput>
  <cfloop list="#list1#" index="i">
    #i#<br>
  </cfloop>
</cfoutput>

produces

1
abc
32
gef

After googling this for a bit I gave up and asked my brother. He told me to use the ‘includeemptyfields’ attribute in listtoarray(). I knew I could turn a list into an array, but I wasn’t aware of the third attribute until today, the default is obviously false, so blank values were never included.

The code below produces the desired output. Notice I am now looping through an array instead of a list.

<cfset newlist = listToArray(list1,',',true) />
<cfoutput>
  <cfloop array="#newlist#" index="i">
    #i#<br>
  </cfloop>
</cfoutput>

1

abc
32

gef

read more

get US Bank Holidays UDF

I was looking for an existing UDF on cflib.org for current bank holidays but the only one I could find was for German holidays only. With this function you can pass in a year otherwise it will assume the current year is to be used.

The following holidays are calculated using this UDF.

Holiday Official Date
New Year's Day January 1
Independence Day July 4
Veterans Day November 11
Christmas Day December 25
Inauguration Day January 20th (Year after election year – multiple of 4)
MLK's Birthday Third Monday in January
George Washington's Birthday Third Monday in February
Memorial Day Last Monday in May
Labor Day First Monday in September
Columbus Day Second Monday in October
Thanksgiving Day Fourth Thursday in November
<cffunction name="getUSBankHolidays" access="public" output="false" returntype="struct" hint="general bank holidays for US">
  <cfargument name="iYear" default="#Year(now())#" />
  <cfset var currentYear = arguments.iYear />
  <cfset var strResult =
  { NewYears = createDate(currentYear, 1, 1),
    Independence = createDate(currentYear, 7, 4),
    Veterans = createDate(currentYear, 11, 11),
    Christmas = createDate(currentYear, 12, 25)
  } />

  <cfif NOT (currentYear - 1) MOD 4>
    <cfset strResult.Inauguration = createDate(currentYear, 1, 20) />
  </cfif>
  <cfset strResult.MLKBirthday = createDate(currentYear, 1, GetNthOccOfDayInMonth(3, 2, 1, currentYear)) />
  <cfset strResult.WashingtonsBirthday = createDate(currentYear, 2, GetNthOccOfDayInMonth(3, 2, 2, currentYear)) />
  <cfset strResult.MemorialDay = createDate(currentYear, 5, (DaysInMonth(createDate(2012, 5, 1))) &#8211; (DayOfWeek(createDate(2012, 5, DaysInMonth(createDate(2012, 5, 1)))) &#8211; 2)) />
  <cfset strResult.LaborDay = createDate(currentYear, 9, GetNthOccOfDayInMonth(1, 2, 9, currentYear)) />
  <cfset strResult.ColumbusDay = createDate(currentYear, 10, GetNthOccOfDayInMonth(2, 2, 10, currentYear)) />
  <cfset strResult.Thanksgiving = createDate(currentYear, 11, GetNthOccOfDayInMonth(4, 6, 11, currentYear)) />
  <cfreturn strResult />
</cffunction>

This function is long overdue for me as monitors that run on week days run on Holidays and result in a lot of false positive ‘down’ notifications. If the array returned is empty then the scheduled task should run. If the array has records then it’s a holiday

This UDF requires the getNthOccOfDayInMonth function from cflib.org

read more

Using PS Tools - pslist and pskill to remotely kill computer processes

At work, we have a lot of computers/servers that need to be remotely managed. If a computer has frozen for some reason, PS Tools is a great program to help determine what the issue is and if necessary remotely reboot the computer. There are 12 different programs that come with PS Tools, but pslist and pskill are the two used most frequently.</p>

All PS Tools programs are ran via the command line. I unzipped all the programs to c:\pstools, so I can use cd c:\pstools in the command prompt to get to my directory from there you can type pslist to get a list of all running processes on a computer.

pslist \\mattbusche is the command to find all running processes on my computer

pslist

Normally if a rogue process is the problem with the computer it will have an extremely high CPU time. Idle and system will always have high times, so those can always be ignored. To kill a process you need the pid from the pslist command. You will need to reference the computer in this command as well pskill \\mattbusche -t 344

That command would terminate pid 344 smss. If the offending process isn’t something you’ve heard of, you probably shouldn’t just go and kill it. We have a ton of VB programs, so those are fairly easy to identify (i.e. pre-trip approval, email reader, etc.)

If for some reason the process cannot be killed then you will need to use psshutdown which I will cover in a later post.

read more