Skip to content

Instantly share code, notes, and snippets.

View CraftyFella's full-sized avatar

Dave Craft CraftyFella

View GitHub Profile
@CraftyFella
CraftyFella / gist:3017098
Created June 29, 2012 10:17
CanIDoSomething DoSomething Pattern
public interface IFoo
{
bool CanFoo(Bar bar);
void DoFoo(Bar bar);
}
public class Thing
{
private IEnumerable<IFoo> _foos;
public Thing(IEnumerable<IFoo> foos)
@CraftyFella
CraftyFella / new_vs_bind.js
Last active December 18, 2015 14:49
Understanding new in Java script vs bind
function Customer(name, age)
{
this.name = name;
this.age = age;
}
var dave = new Customer("Dave", 35)
Dump(dave);
var jax = {};
@CraftyFella
CraftyFella / TestingUt8EncodingAndHiddenBOM.cs
Created July 9, 2013 22:08
Xml Encoding UTF8 and Hidden BOM Byte
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using FluentAssertions;
using NUnit.Framework;
namespace TestingUt8EncodingAndHiddenBOM
{
@CraftyFella
CraftyFella / Replace Default Deserializer in MVC with Json.net Deserializer Example.cs
Last active December 20, 2015 00:29
Replace Default Deserializer in MVC with Json.net Deserializer Example
public class TestEndPointController : Controller
{
[HttpPost]
public ActionResult Record(RecordInputModel model)
{
return
Json(
new
{
success = true,
@CraftyFella
CraftyFella / Mongovue Query Examples.js
Last active December 20, 2015 04:09
Mongovue Query Examples
// Querying arrays by their size
{
"Field1": {$size: 0}
"Field2": {$not: {$size: 0}}
}
// Querying nested fields using a unique identifier
{
"Events.Payload.Body._t" : "EventType",
"Events.Payload.Body._id" : CSUUID("2267495d-63e3-4aa3-ae67-86372a7968fd")
@CraftyFella
CraftyFella / Example.cs
Created October 7, 2013 21:59
DynamicJsonBuilder using ServiceStack.Text
class Program
{
static void Main(string[] args)
{
const string json = "{ \"property\" : \"value\", \"property2\" : 34 }";
var dynamicJsonBuilder = DynamicJsonBuilder.Deserialize(json);
string jsonAfterBuilder = dynamicJsonBuilder
.WithProperty("value2")
.WithProperty2(55)
@CraftyFella
CraftyFella / expressionManipulation.cs
Created November 22, 2013 10:16
Anding two expressions together
using System;
using System.Collections.ObjectModel;
using System.Linq.Expressions;
namespace CTM.Home.MaiyaReports.Processors
{
void Main()
{
Expression<Func<ArrayList, bool>> @default = r => r.Count > 0 && r.Count < 2;
@CraftyFella
CraftyFella / main.cs
Created November 28, 2013 09:19
Example of dymamic dispatch, double dispatch and multiple dispatch
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
@CraftyFella
CraftyFella / TypeExtensions.cs
Created April 22, 2014 09:28
Type Extensions...
public static class TypeExtensions
{
public static bool HasAttribute<TAttribute>(this Type type) where TAttribute : Attribute
{
return type.CustomAttributes.Any(a => a.AttributeType == typeof (TAttribute));
}
public static IEnumerable<Type> DerivedTypesFrom<T>(this Assembly assembly)
{
return assembly.GetTypes().Where(typeof(T).IsAssignableFrom);
@CraftyFella
CraftyFella / steps.cmd
Created April 25, 2014 09:02
Find out which service is using a port on windows box.
# Show me a list of all processes. If they are a service give their name.
# Pipe to findstr which filter out anything that is "N/A" (I.e. only show services)
tasklist /SVC | findstr /V /C:"N/A"
# show me all listening and sending sockets
# -o show me their pid
netstat -a -o | findstr 4260