Skip to content

Instantly share code, notes, and snippets.

@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 / PrettyFileSize.cs
Last active April 20, 2016 11:29
Pretty / Human readable file size formatter
namespace Project {
public static class Utilities {
public static string[] ByteUnits = {"kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"};
public static string GetPrettyFileSize(int fileSize) {
return GetPrettyFileSize((double)fileSize);
}
@theuntitled
theuntitled / ListExtensions.cs
Created April 15, 2016 08:50
Mnemonic Password Generator
using System;
using System.Collections.Generic;
namespace Gists
{
public static class ListExtensions
{
public static T GetRandom<T>(this List<T> list, Random random = null)
{
random = random ?? new Random();
@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 / angular-typescript-inject-demo.ts
Last active March 30, 2016 12:48
TypeScript AngularJS 1.x $inject example
module Dev.Controllers {
export class DemoController {
static $inject: string[] = ["$scope"];
constructor($scope: any) {
// ...
}
@theuntitled
theuntitled / magic.sql
Created March 17, 2016 12:01
Select the size and number of rows for each table of the database
SELECT
t.NAME AS TableName,
s.Name AS SchemaName,
p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM
sys.tables t
INNER JOIN
@theuntitled
theuntitled / DataContext
Created January 19, 2016 15:34
Nice table names for the IdentityFramework
modelBuilder.Entity<ApplicationUser>().ToTable("Users");
modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles");
modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins");
modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims");
modelBuilder.Entity<IdentityRole>().ToTable("Roles");
@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 / BootgridExample.cs
Created March 6, 2015 16:13
Bootgrid WebAPI Request / Response Handling
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Linq;
using System.Web.Http;
using System.Web.Http.Description;
namespace Projektname.BootgridStuff {
/// <summary>
/// Represents a xhr request from a bootgrid component
@theuntitled
theuntitled / SomeCopyText.cshtml
Created December 2, 2014 18:29
.NET MVC 5 Themed Partial Extension Method
<p>Text that does not need to be themed</p>