Skip to content

Instantly share code, notes, and snippets.

Avatar
🍻
Doing the work

Rush Frisby rushfrisby

🍻
Doing the work
View GitHub Profile
View Colorful_Console_16.cs
using System;
using System.Drawing;
using Console = Colorful.Console;
namespace lolcmd
{
class Program
{
private static Random random = new Random();
View ServiceHelper.cs
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.
View KeyLockerExample.cs
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 Jun 30, 2015
Class that locks on objects in a dictionary by key.
View KeyLocker.cs
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 Jun 15, 2015
Intentionally bad code...
View bad_code.cs
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 Jun 10, 2015
linq.js with the addition of CRUD methods
View linq.js
/*--------------------------------------------------------------------------
* 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 Aug 29, 2015
Surrogate example question
View Surrogate.cs
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 Apr 2, 2015
Example class that cant be serialized by protobuf-net
View MyNameValueInfo.cs
[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
Example surrogate class for protobuf-net
View MyNameValueInfoSurrogate.cs
[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 Mar 20, 2015
Bootstrap wrapper html example
View plugin-page.php
<div class="bootstrap-wrapper">
<button class="btn btn-primary">Click me</button>
</div>