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
@ronnieoverby
ronnieoverby / App.xaml.cs
Last active September 16, 2023 12:08
wpf global exception handling
// somewhere early in App.xaml.cs
AppDomain.CurrentDomain.UnhandledException += (s, e) =>
LogUnhandledException((Exception) e.ExceptionObject, "AppDomain.CurrentDomain.UnhandledException");
DispatcherUnhandledException += (s, e) =>
LogUnhandledException(e.Exception, "Application.Current.DispatcherUnhandledException");
TaskScheduler.UnobservedTaskException += (s, e) =>
LogUnhandledException(e.Exception, "TaskScheduler.UnobservedTaskException");
public class ConcurrentList<T> : IList<T>, IDisposable
{
private ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
private int _count = 0;
public int Count
{
get
{
_lock.EnterReadLock();
public static class SftpExtensions
{
/// <remarks>
/// unfortunately the ssh library doesn't expose a modern async api
/// that supports cancellation via CancellationToken
/// so we have to wrap the APM pattern with a TaskCompletionSource
/// </remarks>
public static Task UploadFileAsync(this SftpClient sftpClient, Stream input, string path, bool canOverride, Action<ulong> uploadCallback = null, CancellationToken cancellationToken = default(CancellationToken))
{
var tcs = new TaskCompletionSource<SftpUploadAsyncResult>();
internal static IEnumerable<string> ReadLines(this string s)
{
string line;
using (var sr = new StringReader(s))
while ((line = sr.ReadLine()) != null)
yield return line;
}
<script>
// loop over all "up-down" elements
for(let ud of document.querySelectorAll('span[id$=ud]'))
{
// reflect that it is already expanded
ud.className = 'arrow-up';
// derive the expandable element's id
let id = ud.id.substring(0, ud.id.length - 2);
@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.
@ronnieoverby
ronnieoverby / channels.cs
Last active March 11, 2020 12:48
An example when `Task.Yield()` is useful
var ch = Channel.CreateUnbounded<int>();
var producer = Task.Run(() =>
{
for (int i = 0; i < 500_000; i++)
ch.Writer.WriteAsync(i);
ch.Writer.Complete();
});
### Keybase proof
I hereby claim:
* I am ronnieoverby on github.
* I am ronnieoverby (https://keybase.io/ronnieoverby) on keybase.
* I have a public key ASCXPI6o5jpbNT7RowJ7h_vBeGh0pzcksHwfhqWFQNVxUgo
To claim this, I am signing this object:
@ronnieoverby
ronnieoverby / gist:416183f553bc8a2399339742057ab220
Created April 23, 2019 12:47
Reading references on value types vs. reference types.
https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/data-types/value-types-and-reference-types
https://jonskeet.uk/csharp/references.html
http://www.albahari.com/valuevsreftypes.aspx
@ronnieoverby
ronnieoverby / gist:5d67fc7b4e18ad0c3e2d6c2e140ddddd
Created April 23, 2019 12:47
Reading references on value types vs. reference types.
https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/data-types/value-types-and-reference-types
https://jonskeet.uk/csharp/references.html
http://www.albahari.com/valuevsreftypes.aspx