Skip to content

Instantly share code, notes, and snippets.

View yetanotherchris's full-sized avatar
🔏
;ÿÿÿÿrules

Chris S. yetanotherchris

🔏
;ÿÿÿÿrules
View GitHub Profile
public class HashEncryption
{
/// <summary>
/// Encrypts a string using the MD5 hash encryption algorithm.
/// Message Digest is 128-bit and is commonly used to verify data, by checking
/// the 'MD5 checksum' of the data. Information on MD5 can be found at:
///
/// http://www.faqs.org/rfcs/rfc1321.html
/// </summary>
/// <param name="Data">A string containing the data to encrypt.</param>
@yetanotherchris
yetanotherchris / gist:4746180
Last active December 12, 2015 08:39
NetworkUtils
using System;
using System.Security;
using System.Net;
using System.Net.Sockets;
namespace Demo
{
public class NetworkUtils
{
/// <summary>
/// Performs a hostname lookup from an IP.
@yetanotherchris
yetanotherchris / gist:4746259
Created February 9, 2013 17:43
Factory design pattern example
namespace DesignPatterns
{
/// <summary>
/// Defines the methods/properties the plugin can support.
/// </summary>
public interface IPlugin
{
string GetDetails();
}
@yetanotherchris
yetanotherchris / gist:4746280
Created February 9, 2013 17:46
Abstract factory design pattern example
namespace DesignPatterns
{
public abstract class AbstractPluginFactory
{
public static AbstractPluginFactory GetFactory(string renderer)
{
switch (renderer)
{
case "ASPX":
return new ASPXRendererFactory();
@yetanotherchris
yetanotherchris / gist:4746293
Created February 9, 2013 17:49
Singleton example from Jon Skeet
public sealed class Singleton
{
Singleton()
{
}
public static Singleton Instance
{
get
{
@yetanotherchris
yetanotherchris / gist:4746312
Created February 9, 2013 17:58
Iterator design pattern example
namespace DesignPatterns
{
private static void IteratorTest()
{
IteratorExample example = new IteratorExample();
foreach (string item in example)
{
Console.WriteLine(item);
}
}
@yetanotherchris
yetanotherchris / gist:4746350
Last active December 12, 2015 08:48
Strategy design pattern example
namespace DesignPatterns
{
public class User
{
public string Name { get; set; }
public int Age { get; set; }
public override string ToString()
{
return string.Format("{0} {1}", Name, Age);
}
@yetanotherchris
yetanotherchris / gist:4746383
Created February 9, 2013 18:11
Visibility example
internal class FooBarDaddy
{
public void Run()
{
Foobar1 fb = new Foobar1();
}
/// Only accessible inside FooBarDaddy
private class Foobar1
{
@yetanotherchris
yetanotherchris / gist:4746404
Created February 9, 2013 18:15
Mediator design pattern example
namespace DesignPatterns
{
public delegate void MessageReceivedEventHandler(string message, string from);
public class Mediator
{
public event MessageReceivedEventHandler MessageReceived;
public void Send(string message, string from)
{
if (MessageReceived != null)
@yetanotherchris
yetanotherchris / gist:4746426
Last active December 12, 2015 08:48
Observer design pattern example
namespace DesignPatterns
{
/// <summary>
/// The use of an interface here mightseem a bit redundent, but it's to keep
/// inline with the original gang of 4 definition of the pattern. The implementing class
/// is still responsible for wiring itself to the Subject's notify event.
/// </summary>
public interface IObserver
{
void Update(string message);