Skip to content

Instantly share code, notes, and snippets.

@theuntitled
theuntitled / ApplicationUser.cs
Last active October 26, 2023 17:12
Ignoring "Roles", "Claims" and "Logins" when serializing an ApplicationUser / IdentityUser
using System;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNet.Identity.EntityFramework;
using Newtonsoft.Json;
namespace Project.Models
{
[MetadataType(typeof (ApplicationUserMetaData))]
public class ApplicationUser : IdentityUser
{
@theuntitled
theuntitled / ByteRangesRouteConstraint.cs
Created October 10, 2019 10:20
ASP.NET Core 3 Partial Content Response (Status Code 206) for electron-updater
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
namespace Example
{
public class ByteRangesRouteConstraint : IRouteConstraint
{
public bool Match(HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection)
{
if (!values.TryGetValue("url", out var url) || url == null)
@theuntitled
theuntitled / MediaHotkeys.cs
Created November 30, 2015 16:10
Send Media Hotkeys with C#
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace MediaHotkeys
{
internal class Program
{
[DllImport("user32.dll", SetLastError = true)]
private static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
@theuntitled
theuntitled / dotnet-dev-cert.ps1
Created January 14, 2022 00:13
Generate a https certificate with dotnet
dotnet dev-certs https -ep "dev-cert.pfx" -p "d@nK3w1lhELm"
dotnet dev-certs https --trust
@theuntitled
theuntitled / rainbows.css
Created June 9, 2017 12:51
Rainbow text effect for your text
.easteregg {
animation: rainbow 1s infinite linear;
-moz-animation: rainbow 1s infinite linear;
-webkit-animation: rainbow 1s infinite linear;
-o-animation: rainbow 1s infinite linear;
-webkit-transition: color;
-moz-transition: color;
-o-transition: color;
transition: color
}
@theuntitled
theuntitled / CustomPasswordHasher.cs
Last active March 27, 2019 02:26
IdentitityFramework 2 Custom SHA256 IPasswordHasher with Salt
using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.AspNet.Identity;
namespace Project
{
public class CustomPasswordHasher<TUser> : ICustomPasswordHasher<TUser> where TUser : class , IUser<string>
{
@theuntitled
theuntitled / Measure.sql
Created February 27, 2019 09:37
Measures the elapsed time for a query in milliseconds.
DECLARE @t1 DATETIME;
DECLARE @t2 DATETIME;
SET @t1 = GETDATE();
-- Query to measure
SET @t2 = GETDATE();
SELECT DATEDIFF(millisecond,@t1,@t2) AS elapsed_ms;
@theuntitled
theuntitled / DataContext.cs
Last active December 14, 2018 11:12
Elmah v1.2 POCO and Code First Migration
using System.Data.Entity;
using ProjectName.Models;
namespace ProjectName {
public class DataContext : DbContext {
internal DbSet<ElmahError> ElmahErrors { get; set; }
}
@theuntitled
theuntitled / CustomSqlErrorLog.cs
Created April 19, 2017 13:54
ASP.NET MVC error page containing the ELMAH error id
using System.Collections;
using System.Web;
using Elmah;
namespace Project
{
/// <summary>
/// A custom implementation of the elamh provided <see cref="SqlErrorLog" />.
/// </summary>
public class CustomSqlErrorLog : SqlErrorLog
@theuntitled
theuntitled / TaxonomySearchResult.ts
Created September 20, 2016 11:50
SharePoint 2013 JSOM Taxonomy Managed Metadata Field Result
class TaxonomySearchResult {
id: string;
label: string;
termSetId: string;
parentTermId: string;
constructor(resultValue: string) {
const informationParts = resultValue.split(";");
for (let i = 0; i < informationParts.length; i++) {