Skip to content

Instantly share code, notes, and snippets.

View michaelbramwell's full-sized avatar

696d656b michaelbramwell

  • Perth Australia
View GitHub Profile
@michaelbramwell
michaelbramwell / MSSql Kill PID
Last active March 1, 2016 03:23
MSSql Kill PID - Use when db ops are failing like restore due to existing processes connecting to db
EXEC sp_who2
-- then
KILL <PID No.>
@michaelbramwell
michaelbramwell / GetFromDictionary.cs
Last active March 9, 2016 01:24
Generic get/set operation for types that are stored in an implementation of <see cref="IDictionary"/>
public static T GetFromDictionary<T>(string key, IDictionary items, Func<T> whenKeyNotFound)
{
if (items[key] != null)
{
// return from dictionary
return (T)items[key];
}
// return new item from caller and add to dictionary
@michaelbramwell
michaelbramwell / hexToRgb.js
Last active February 17, 2016 03:46
Hex to Rgb
var hexToRgb = function(hex) {
var parse = function(start, end){
return parseInt(hex.substring(start, end), 16);
}
hex = hex.replace("#", "");
return {
r: parse(0, 2),
g: parse(2, 4),
@michaelbramwell
michaelbramwell / RecursiveCopyToOneDirectory.bat
Last active January 14, 2016 01:59
Recursive copy to one directory
for /r "C:\sourceDir" %%f in (*.fileExt) do @xcopy "%%f" "C:\targetDir" /D /Y
@michaelbramwell
michaelbramwell / MapMultiColumnFieldsFromCSVToOneProperty.cs
Created May 21, 2015 02:11
Map Multi Column Fields From CSV to one property
public static string ParseMultiColumnFields(KeyValuePair<int, List<string>> row, int fromColumn, int toColumn)
{
var fields = new StringBuilder();
int lineCount = 0;
for (int i = fromColumn; i <= toColumn; i++)
{
if (string.IsNullOrEmpty(row.Value[i]))
{
break;
}
@michaelbramwell
michaelbramwell / GenericValidationParser.cs
Last active August 29, 2015 14:21
Generic Validation Parser
public static T ParseRequiredValue<T>(string value, Expression<Func<T>> property) where T : IConvertible
{
var propertyInfo = ((MemberExpression)property.Body).Member as PropertyInfo;
if (typeof(T) == typeof(DateTime))
{
DateTime dt;
bool canConvert = DateTime.TryParse(value, CultureInfo.CurrentCulture, DateTimeStyles.None, out dt);
if (!canConvert)
@michaelbramwell
michaelbramwell / TokenReplacementFileExtensions
Created May 6, 2015 07:35
SharePoint Token Replacement File Extensions
<!-- Must include this proj file when creating isapi svc's -->
<TokenReplacementFileExtensions>svc</TokenReplacementFileExtensions>
@michaelbramwell
michaelbramwell / Factory.cs
Last active January 30, 2017 14:08
Factory
public interface IFactory
{
IAbbreviationsAndAcronymsService AbbreviationsAndAcronymsService {get; set;}
IBusinessActivityService BusinessActivityService {get; set;}
Factory Make(ConcreteTypes type);
}
public class Factory
{
public IAbbreviationsAndAcronymsService AbbreviationsAndAcronymsService;
@michaelbramwell
michaelbramwell / SPMailWrapper.cs
Last active August 29, 2015 14:17
SP MailWrapper
/// <summary>
/// Handles Sending of Email notifications
/// SP Central Admin From address will be used when From() not provided
/// Example Usage:
/// MailNotification mailNotification = new MailNotification(SPContext.Current.Web)
/// mailNotification.To("someone@somewhere.com.au")
/// .From("admin@somewhere.com.au")
/// .Subject("You Have Mail")
/// .Body("Hello <strong>world</strong>")
/// .Send();
@michaelbramwell
michaelbramwell / ConsumeSharePointListODataServiceAsJSON.cs
Last active August 29, 2015 14:16
Consume SharePoint List OData Service as JSON
// dependencies - json request to model util, PredicateBuilder, cache util, models generated from service
public class SomeService
{
/// <summary>
/// Call this constructor when the fully formed service url is not known e.g on init
/// </summary>
public SomeService()
{
this.ServiceUrl = "someAbsurl";
}