Skip to content

Instantly share code, notes, and snippets.

@jesslilly
jesslilly / ProductControl.cs
Last active August 11, 2023 17:09
How would you refactor this code?
using System.Collections.ObjectModel;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace MyApplication.Web.Controllers
{
public class ProductControl : Controller
{
@jesslilly
jesslilly / AttributeCrudCommands.cs
Last active March 14, 2024 18:04
Jess Lilly Sample Code .NET 6 MVC
using Domain.Toolkit;
using Domain.Sample.AppModels.Attributes;
using Domain.Sample.DbModels.Sample;
namespace Domain.Sample.Services.Attributes;
public class AttributeCrudCommands : IAttributeCrudCommands
{
private readonly SampleDbContext _db;
private readonly ILogger<AttributeCrudCommands> _logger;
@jesslilly
jesslilly / !jQuery Functions
Last active April 30, 2020 20:48
Some jQuery to do various common things
Using this file to rename the gist
@jesslilly
jesslilly / HtmlSanitizerTests.cs
Created January 31, 2020 14:22
MSTEST Stub for Ganss.XSS.HtmlSanitizer. Test your config.
using Ganss.XSS;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace VEIC.Tracker.Services.Tests.Shared
{
[TestClass]
public class HtmlSanitizerTests
{
private IHtmlSanitizer _htmlSanitizer;
@jesslilly
jesslilly / drop.sql
Created November 29, 2018 21:10
DROP ALL SQL SERVER TABLES
BEGIN -- Delete all tables in order to re-create.
DECLARE @sql NVARCHAR(MAX);
SET @sql = N'';
SELECT @sql = @sql + N'
ALTER TABLE ' + QUOTENAME(s.name) + N'.'
+ QUOTENAME(t.name) + N' DROP CONSTRAINT '
+ QUOTENAME(c.name) + ';'
FROM sys.objects AS c
INNER JOIN sys.tables AS t
@jesslilly
jesslilly / Program.cs
Created May 22, 2018 19:54
HttpClient.cs Authentication Error?
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleTestApp1
{
class Program
{
@jesslilly
jesslilly / BuildingDbContextFactory.cs
Created April 9, 2018 13:11
Simple IDesignTimeDbContextFactory example
public class FooDbContextFactory : IDesignTimeDbContextFactory<FooDbContext>
{
public FooDbContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<FooDbContext>();
optionsBuilder.UseSqlServer("DeaultConnection");
return new FooDbContext(optionsBuilder.Options);
}
}
@jesslilly
jesslilly / gist:e6ccf70736bc1a8ae9abe5afc212c1de
Created February 8, 2018 13:13
Vue Directive on show-bs-tab
Vue.directive('on-show-bs-tab', {
bind: function (el, binding) {
// This is BS4 jQuery
// When the tab is activated, load the data!
$(el).on('show.bs.tab', function (e) {
if (typeof binding.value === "function") {
binding.value.call();
}
});
}
@jesslilly
jesslilly / CampaignMonitor.cs
Created October 10, 2017 18:03
Get all list names and list IDs from Campaign Monitor (createsend_dotnet)
[TestMethod]
public void PrintListIds()
{
PrintListIds("key", "id");
PrintListIds("key", "id");
PrintListIds("key", "id");
}
private static void PrintListIds(string apiKey, string clientId)
{
[Test]
public void GetSimilarity_SpaceInTarget_NotZero()
{
var matcher = new SimMetricsMetricUtilities.JaroWinkler();
var target = " 1 main";
var candidate = "1 main st";
var similarity = matcher.GetSimilarity(candidate, target);
var message = string.Format("Expect similarity {0} to be > .9", similarity);
Assert.IsTrue(similarity > .90, message);