Showing posts from October, 2012

Count Keywords Occurance in a Directory

I searched google for a Word Counter, I wanted to read in files in a directory and output the number of times that word occurs in those files. So I created this command line application that takes an input file of keywords and then searches for those keywords in the local directory and prints out the "File - Keyword - Number of occurances". I wrote this years ago, today I would have probably written it as a PowerShell script =) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Text.RegularExpressions; namespace CountKeywords {     class Program     {         public static void Main(string[] args)         {             List<string> Keywords = new List<string>();             StreamReader SR = File.OpenText(args[0]);             string S = SR.ReadLine();             while (S != null)             {                 Keywords.Add(S.Trim());                 S = SR.ReadLine();      

Leadership and Team Morale

Team Morale is a serious issue for all leaders to consider. The Masters of Project Management introduced me to a model I found applicable to my role of work and lined up with experience as to what causes work dissatisfaction and satisfaction. The model below is the result of a study: Through this model we find that achievement and recongition triumph over company policy and administration which remain the strongest causes of dissatisfaction. As a leader it is important to target aspects of achieving success and warranted recognitioning whilst avoiding highly administrative policies so that these factors do not compound to create high dissatisfaction. Negative Example: I remember a position where the new assistant manager would discuss how new policies were going to be introduced and how everything would need to be checked by her (she was not a domain knowledge expert) and as things progressed her policies got more petty, you could only gain access to stationary by asking her

VIEMU for VS2010/12 Cheatsheet

Published by VIEmu this cheatsheet to keep around when learning VIM fortunately I almost never use it nowadays :-)

NeuroPower Framework to Effective Leadership

This blog is to provide an introduction to the NeuroPower framework and reduces a highly technical well referenced material into simple, yet real world examples. This framework will assist project managers in building effective teams that work in a harmonious network maintaining respect for each other. Introduction: Phycology is one of the oldest fields of study, there were notes on the reoccurrences of patterns within the brain since prior to Ancient Egypt. These studies linked phycology with religion but nevertheless represented patterns in behaviour and techniques for the modification of behaviour. NueroPower combines the intellect of a master of Artificial Intelligence and Phycology to produce a logical representation of behaviour patterns and leaders can use this model to predict behaviour, allowing leaders to mitigate risk and create a harmonious team. Tension and the Amygdala This was best explained to me as a story; imagine for a moment that you are a bunny rabbit, n

Recursive T-SQL Backup All Databases Script

I had this script running as a job on my production server. I had to modify this script to include a TRY-CATCH block so that if a backup command failed it will continue on to the next database and not exit the script. This was an issue with the script that I had to resolve. DECLARE @name VARCHAR(50) -- database name DECLARE @path VARCHAR(256) -- path for backup files DECLARE @fileName VARCHAR(256) -- filename for backup DECLARE @fileDate VARCHAR(20) -- used for file name -- specify database backup directory SET @path = 'C:\Backup\' -- specify filename format SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) DECLARE db_cursor CURSOR FOR SELECT name FROM master.dbo.sysdatabases WHERE name NOT IN ('master','model','msdb','tempdb') -- exclude these databases OPEN db_cursor FETCH NEXT FROM db_cursor INTO @name WHILE @@FETCH_STATUS = 0 BEGIN SET @fileName = @path + @name + '_' + @fileDate

Erlang Cheatsheet

For my own benefit and of any others out of convenience. This is a useful Erlang Cheat sheet with some common commands.

.NET Framework Posters & ASP.NET Page Lifecycle Poster

Some handy .NET Framework posters to hang around the office and also a ASP.NET page lifecycle poster:

SharePoint - Delete Manager from UserProfile

Today's task revolved around removing the Manager I set when testing the profile pages on the my site portal. I had set the manager on a service account so it had to be removed to stop appearing as a colleague to team members and potentially exposing a security risk in giving away the service account username. Setting it is possible directly from the Organisational View page that comes as part of the site template. There is a link called "Set My Manager", which allows you to set the current UserProfile's manager. Once set though I wanted to remove this profile. Unfortunately, there is no way for the user to remove their manager only set the manager. So only an administrator can remove the manager. Initially, being a powershell fanatic. I tried to remove the manager using the object model using the following powershell commands: $site = get-spsite http://localhost $context = Get-SPServiceContext $site $mgr = new-object "Microsoft.Office.Server.U

T-SQL script to pull Active Directory Users

This script allowed us to query AD and pull all the users into our asp_net membership system. Its a handy script and shows some real strengths of using T-SQL. set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go CREATE PROCEDURE [dbo].[config_PullADUsers]             -- Add the parameters for the stored procedure here             @LDAProot nvarchar(MAX)  AS BEGIN             -- SET NOCOUNT ON added to prevent extra result sets from             -- interfering with SELECT statements.             SET NOCOUNT ON;                                     if exists (select * from tempdb.dbo.sysobjects where id = object_id('tempdb.dbo.#ldap'))             drop table #ldap             create table [dbo].[#ldap] (                         [row_id] [int] IDENTITY (1, 1) NOT NULL ,                          [userAccountControl] nvarchar(512),                          [objectSid] nvarchar(256),                          [objectSidSddl] nvarchar(256) collate Latin1_General_CI

SharePoint PageLayout MissingMethodException and ErrorWebPart

PART 1 (FIX IN PART 2): Another SharePoint boggling issue. I defined a Page Layout as illustrated below. It has two columns left and right with 80% and 20% width respectively. When deploying this page on my local system I found that creating a page resulted in an error. Entering web part maintenance mode on the pagelayout page revealed there were several ErrorWebPart components listed for my page layout? At the moment I do not have time to investigate why or how they are there. But removing these through the maintenance protal fixed the defect. If I get around to tracing the source of the issue I will post. Hopefully the latest cumulative update will prevent this sort of defect from occuring!  <%@ Page ClassName="BOQTwoColumnPageLayout" AutoEventWireup="true"  language="C#"   Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=,Culture=neutral,PublicKeyToken=71e9bce11

Install/Migrate a New SharePoint Farm 2010 "Got Ya's"

This is a short-sweet post of the problems we experienced when reinstalling our SharePoint Farm, we've all setup SharePoint 2010 locally as a single server SharePoint farm, with no glitches or hiccups from the automated installer. But when installing SharePoint on a 4 server farm we had some hiccups that I thought I might jot down for future reference and anyone else who has the luxury of running into some of these issues: Some prerequisites we had setup from our previous farm: 1. An instance of SQL Server running and db_owner role by our domain "SPSetup" account. 2. 4 VM's excluding the database server running WIN2k8 R2 with "SPSetup" having full access on those too. 3. A seperate "Svcspfarm" account with less access to the rest of the network =), (refer to msdn for better articles on permission setups we had ours configured by Hewlett-Packard). 4. Experience installing SharePoint, there are plenty of A,B,C guides on install

SharePoint 2010: How To Enable the Developer Console

This is a powershell script that will enable the developer console on a sharepoint farm: $consoleSettings =[Microsoft.Sharepoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings $consoleSettings.DisplayLevel = "OnDemand" $consoleSettings.RequiredPermissions = "EmptyMask" $consoleSettings.TraceEnabled = $ true $consoleSettings.Update() Short but sweet, now once you visit your SharePoint site you will see a diagnostics icon next to your username on the top bar. In case you receive errors saying that PowerShell could not find the type  Microsoft.Sharepoint.Administration.SPWebService , load the SharePoint dll using following command: [ void ][System.Reflection.Assembly]::LoadWithPartialName( "Microsoft.SharePoint" )

Enable PowerShell Remoting with Client Outside of Server's Domain (Trusted Host and Double Hop Issue)

To enable remote powershelling with servers not in the same domain as the client machine you will need to perform the following steps: Note: Do not allow unencrypted communication for internet use. On the client PC type: PS c:\users\root> cd wsman:localhost\Client PS WSMan:\localhost\Client> Set-Item AllowUnencrypted -Value $true -force PS WSMan:\localhost\Client> Set-Item TrustedHosts -Value * -force On the server PC type: PS c:\users\root> Enable-PSRemoting Then using regedit set the key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WSMAN\Service\allow_unencrypted to 0x00000001 To connect from the client type: PS WSMan:\localhost\Client> New-PSSession -name Server01 -computername boqsource -credential boq\spsetup  -Port 5985 PS WSMan:\localhost\Client> Enter-PSSession Server01 You should be on a command line on your server! To add Sharepoint commands to your shell type: [server] c:\> Add-PSSnapin Microsoft.Sharepoint.Powe

SharePoint AAM Storage Location

Recently, I had changed the AAM on the production farm. Shortly after I rolled back the configuration database but alas the old settings were still there. I desperately began looking for the storage location of the AAM settings. I found very little information on google and thought that it would be good to post regarding this issue. Fortunately microsoft does have a KB article on the matter, but it was not easy to find. So a little extra under the bonnet information when it comes to SharePoint. The AAM configuration does live in the Configuration Database, so why didn't it update on restore? The answer lies with the WFE which also caches these values, Central Administration also displays the values from the cache and not the configuration database...In the event that they are out of sync you need to nuke the WFE by deleting the cache folders and allowing them to rebuild/refresh. Then your new settings will apply. Also I found that whilst this was an issue I could

SQL 2005/2008 Query Current Version and Configuration Settings

This T-SQL query will list the current SQL version and configuration settings for the current instance for SQL Server:     sp_configure 'show advanced options', 1 reconfigure GO sp_configure GO SELECT SERVERPROPERTY('productversion') as ProductVersion SELECT SERVERPROPERTY ('productlevel') as Level SELECT SERVERPROPERTY('edition') as EDITION SELECT @@VERSION as VERSION

Mnesia - Create a Fragmented Table

I have created and worked with fragmented tables before. But not having done so in so long it took abit of effort to remember how to do it without looking at my old source code. Ignore the delete and create schema, you will need to fix these if you want to turn this into a real database as it may delete your database if your not careful when you run install()! This simple fragmented test table will allow you to create new users calling the add_user() function with a username/password/email address. Keep in mind you can only create the table as type bag or set for disc based tables. There are third party efforts to create a disc based ordered_set (tcerl is one that I use), but these are not straight forward to setup and not part of the OTP framework. The tuple we have added is frag_properties for the mnesia:create_table function this allows us to configure this table as a fragmented table. In this case the node_pool consists of only this node retrieved by node() function call. 20

T-SQL Script Detach, Move & Attach

One of my tasks recently involved moving the physical files from a set of MSSQL databases from one partition to another. There were a number of databases so I created the following script in order to detach, move and re-attach the databases. This script was used to move databases on the same box. But I believe with the use of a Linked Server, a mapped drive and a nice OPENQUERY on the linked server you could adapt this script to move this to another server as well. I don't have that itch at the moment, but if it does come up I will make another post with the updated script (otherwise if you make the change please share!) DECLARE @name VARCHAR(50) -- database name DECLARE @nameDB VARCHAR(50) -- database name DECLARE @nameLog VARCHAR(50) -- database log name DECLARE @path VARCHAR(256) -- path for backup files DECLARE @fileNameDB VARCHAR(256) -- filename for backup DECLARE @fileNameLog VARCHAR(256) -- filename for backup DECLARE @destinationPath VARCHAR(256) -- new pa

Installing Sharepoint Server 2010 on a Windows 7 Machine

A quick simple guide to installing Microsoft Sharepoint Server 2010 on a Windows 7 PC. Step 1: Load the CD or Image onto a drive. Step 2: Save the following block of xml into a file named "Config.xml" in the root of your C drive. The path of the file will be "C:\Config.xml" <Configuration>   <Package Id="sts">     <Setting Id="LAUNCHEDFROMSETUPSTS" Value="Yes"/>   </Package>   <Package Id="spswfe">     <Setting Id="SETUPCALLED" Value="1"/>     <Setting Id="OFFICESERVERPREMIUM" Value="1" />   </Package>   <ARP ARPCOMMENTS="" ARPCONTACT="" />   <Logging Type="verbose" Path="%temp%" Template="SharePoint Server Setup(*).log"/>   <Display Level="basic" CompletionNotice="No" AcceptEula="Yes"/>   <PIDKEY Value="XXXXX-XXXXX-XX

Similarities between F# and Erlang

Funnily enough my main goal at the moment is to become a good functional programmer. I have been in the OO world since I was a baby =D. To that end, this will be my first living post, I aim to list all the parallels between F# and Erlang. There are many parallels between them and the truth is that F# is a hybrid language as it supports objects (oh no). But whilst that is helpful when dealing with the .NET Framework it can lead to working in a completely OO manner in a supposedly functional language. Also in order to easily move back and forward between two very good platforms I believe this table is key in maintaining patterns that can be used across both platforms. A short example would be the need to perform tail recursion on a list. In F# there are a number of methods using while/until/do and in erlang I find a tail recursion is normally required. To that end when I reach a need to iterate I try to implement a tail recursion so that when I'm writing programs I solve them the

T-SQL Select Distinct on Single Column of Multi Column Select

After a long day at work I realized I needed to do a distinct select on a integer column and read any value in the other columns. Seemed simple but was a bit of a pain to grasp the query syntax. An example implementation: SELECT DISTINCT Rating, MAX(Title) FROM WallpaperGallery Group By Rating   Two important notes about the query. We run a distinct on [Rating] and we also need an aggregate function on the next column (can be max, min, etc.)  The second note is that the grouping need to happen on the distinct column and no other so that we have one row per distinct value in the [Rating] column. This query will disregard [Title]s that are not distinct for each distinct [Rating]. So if we have 10 rows with five distinct [Rating]s and all the titles are distinct then we will get 5 rows returned with the result of the Max() function on the Title column.

Modify DataView XSLT to Add Url in Grid to Workflow Initiation Form

I recently created a data view. I wanted a simple link to the list items workflow initiation form, to simply allow the user to access and start the workflow. The confusing aspect of all this is that normally we could do something simple such as <a href= http://someurl/page.aspx?ID={@ID} ></a> The xsl transform will resolve {@ID } to the value of @ID. The problem with this was that I actually also needed to include ListID and TemplateID both of these query parameters require the Guid to be wrapped in curly braces. So I modified the above and added a ListID to create the following: <a href= http://someurl/page.aspx?ID={@ID} &List={05cf277f-5d2e-4b46-8dc9-27a1e1c5ff36}></a> The first I problem I had with this was an error occured due to the & ampersand. I needed to encode it to and to prevent Sharepoint from erroring as a result of unencoded text. The second problem is that curly braces resolve variables. So the second error was relating