Skip to content

Instantly share code, notes, and snippets.

View AndyConlisk's full-sized avatar

Andy Conlisk AndyConlisk

  • Conlisk Consulting
  • Louisville, KY
View GitHub Profile
@AndyConlisk
AndyConlisk / Background.cs
Created January 3, 2015 22:11
Simple Background Tasks for ASP.NET
//Easy Background tasks in ASP.NET projects
//Inspiration from http://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/
//This code is added into the Global.asax file. In the Application_Start() method
private static CacheItemRemovedCallback OnCacheRemove = null;
protected void Application_start()
{
//The register code that is put in here
//Here is where you add all the tasks you want to start on application start
@AndyConlisk
AndyConlisk / ProductRandomImage.sql
Created January 5, 2015 19:26
SQL to get a random image from a product of the product category
SELECT b.Id AS BusinessId, COALESCE(subCategoryImage.Id, parentCategoryImage.Id) AS ImageAssetId, COALESCE(subCategoryImage.CategoryId, parentCategoryImage.CategoryId) AS CategoryId, b.Name, COALESCE(subCategoryImage.FileName, parentCategoryImage.FileName) AS FileName
FROM Businesses b
OUTER APPLY (
SELECT TOP 1 *
FROM ImageAssets
WHERE CategoryId = b.CategoryId
AND Deleted = 0
ORDER BY CHECKSUM(NEWID(), b.id) & 2147483647
) subCategoryImage
OUTER APPLY (
@AndyConlisk
AndyConlisk / sql_findTableUsageInStoredProc
Last active August 29, 2015 14:20
SQL statment to find all instances of utility in stored procs
SELECT DISTINCT so.name FROM syscomments sc INNER JOIN sysobjects so on sc.id=so.id WHERE sc.text LIKE '%utility%'
@AndyConlisk
AndyConlisk / combinemultiplerowintoone.sql
Created September 20, 2016 16:32
SQL select statement to combine multiple row vales into one field
SELECT p.Name, substring
((SELECT ', ' + k.Number FROM dbo.Keys k
JOIN dbo.Keys_Assignments ka ON ka.KeyID = k.KeyID
WHERE ka.PersonID = p.PersonID
FOR XML PATH('')), 2, 1000) [Keys]
FROM dbo.People p
SELECT k.Number, SUBSTRING
((SELECT '; ' + p.Name FROM dbo.People p
### Keybase proof
I hereby claim:
* I am andyconlisk on github.
* I am kingpancake (https://keybase.io/kingpancake) on keybase.
* I have a public key ASALMMqf4SM6CNyfc95F_w2_aYcKnvvdEA9bENXjbTLrlAo
To claim this, I am signing this object:
@AndyConlisk
AndyConlisk / projectsetupdescription.txt
Created March 2, 2017 14:32
Description on setting up MVC web projects
Application.Core
This namespace should contain all functionality that is not expansive enough to be in its own project but are required by multiple consumers/projects
- Logging and other cross access functions
- Generic helper classes for logging.
- Non-domain specific, independent functionality, and Profiling. Such as .NET Extension methods.
Application.Domain
This namespace contains the domain objects.
- Domain Objects (POCO), Shared data transfer objects, Models, ViewModels, etc
- Business logic for Validators, Filters, Factories, Regular expressions
Application.Data
@AndyConlisk
AndyConlisk / FindRemoveDuplicates.sql
Created March 8, 2017 14:12
Finding and removing duplicate rows from database
-- SQL databate table dbo.Test with columns Id, FirstName, LastName, TransactionNumber, LastUpdatedDate
-- Select rows that are duplicates without using LastUpdatedDate
-- If needed can insert into a backup/archive table
SELECT t.Id, t.FirstName, t.LastName, t.TransactionNumber, t.LastUpdatedDate
FROM dbo.Test t
LEFT OUTER JOIN (
SELECT MIN(Id) as Id,
FirstName, LastName, TransactionNumber
FROM dbo.Test
@AndyConlisk
AndyConlisk / Model1.cs
Created May 13, 2017 23:02
Example Entity Framework One to Many and Many to Many
namespace ComplexEntityFramework
{
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
public class Model1 : DbContext
{
public Model1()
: base("name=Model1")
@AndyConlisk
AndyConlisk / generateUUID.js
Created June 14, 2017 18:24
generate a UUID / GUID in javascript
function generateUUID() {
var d = new Date().getTime();
if (window.performance && typeof window.performance.now === "function") {
d += performance.now();; //use high-precision timer if available
}
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});