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 UnixTimestamp | |
| { | |
| private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); | |
| public static double Convert(this DateTime dateTime) | |
| { | |
| return dateTime.Subtract(Epoch).TotalMilliseconds; | |
| } | |
| public static DateTime Convert(this double offset) |
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
| def patiently(&block) | |
| cycles = 0 | |
| begin | |
| yield | |
| rescue => e | |
| cycles += 1 | |
| sleep 0.1 | |
| if cycles < 10 | |
| retry | |
| else |
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; | |
| using System.Threading; | |
| namespace Alexw.RunningConsoleApp | |
| { | |
| public class Program | |
| { | |
| static readonly ManualResetEvent QuitEvent = new ManualResetEvent(false); | |
| static void Main(string[] args) |
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
| // Needs System.Net; | |
| // Prefer HttpClient for real situations other than testing | |
| void Main() | |
| { | |
| while(true) { | |
| try { | |
| var url = "http://example.com/sub/dir/page.aspx?a=1234&b=something"; | |
| var request = (System.Net.HttpWebRequest) System.Net.WebRequest.Create (url); | |
| var response = (System.Net.HttpWebResponse)request.GetResponse (); |
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
| // tinypubsub: | |
| // https://gist.github.com/cowboy/661855 | |
| // code assumes you have shimmed jquery with the correct version in requirejs config: | |
| // http://requirejs.org/docs/jquery.html#modulename | |
| define(["jquery"], function (jQuery) { | |
| var o = jQuery({}); | |
| jQuery.subscribe = function () { |
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 IEnumerable<string> GetExecutableFromPaths(string fileName) | |
| { | |
| var path = Environment.GetEnvironmentVariable("PATH"); | |
| var pathFolders = path.Split(';'); | |
| foreach (var folder in pathFolders) | |
| { | |
| var fullPath = Path.Combine(folder, fileName); | |
| if (File.Exists(fullPath)) | |
| yield return fullPath; |
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
| # Your use statement can do all the work for you | |
| app.Use(async (context, next) => | |
| { | |
| if (!IsAuthenticated(context)) | |
| { | |
| context.Response.StatusCode = 401; | |
| var bytes = System.Text.Encoding.UTF8.GetBytes("You are not authorised!"); | |
| context.Response.Body.Write(bytes, 0, bytes.Length); | |
| await Task.FromResult(context); |
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
| /// <summary> | |
| /// Loop until a condition is met and your function returns true | |
| /// </summary> | |
| /// <param name="action">The delegate to run. Return true to exit the loop.</param> | |
| /// <param name="delay">Return a timespan for the delay between loops</param> | |
| /// <param name="whentoStop">Return true when the loop should stop when catching exceptions or looping</param> | |
| public static void DoUntil(Func<bool> action, Func<int, TimeSpan, TimeSpan> delay, Func<int, TimeSpan, bool> whentoStop) | |
| { | |
| var startedUtc = DateTime.UtcNow; | |
| var amountOfRetriesAllowed = 0; |
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; | |
| using System.Net.Sockets; | |
| // taken from https://stackoverflow.com/questions/138043/find-the-next-tcp-port-in-net | |
| public static class TcpPorts | |
| { | |
| public static int GetFreeTcpPort() | |
| { | |
| var l = new TcpListener(IPAddress.Loopback, 0); |
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; | |
| using System.Net; | |
| using RestSharp; | |
| namespace Alexw.ParkingAvailable | |
| { | |
| public class KibanaClient | |
| { | |
| private readonly IRestClient _client; | |
| private readonly string _token; |
OlderNewer