Skip to content

Instantly share code, notes, and snippets.

View droyad's full-sized avatar

Robert Wagner droyad

View GitHub Profile
@droyad
droyad / gist:b0d54c08578fc8fb21b1
Created August 8, 2014 01:14
Long FormUrlEncodedContent
//IEnumerable<KeyValuePair<string, string>> serializedParameters
// Do this instead of using FormUrlEncodedContent as it only supports url escaping of strings shorter than 30,000 (or 60,000)
// Would use MultipartFormDataContent but Esri doesn't look like it accepts that
var pars = string.Join("&", serializedParameters.Select(p => p.Key + "=" + Encode(p.Value)));
var content = new ByteArrayContent(Encoding.ASCII.GetBytes(pars));
content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
var message = await client.PostAsync(url, content);
return await message.Content.ReadAsStringAsync();
Lazy<int> _lazy;
void Main()
{
_lazy = new Lazy<int>(CreateInt);
for(int x = 0; x < 10; x++)
{
new Thread(Run).Start();
}
}
class ObjectSettingsReader : ISettingsReader
{
private readonly Dictionary<string, string> _values;
public ObjectSettingsReader(object obj)
{
var q = from p in obj.GetType().GetProperties()
where p.CanRead
let v = "" + p.GetValue(obj)
where v != ""
//Psudo C#
public class Program(IDb db)
{
_db = db;
void Main()
{
var results = _db.Query(new FooQuery().From(DateTime.Today).ForUser("doe"));
}
@droyad
droyad / gist:8553563
Created January 22, 2014 04:38
Array based Game of Life
let initField x y s =
match (x,y) with
| (1,1) | (1, 2) | (1,3) -> true
| _ -> false
let valueAt (f:bool[,]) c =
match c with
| (x,y) when x < 0 -> false
@droyad
droyad / gist:8292852
Created January 7, 2014 00:54
Add to Glimpse Timeline
using (Timeline.Capture("FormulaEvaluator.Evalauate"))
{
// Code to time
}
public static class Timeline
{
public static IDisposable Capture(string eventName)
{
#pragma warning disable 618
@droyad
droyad / gist:8000065
Created December 17, 2013 04:31
CombiningSettingsReader
public class CombiningSettingsReader : ISettingsReader
{
private readonly ISettingsReader[] _settingsReaders;
public CombiningSettingsReader(params ISettingsReader[] settingsReaders)
{
_settingsReaders = settingsReaders;
}
public string ReadValue(string key)
@droyad
droyad / gist:7763181
Created December 3, 2013 02:52
PropertyInfo to Expression
void Main()
{
var propertyInfo = typeof(A).GetProperty("Foo");
var lambda = Get<A>(propertyInfo);
lambda.Compile()(new A()).Dump();
}
public Expression<Func<T, int>> Get<T>(PropertyInfo propertyInfo)
{
ParameterExpression entity = Expression.Parameter(typeof (A), "e");
namespace IBM
{
public class DeepThought
{
private static void Main(string[] args)
{
new DeepThought("What is the answer to life, the universe and everything?");
}
private DeepThought(Setting<QuestionConfigurationSetting, string> question)
namespace IBM
{
public class DeepThought
{
private static void Main(string[] args)
{
new DeepThought("What is the answer to life, the universe and everything?");
}
private DeepThought(Setting<QuestionConfigurationSetting, string> question)