Skip to content

Instantly share code, notes, and snippets.

View Deathspike's full-sized avatar

Deathspike

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / gist:8496429
Created January 18, 2014 21:04
simple reflection with interface and attribute c#
using System;
using System.Linq;
using System.Reflection;
namespace reflectos {
// interface to implement a command
interface ICommand {
void Run();
}
@Deathspike
Deathspike / gist:8496311
Created January 18, 2014 20:56
simple reflection command with interface C#
using System;
using System.Linq;
using System.Reflection;
namespace reflectos {
// interface to implement a command
interface ICommand {
string Name { get; }
void Run();
}
@Deathspike
Deathspike / gist:8495642
Created January 18, 2014 20:15
super simple web crawler example (c#) for random people on SO (needs error checking; your job)
using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
namespace Crawl {
class Crawlie {
private HashSet<string> _crawled;
private List<string> _matches;
public byte[] Delta() {
// Make a snapshot of the pixels in RGBA format.
byte[] Snapshot = _Capturer.Snapshot();
// Check if the previous snapshot is invalid.
if (_PreviousSnapshot != null) {
// Initialize a new instance of the MemoryStream class.
using (MemoryStream MemoryStream = new MemoryStream()) {
using (var zipper = new GZipStream(MemoryStream, CompressionLevel.Fastest)) {
// Initialize a new instance of the BinaryWriter class.
using (BinaryWriter BinaryWriter = new BinaryWriter(zipper)) {