Skip to content

Instantly share code, notes, and snippets.

View csharpforevermore's full-sized avatar
🏠
Working from home

Randle csharpforevermore

🏠
Working from home
View GitHub Profile
@csharpforevermore
csharpforevermore / ReplaceStringCaseInsensitive.cs
Created February 12, 2014 17:06
Like String.Replace but can do so with regards to case and culture.
using System;
using System.Text;
public static class ExtensionMethods
{
/// <summary>
/// Case insensitive string replacement
/// </summary>
/// <param name="str">string to process</param>
/// <param name="oldValue">old value to find</param>
@csharpforevermore
csharpforevermore / DictionaryStringStringToString
Created February 13, 2014 05:16
Dictionary<string, string> to a single string with commas separating the keyvaluepairs
string s = string.Join(",", myDict.Select(x => x.Key + "=" + x.Value).ToArray());
@csharpforevermore
csharpforevermore / ListAllCachedUmbracoMacros.sql
Created February 17, 2014 09:19
In Umbraco, sometimes you want to know how many macros have caches. This query will tell you how long has been set on each macro.
/****** Script for SelectTopNRows command from SSMS ******/
SELECT *
FROM [dbo].[cmsMacro]
WHERE macroRefreshRate > 0
@csharpforevermore
csharpforevermore / GetMacroCacheDetails.sql
Created February 17, 2014 09:27
Umbraco 4.9.1 - show all macro cache settings.
/****** Script for SelectTopNRows command from SSMS ******/
SELECT
macro AS 'ID',
macroName AS 'Name',
macroPropertyAlias AS 'Alias',
macroRefreshRate AS 'Timeout'
FROM [dbo].[cmsMacroProperty] AS table1
LEFT OUTER JOIN [dbo].[cmsMacro] AS table2
ON table1.macro = table2.id
@csharpforevermore
csharpforevermore / ListInstalledPrograms.ps1
Created February 24, 2014 00:36
Shows a list of all the programs installed on the current machine.
Get-WmiObject -Class Win32_Product | Select-Object -Property Name
@csharpforevermore
csharpforevermore / ConfigurationHelper.cs
Created February 24, 2014 14:39
This static helper class allows the easy generation of a strongly typed web.config value.
/// <summary>
/// Helper class for accesing configuration file
/// </summary>
public class ConfigurationHelper
{
/// <summary>
/// Returns strongly typed application setting value
/// </summary>
/// <typeparam name="T">Entry type</typeparam>
/// <param name="key">configuraiton key</param>
@csharpforevermore
csharpforevermore / StringToEnum.cs
Created February 24, 2014 15:00
Parse a string to an enum
public static T ParseEnum<T>( string value )
{
return (T) Enum.Parse( typeof( T ), value, true );
}
@csharpforevermore
csharpforevermore / Answer.txt
Created February 24, 2014 15:03
What is the point of the IIS folder /aspnet_client/ ?
In the days of .NET 1.1, this gave sites JavaScript support. Safe to delete on most websites.
@csharpforevermore
csharpforevermore / ReplaceFooWithBar.ps1
Created February 28, 2014 00:23
Open the text file test.txt and replace all occurrences of "foo" with "bar"
(Get-Content test.txt) | ForEach-Object { $_ -replace "foo", "bar" } | Set-Content test.txt
@csharpforevermore
csharpforevermore / GetModelAsIPublishedContent
Created April 3, 2014 19:10
Get a view model as IPublishedContent.
UmbracoHelper Help = new UmbracoHelper(UmbracoContext.Current);
IEnumerable Item = Help.TypedContent(JsonId.ToString().Split(',')).OfType();