Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Drawing;
using Console = Colorful.Console;
namespace lolcmd
{
class Program
{
private static Random random = new Random();
@rushfrisby
rushfrisby / ServiceHelper.cs
Created April 5, 2017 19:46
WCF Service Helper
using System;
using System.ServiceModel;
public class ServiceHelper
{
#region Public Methods
/// <summary>
/// WCF proxys do not clean up properly if they throw an exception. This method ensures that the service proxy is handled correctly.
/// Do not call TService.Close() or TService.Abort() within the action lambda.
@rushfrisby
rushfrisby / KeyLockerExample.cs
Created June 30, 2015 15:41
Using KeyLocker
class KeyLockerExample
{
static readonly ThreadState[] StopStates = { ThreadState.AbortRequested, ThreadState.Aborted };
static void Main()
{
var threads = new List<Thread>();
var sw = new Stopwatch();
var timelimit = new TimeSpan(0, 0, 30);
@rushfrisby
rushfrisby / KeyLocker.cs
Created June 30, 2015 15:34
Class that locks on objects in a dictionary by key.
public class KeyLocker : IDisposable
{
private static readonly ConcurrentDictionary<object, object> Locks = new ConcurrentDictionary<object, object>();
private readonly object _locker;
public KeyLocker(object key)
{
_locker = Locks.GetOrAdd(key, new object());
Monitor.Enter(_locker);
}
@rushfrisby
rushfrisby / bad_code.cs
Created June 15, 2015 19:53
Intentionally bad code...
public interface IUserService
{
User GetUser(string userName);
}
public static class UserService : IUserService
{
public User GetUser(string userName)
{
using(var context = new SomeDbContext())
@rushfrisby
rushfrisby / linq.js
Created June 10, 2015 13:16
linq.js with the addition of CRUD methods
/*--------------------------------------------------------------------------
* linq.js - LINQ for JavaScript
* ver 2.2.0.2 (Jan. 21th, 2011)
*
* created and maintained by neuecc <ils@neue.cc>
* licensed under Microsoft Public License(Ms-PL)
* http://neue.cc/
* http://linqjs.codeplex.com/
*--------------------------------------------------------------------------*/
@rushfrisby
rushfrisby / Surrogate.cs
Last active August 29, 2015 14:21
Surrogate example question
class Parent {
DateTime CreatedOn {get;set;}
}
class DateTimeSurrogate {
long Value {get;set;}
}
//will other system need to mimic above structure or can other system deserialize as
@rushfrisby
rushfrisby / MyNameValueInfo.cs
Created April 2, 2015 05:04
Example class that cant be serialized by protobuf-net
[DataContract]
public class MyNameValueInfo
{
[DataMember(Order = 1)]
public string Name { get; set; }
[DataMember(Order = 2)]
public object Value { get; set; }
}
@rushfrisby
rushfrisby / MyNameValueInfoSurrogate.cs
Last active May 26, 2021 15:27
Example surrogate class for protobuf-net
[DataContract]
public class MyNameValueInfoSurrogate
{
//string is serializable so we'll just copy this property back and forth
[DataMember(Order = 1)]
public string Name { get; set; }
//byte[] is serializable so we'll need to convert object to byte[] and back again
[DataMember(Order = 2)]
public byte[] Value { get; set; }
@rushfrisby
rushfrisby / plugin-page.php
Created March 20, 2015 03:36
Bootstrap wrapper html example
<div class="bootstrap-wrapper">
<button class="btn btn-primary">Click me</button>
</div>