Skip to content

Instantly share code, notes, and snippets.

View lorddev's full-sized avatar
🎻
likes music

Aaron lorddev

🎻
likes music
View GitHub Profile
@lorddev
lorddev / IBusinessRules.cs
Last active June 17, 2016 13:26
Ideas on a business rules implementation
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Devlord.Utilities
{
/// <summary>
/// Use for designing a business rule where conditions are evaluated and the actions are executed based on the evaluation.
/// Rules can be chained by setting the "Action" as another business rule.
@lorddev
lorddev / Git-Prune-Branches
Created February 16, 2016 19:20
PowerShell script for pruning branches already merged
function Prune-Branches
{
git branch --merged | ForEach-Object { $_.Trim() } |
Where-Object {-not ( $_ -Like "*master" )} | Where-Object {-not ( $_ -Like "*develop" )} | ForEach-Object { git branch -d $_.Replace('origin/', '') }
}
@lorddev
lorddev / AntiForgeryTokenValidator.asp
Last active May 23, 2024 17:59
Classic ASP version of ASP.NET MVC AntiForgeryToken validator
<%
' Use with a very short session (basically the page lifecycle, GET then POST)
Class AntiForgeryValidator
Private m_securityToken
Sub SetCookie()
m_securityToken = CreateWindowsGuid()
Response.Cookies("RequestVerificationToken") = m_securityToken
@lorddev
lorddev / UnderscoreContractResolver.cs
Last active August 29, 2015 13:57
Say you're trying to serialize a JSON API such as Google Maps where all the properties are lowercase and words are separated by underscores. But in order to keep your own code clean, you need to use camel casing...
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace Test
{
public class FooTest
{
public void TestCustomResolver()
{
@lorddev
lorddev / parsehashbang.js
Last active August 29, 2015 13:56 — forked from miohtama/parse-hash-bang-arguments-in-javascript.js
Useful for ajax navigation
/**
* Parse hash bang parameters from a URL as key value object.
*
* #x&y=3 -> { x:null, y:3 }
*
* @param aURL URL to parse or null if window.location is used
* @return Object of key -> value mappings.
*/
function parseHashBang(url) {
url = url || window.location.href;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EntityExtensions {
public class FakeDbSet<T> : System.Data.Entity.IDbSet<T> where T : class {
private readonly List<T> list = new List<T>();
public FakeDbSet() {
@lorddev
lorddev / DAL method wrapper.cs
Created November 11, 2012 04:37
Tiny method that wraps the delegate you pass into it with standard connection/command using blocks
/// <summary>
/// Speeds up DAL development by reducing repeated code.
/// </summary>
private void OpenConnectionAndDispose(string storedProcedure, Action<SqlCommand> action)
{
using (var conn = new SqlConnection(connectionString))
{
using (var command = new SqlCommand(query, conn))
{
command.CommandType = CommandType.StoredProcedure;
@lorddev
lorddev / IEachified.cs
Created October 21, 2012 18:59
Enforces a rule that a collection can perform a certain action on each of its items.
/// <summary>
/// Enforces a rule that a collection can perform a certain action on each of its items.
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IEachified<T>
{
void ForEach(Action<T> action);
}