Skip to content

Instantly share code, notes, and snippets.

View ronnieoverby's full-sized avatar
🏠
Working from home

Ronnie Overby ronnieoverby

🏠
Working from home
  • Olo
  • Lexington, NC
View GitHub Profile
void Main()
{
using(var l = new ReaderWriterLockSlim())
{
var tasks = Enumerable.Range(0,2).Select (i =>
Task.Run(() =>
{
l.EnterUpgradeableReadLock();
try
{
using System;
using System.Collections.Generic;
public class CharacterComparer : IEqualityComparer<char>, IEqualityComparer<string>
{
public static readonly CharacterComparer Ordinal = new CharacterComparer(StringComparer.Ordinal);
public static readonly CharacterComparer OrdinalIgnoreCase = new CharacterComparer(StringComparer.OrdinalIgnoreCase);
public static readonly CharacterComparer CurrentCulture = new CharacterComparer(StringComparer.CurrentCulture);
public static readonly CharacterComparer CurrentCultureIgnoreCase = new CharacterComparer(StringComparer.CurrentCultureIgnoreCase);
public static readonly CharacterComparer InvariantCulture = new CharacterComparer(StringComparer.InvariantCulture);
@ronnieoverby
ronnieoverby / JaroWinklerDistance.cs
Last active June 14, 2021 16:16
Some modifications to the algorithm found at http://stackoverflow.com/a/19165108/64334
public static class JaroWinklerDistance
{
/* The Winkler modification will not be applied unless the
* percent match was at or above the mWeightThreshold percent
* without the modification.
* Winkler's paper used a default value of 0.7
*/
private const double WeightThreshold = 0.7;
/* Size of the prefix to be concidered by the Winkler modification.
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace CoreTechs.Common
{
public class BufferedEnumerable<T> : IEnumerable<T>
{
var dt = DateTime.Parse("3/1/2015 12:07 AM", CultureInfo.CurrentCulture, DateTimeStyles.AssumeUniversal);
var dto = new DateTimeOffset(dt);
@ronnieoverby
ronnieoverby / index.html
Created March 5, 2015 02:56
peek @ password angular directive
<p>
The password input below is using the "peek-password" directive.
Focusing on the input will reveal the peek icon on the right side.
Hovering the mouse over the peek icon will cause the password value to be visible.
Try it!
</p>
<form ng-app="app" class="form-horizontal">
@ronnieoverby
ronnieoverby / Base64Extensions.cs
Created February 21, 2015 16:47
I got bored and implemented a base64 encoder/decoder. This is much slower than the .NET implementation.
public static class Base64Extensions
{
private static readonly Lazy<char[]> EncMap =
new Lazy<char[]>(BuildEncodingMap);
private static readonly Lazy<int[]> DecMap =
new Lazy<int[]>(BuildDecodingMap);
private const char Pad = '=';
public class ConcurrentList<T> : IList<T>, IDisposable
{
private ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
private int _count = 0;
public int Count
{
get
{
_lock.EnterReadLock();
@ronnieoverby
ronnieoverby / DemoGettingUsersInSpecificRole.cs
Created January 30, 2015 21:57
Demonstrates efficiently querying the default MVC 5 entity framework model for users in a given role.
using System;
using System.Collections.Generic;
using System.Linq;
using WebApplication9.Models;
namespace WebApplication9
{
public class DemoGettingUsersInSpecificRole
{
private readonly ApplicationDbContext _db;
@ronnieoverby
ronnieoverby / epiphany.cs
Last active August 29, 2015 14:13
Comment after something happens, not before!
public void Write(RecordBase record)
{
if (record == null)
throw new ArgumentNullException("record");
// we have something to write
var spec = Spec.GetRecordSpec(record);
if (spec == null)
throw new UnknownRecordTypeException("Unknown record type: " + record.GetType().FullName);