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 / MyExtensions.cs
Created October 21, 2016 13:25
Mitigates Linqpad DumpContainer MemoryDump
public static class MyExtensions
{
public static void UpdateContentOccasionally(this DumpContainer dc, object newContent, int intervalMilliseconds = 1000) =>
UpdateContentOccasionally(dc, newContent, TimeSpan.FromMilliseconds(intervalMilliseconds));
public static void UpdateContentOccasionally(this DumpContainer dc, object newContent, TimeSpan interval)
{
var swAttachment = dc.GetOrSetAttached(() => Stopwatch.StartNew());
@ronnieoverby
ronnieoverby / Global.asax.cs
Last active October 20, 2016 02:07
It's REALLY easy to create a Reverse HTTP Server with Web API
private void SetupRouting(HttpConfiguration config)
{
config.Routes.MapHttpRoute("proxy_else", "{*uri}", new
{
controller = "Proxy",
uri = RouteParameter.Optional
});
}
void Main()
{
var bytes = Encoding.UTF8.GetBytes("Anything you want");
var hash1 = new MD5().ComputeHash(bytes);
var hash2 = System.Security.Cryptography.MD5.Create().ComputeHash(bytes);
BitConverter.ToString(hash1).Dump();
BitConverter.ToString(hash2).Dump();
using System.Net.Http; // reference System.Net.Http.dll
using System.Net.Http.Headers;
using System.Threading.Tasks;
public static class MailgunSample
{
public static async Task<string> SendSimpleMessageAsync(string domain, string apikey, string from, string to, string subject, string text)
{
var authHeader = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(Encoding.ASCII.GetBytes($"api:{apikey}")));
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>();
@ronnieoverby
ronnieoverby / Privates.js
Created December 1, 2015 18:13
private state in ES6 classses
function Privates() {
var map = new WeakMap();
return function (obj) {
if (!map.has(obj))
map.set(obj, {});
return map.get(obj);
onmessage = function(msg) {
// TODO: long running code that uses msg.data to figure out answer to everything
postMessage(42);
};
public static class LightInjectExtensions
{
public static void RegisterFunc<T>(this IServiceRegistry reg, Func<IServiceFactory, T> factoryFunc)
{
if (reg == null) throw new ArgumentNullException("reg");
reg.Register(sf => factoryFunc(sf));
}
}
var n = 1234;
var array = map(n.toString().split(''), parseInt);