Skip to content

Instantly share code, notes, and snippets.

View alexander-williamson's full-sized avatar

Alexander Williamson alexander-williamson

View GitHub Profile
@alexander-williamson
alexander-williamson / GetExecutableFromPath.cs
Created December 21, 2016 17:11
Find matching files PATH environment variable folders
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;
@alexander-williamson
alexander-williamson / pubsub.js
Last active May 28, 2017 19:06
RequireJs jQuery
// 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 () {
@alexander-williamson
alexander-williamson / Recurse.cs
Created September 22, 2016 09:26
Simple LinqPad example to hit an endpoint
// 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 ();
using System;
using System.Threading;
namespace Alexw.RunningConsoleApp
{
public class Program
{
static readonly ManualResetEvent QuitEvent = new ManualResetEvent(false);
static void Main(string[] args)
@alexander-williamson
alexander-williamson / patiently.rb
Created July 6, 2016 16:38 — forked from avanderberg/patiently.rb
retry wrapper for cucumber steps
def patiently(&block)
cycles = 0
begin
yield
rescue => e
cycles += 1
sleep 0.1
if cycles < 10
retry
else
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)