Skip to content

Instantly share code, notes, and snippets.

View Deathspike's full-sized avatar

Deathspike

View GitHub Profile
@Deathspike
Deathspike / gist:51475196ad129d4835dd
Created August 20, 2014 12:06
ASP.NET Grid.Mvc default filter to 'Contains' via JS
(function () {
TextFilterWidget.prototype.renderWidget = (function(fn) {
return function() {
this.value.filterType = '2';
fn.call(this);
};
})(TextFilterWidget.prototype.renderWidget);
})();
@Deathspike
Deathspike / Index.cshtml
Created December 11, 2014 11:12
ASP.NET MVC Strong-Typed Views with ViewModels
@model MyViewModel
<div>My strong-typed name is @Model.Name</div>
@Deathspike
Deathspike / Context.cs
Created January 14, 2015 14:11
Quick UoW implementation using and isolating EF from consuming code
public class Context : IContext
{
public readonly ServiceEntities _entities;
#region Constructor
public Context()
{
_entities = new ServiceEntities();
}
@Deathspike
Deathspike / DataController.cs
Last active June 14, 2018 21:00
ASP.NET MVC Using a Context in a DataController
public abstract class DataController : Controller
{
private IContext _context;
#region Constructor
protected DataController()
{
_context = new Context();
}
@Deathspike
Deathspike / Account.cs
Created February 5, 2015 15:52
C# Password Storage
public class Account
{
#region Abstract
private static string GenerateHash(string password, string salt, int iterations)
{
using (var rfc2898DeriveBytes = new Rfc2898DeriveBytes(password, Convert.FromBase64String(salt), iterations))
{
return Convert.ToBase64String(rfc2898DeriveBytes.GetBytes(64));
}
@Deathspike
Deathspike / require.ts
Last active May 12, 2017 13:12
Provides a synchronous require implementation for development purposes.
/* tslint:disable:no-eval */
/* tslint:disable:no-shadowed-variable */
/* tslint:disable:restrict-plus-operands */
/**
* Provides a synchronous require implementation for development purposes.
* @author Roel van Uden
* @license MIT
*/
let require = ((): {(id: string): any, detour?: (id: string, value: string | ((id: string) => any)) => void} => {
@Deathspike
Deathspike / Program.cs
Created August 7, 2015 12:43
Super simple and super naive threaded socket server with async/await
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
namespace Test {
internal class Program {
public static void Main() {
var client = Task.Run(() => Client());
@Deathspike
Deathspike / Bindable.cs
Created August 24, 2015 08:30
Example of a Bindable in .NET 4.5
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Rs.Os
{
internal abstract class Bindable : IBindable
{
#region Abstract
/**
* Extracts the property name from a property expression function.
* @param fn The function.
* @return The property name.
*/
function nameof(fn: Function): string {
var body = fn ? fn.toString() : null;
var lambdaExpression = body ? body.match(/(?:=>|return)\s*(.+?)\s*(?:;|}|$)/) : null;
var propertyExpression = lambdaExpression ? lambdaExpression[1].match(/\.\s*(.+?)\s*$/) : null;
if (propertyExpression != null) {
@Deathspike
Deathspike / Context.cs
Created January 20, 2016 09:07
EF6+ UoW
public class Context : IContext
{
private readonly Entities _entities; // EF6+ DbContext
#region Constructor
static Context()
{
var ensureReference = SqlProviderServices.Instance;
}