Skip to content

Instantly share code, notes, and snippets.

View lukencode's full-sized avatar
🙃

Luke Lowrey lukencode

🙃
View GitHub Profile
@lukencode
lukencode / ListDiff.cs
Last active October 11, 2015 23:28
Quick class for determining changes (additions, removals) in lists
public static class ListDiff
{
public static List<ListDiffItem<T>> GetDiff<T>(List<T> oldList, List<T> newList, Func<T, T, bool> equalsFunction = null)
{
var combined = new List<ListDiffItem<T>>();
foreach(var i in newList)
{
var diff = new ListDiffItem<T>();
diff.Item = i;
@lukencode
lukencode / Hierarchyize.cs
Last active October 13, 2015 17:17
I have know idea if this will work...
public static class Hierarchyize
{
public static List<Nested<T>> Transform<T>(IEnumerable<T> items, Func<T, T, bool> isParentFunction, Func<T, bool> isRootFunction)
{
Action<Nested<T>> setChildren = null;
setChildren = parent =>
{
parent.Children = items
.Where(childItem => isParentFunction(childItem, parent.Item))
@lukencode
lukencode / widget.js
Last active December 7, 2021 19:16
Starter template for creating jsonp embeddable widgets.
(function () {
var scriptName = "embed.js"; //name of this script, used to get reference to own tag
var jQuery; //noconflict reference to jquery
var jqueryPath = "http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js";
var jqueryVersion = "1.8.3";
var scriptTag; //reference to the html script tag
/******** Get reference to self (scriptTag) *********/
var allScripts = document.getElementsByTagName('script');
@lukencode
lukencode / octobuild.build
Created February 7, 2013 03:22
Octopack build script
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<PropertyGroup>
<DeployFiles>$(MSBuildStartupDirectory)\DeployFiles.msbuild</DeployFiles>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<VersionPatch>0</VersionPatch>
<ChangesetNumber>0</ChangesetNumber>
<NugetFileShare>\\itsmanv01\Releases</NugetFileShare>
Write-Host "Looking for " $OctopusPackageDirectoryPath "app_offline*.htm*"
if(Test-Path $OctopusPackageDirectoryPath\app_offline*.htm*)
{
ren $OctopusPackageDirectoryPath\app_offline*.htm* app_offline.htm
}
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<PropertyGroup>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<VersionPatch>0</VersionPatch>
<ChangesetNumber>0</ChangesetNumber>
<NugetFileShare>\\itsmanv01\Releases</NugetFileShare>
<SolutionPath>RequisitioningSolution.sln</SolutionPath>
CREATE PROCEDURE spNextStudySequence
@StudyID int
AS
DECLARE @temp table
(
ID bigint
);
UPDATE tStudy_Sequences
SET Sequence = Sequence + 1
@lukencode
lukencode / DbUp.cs
Created April 8, 2013 23:27
DbUp program with dodgy hack to create db if it doesnt exist - good for developing.
public class Program
{
/// <summary>
/// Entry point.
/// </summary>
/// <param name="args">The args.</param>
/// <returns></returns>
static int Main(string[] args)
{
var rawConnectionString = ConfigurationManager.ConnectionStrings["db"].ConnectionString;
@lukencode
lukencode / embeddedtemplate.cs
Created May 21, 2013 06:27
Embedded tempate
/// <summary>
/// Adds template to email from embedded resource
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="path">Path the the embedded resource eg [YourAssembly].[YourResourceFolder].[YourFilename.txt]</param>
/// <param name="model">Model for the template</param>
/// <param name="isHtml">True if Body is HTML, false for plain text (Optional)</param>
/// <param name="assembly">The assembly your resource is in. Defaults to calling assembly.</param>
/// <returns></returns>
public class DataMockHelpers
{
public Mock<IQeraUnit> GetMockUnit()
{
var unit = new Mock<IQeraUnit>();
return unit;
}
public Mock<TRepo> MockRepo<TRepo, TEntity>(List<TEntity> seedData = null, bool callBase = false, MockBehavior behavior = MockBehavior.Default)
where TRepo : class, IRepo<TEntity>