A Pen by Ronnie Overby on CodePen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void SetupRouting(HttpConfiguration config) | |
| { | |
| config.Routes.MapHttpRoute("proxy_else", "{*uri}", new | |
| { | |
| controller = "Proxy", | |
| uri = RouteParameter.Optional | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}"))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Privates() { | |
| var map = new WeakMap(); | |
| return function (obj) { | |
| if (!map.has(obj)) | |
| map.set(obj, {}); | |
| return map.get(obj); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| onmessage = function(msg) { | |
| // TODO: long running code that uses msg.data to figure out answer to everything | |
| postMessage(42); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var n = 1234; | |
| var array = map(n.toString().split(''), parseInt); |