Skip to content

Instantly share code, notes, and snippets.

View droyad's full-sized avatar

Robert Wagner droyad

View GitHub Profile
@droyad
droyad / gist:6602748
Created September 18, 2013 00:26
Scale image
var size = image.Size;
var aspectRatio = size.Width / size.Height;
var newSize = aspectRatio > 1
? new SizeF(maxHeightOrWidth, maxHeightOrWidth / aspectRatio)
: new SizeF(maxHeightOrWidth * aspectRatio, maxHeightOrWidth);
var all = @"// redacted";
var firstLetters = all
.Split('\n')
.Select(n => n.Trim().ToUpper())
.Select(n => n.Substring(n.IndexOf(" ") + 1)[0]);
var counts = from l in firstLetters
group l by l into g
select new
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)
@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");
@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: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: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
//Psudo C#
public class Program(IDb db)
{
_db = db;
void Main()
{
var results = _db.Query(new FooQuery().From(DateTime.Today).ForUser("doe"));
}
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 != ""