Git Sparse Checkout Exclude

To exclude a directory, first include everything (e.g. /*), then exclude the specific folder or file:

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ git config core.sparsecheckout true

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ echo '/*' > .git/info/sparse-checkout

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ echo '!a_directory_i_want_to_exclude/' >> .git/info/sparse-checkout

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ git read-tree -m -u HEAD

This works with git 2.1.4

$ git --version
git version 2.1.4

PerformancePoint Dashboard Render Callback

Doing some JIT branding on a SharePoint 2010 site with bootstrap v2, I needed a way to determine when the PerformancePoint elements on a dashboard had finished loading. PerformancePoint has a problem (or maybe it’s my problem) calculating the width of its components with regard to bootstrap; I fooled it by giving the content area extra margin-left (67px in my case), and then taking it away once all PerformancePoint elements are loaded:

<script type="text/javascript">
    var NotifyBrowserOfAsyncUpdateTimeout = false;

    function NotifyBrowserOfAsyncUpdate(elem) {
        window.console && window.console.log('NotifyBrowserOfAsyncUpdate');
        if (NotifyBrowserOfAsyncUpdateTimeout) {
            clearTimeout(NotifyBrowserOfAsyncUpdateTimeout);
        }
        NotifyBrowserOfAsyncUpdateTimeout = setTimeout(function() {
            // do some stuff
            jQuery('#MSO_ContentTable').css('margin-left', '0');
            window.console && window.console.log('NotifyBrowserOfAsyncUpdateTimeout');
        }, 100);
    }
</script>

I added in the setTimeout/clearTimeout with a nominal 100ms duration, but it probably is not necessary; given some very light testing, by the time the first callback hits, PerformancePoint has correctly calculated the width of its components.

Credit: http://stackoverflow.com/questions/3372565/performancepoint-sharepoint-2010-and-jquery

Add git branch to a bash prompt

Add the following code to ~/.bash_profile or ~/.bashrc.

function ps1_git_branch {
    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \(\1\)/'
}

export PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\$(ps1_git_branch)\[\e[0m\]\n\$ "

When in a folder that contains a .git repository, the current branch will show up in parenthesis.

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$

Looking for something more complicated? Check out richardhansen’s https://github.com/git/…/git-prompt.sh contribution.

SharePoint 2010 Secure Store shared service is not responding

When trying to manage the Secure Store Service in SharePoint 2010 I ran into an error stating that the “secure store shared service is not responding…”

ULS logs dumped the following critical error message:

08/30/2013 12:27:50.80	w3wp.exe (0x1AEC)
0x16E8	Secure Store Service
Secure Store
7557
Critical
The Secure Store Service application Secure Store Service is not accessible. The 
full exception text is: The HTTP service located at 
http://localhost:32843/SecurityTokenServiceApplication/securitytoken.svc/actas 
is too busy.
68b1350d-de57-4ee8-922b-19a771c0b31b

After stumbling around google for a while, I came across the following article which suggested that the Security Token service needed to be reprovisioned: http://blogs.msdn.com/b/sowmyancs/archive/2010/07/16/sharepoint-2010-service-applications-bcs-metadata-access-service-are-not-working.aspx

PS C:\Users\uhleeka> Get-SPServiceApplication

DisplayName          TypeName             Id
-----------          --------             --
Secure Store Service Secure Store Serv... a785c55d-74fe-4c36-b3f0-ead5ce920fd0
State Service        State Service        da12d0c8-4455-4ff0-8d78-fafc17495f72
PerformancePoint ... PerformancePoint ... 287024db-317b-4157-b1cf-48fad7997e46
Visio Graphics Se... Visio Graphics Se... e67b7b0b-89c7-413e-97a3-3bdd2181c2e3
Managed Metadata ... Managed Metadata ... 9a407eef-f763-4f8a-a40e-13fcfc731372
Web Analytics Ser... Web Analytics Ser... 9a6bd1b0-3318-4018-b06f-e9bfcbeab042
Excel Services Ap... Excel Services Ap... ae2b3782-8434-4259-8941-de7f6a10e752
Security Token Se... Security Token Se... aea1b402-c567-414a-87ec-de78ef1c050d
Application Disco... Application Disco... aa7cd819-184e-4be3-97ce-bab1ddaa5ccb
Usage and Health ... Usage and Health ... 6c149bc0-1d6f-464a-a191-51afa27e9f89
Search Administra... Search Administra... 9f714436-729e-42ea-a8f0-94cc9f659d7d
Word Automation S... Word Automation S... 5849509b-27bb-4ea3-9377-77261832f58b
User Profile Serv... User Profile Serv... ad8c6f20-4f57-4c6b-82c1-2ff2e4c3894c
Business Data Con... Business Data Con... b352de0b-1bb4-4998-83c2-93d239abcabf
Search Service Ap... Search Service Ap... 14e512ae-59fa-4a21-9cfd-9cfbc7392293


PS C:\Users\uhleeka> $sts = Get-SPServiceApplication | ?{$_ -match "Security"}
PS C:\Users\uhleeka> $sts

DisplayName          TypeName             Id
-----------          --------             --
Security Token Se... Security Token Se... aea1b402-c567-414a-87ec-de78ef1c050d


PS C:\Users\uhleeka> $sts.Status
Online
PS C:\Users\uhleeka> $sts.Provision()

PowerShell to the rescue. Thankx sowmyancs!

Git Sparse Checkout

From the root of your local git repo:

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ git config core.sparsecheckout true

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ echo a_directory_i_want_to_include/ > .git/info/sparse-checkout

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ echo another_directory_i_want_to_include/ >> .git/info/sparse-checkout

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ git read-tree -m -u HEAD

Validate:

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ ls
a_directory_i_want_to_include/ another_directory_i_want_to_include/
Filed Under: Git | Tagged:

SharePoint 2010 SPSecurity.RunWithElevatedPrivileges HandleAccessDenied

The Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges method enables you to supply a delegate that runs a subset of code in the context of an account with higher privileges than the current user.

Using SharePoint context with an unauthenticated user does not actually elevate privileges:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    // do something with SPContext.Current.Web 
    // fails with a HandleAccessDenied Exception
    // because SPContext is loaded with the site,
    // not within this delegate block.
});

So to get actual elevated privileges, you have to reload the context:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite site = new SPSite(this.Page.Request.Url.ToString()))
    {
        using (SPWeb thisWeb = site.OpenWeb())
        {
            // do something with thisWeb
        }
    }
});

See here for a better explanation: http://www.danlarson.com/spsecurity-runwithelevatedpriveleges/

C# Hash String to Hexadecimal String

Outputs a 40 character hexadecimal hash string using the MD5 algorithm.

private string ToHash(string source)
{
    byte[] bytes;
    char[] c;
    byte b;
	
    //using (SHA1 m = new System.Security.Cryptography.SHA1Managed())
    using (MD5 m = System.Security.Cryptography.MD5.Create())
    {
        bytes = m.ComputeHash(System.Text.UTF8Encoding.UTF8.GetBytes(source));
        c = new char[bytes.Length * 2];
        for (int i = 0; i < bytes.Length; ++i)
        {
            b = ((byte)(bytes[i] >> 4));
            // replace 0x57 with 0x37 to output uppercase
            c[i * 2] = (char)(b > 9 ? b + 0x57 : b + 0x30);
            b = ((byte)(bytes[i] & 0xF));
            // replace 0x57 with 0x37 to output uppercase
            c[i * 2 + 1] = (char)(b > 9 ? b + 0x57 : b + 0x30);
        }
    }
    return new string(c);
}

C# Thread.Sleep(TimeSpan) to Run Every 10 minutes

Based on truncating a DateTime to the second in C# while preserving the “Kind” (Local, UTC, Undefined):

dateTime = dateTime.AddTicks( - (dateTime.Ticks % TimeSpan.TicksPerSecond));

Thread.Sleep until the next 10 minute mark (e.g. Run every 00, 10, 20, 30, 40, 50 minutes):

Thread.Sleep(
    TimeSpan.FromTicks(
        (TimeSpan.TicksPerMinute * 10) - 
        (DateTime.Now.Ticks % (TimeSpan.TicksPerMinute * 10))
    )
);

Credit: http://stackoverflow.com/a/1005222/152852

In the real world, the above code appears to be waking up a fraction of a second too early. So perhaps adding an additional tick might be the way to go:

Thread.Sleep(
    TimeSpan.FromTicks(
        1 + (TimeSpan.TicksPerMinute * 10) - 
        (DateTime.Now.Ticks % (TimeSpan.TicksPerMinute * 10))
    )
);

Less than percent colon – code render blocks in ASP.NET

ASP.NET 4.0 introduces the following code render block syntax:

<%: YourOutput() %>

The search terms “less than percent colon” and “less than percentage colon” did not turn up anything for me in google, but thanks to stackoverflow:

http://stackoverflow.com/questions/2676236/are-and-the-same-thing-as-embbed-code-expression-blocks

<%: is almost the same as <%= except that the output from <%: is automagically html encoded.