Skip to content

Instantly share code, notes, and snippets.

@rushfrisby
rushfrisby / JsonSchemaToPocos.cs
Last active June 2, 2023 07:45
Converts a JSON schema to C# POCO classes
class Program
{
private const string Cyrillic = "Cyrillic";
private const string Nullable = "?";
static void Main()
{
string schemaText;
using (var r = new StreamReader("schema.txt"))
@rushfrisby
rushfrisby / stopwatch.js
Last active April 7, 2022 13:28
Stopwatch class in JavaScript
function Stopwatch()
{
var sw = this;
var start = null;
var stop = null;
var isRunning = false;
sw.__defineGetter__("ElapsedMilliseconds", function()
{
return (isRunning ? new Date() : stop) - start;
@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; }
using System;
using System.Drawing;
using Console = Colorful.Console;
namespace lolcmd
{
class Program
{
private static Random random = new Random();
using System;
using System.Security.Cryptography;
using System.Text;
public static class Crypto
{
#region MD5
public static string HashMD5(string phrase)
{
@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 / 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 / bootstrap-hack.js
Created March 20, 2015 03:28
Bootstrap hack for wordpress admin
var bootstrapCss = 'bootstrapCss';
if (!document.getElementById(bootstrapCss))
{
var head = document.getElementsByTagName('head')[0];
var bootstrapWrapper = document.createElement('link');
bootstrapWrapper.id = bootstrapCss;
bootstrapWrapper.rel = 'stylesheet/less';
bootstrapWrapper.type = 'text/css';
bootstrapWrapper.href = '../wp-content/plugins/myplugin/css/bootstrap-wrapper.less';
bootstrapWrapper.media = 'all';
@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);
}