Skip to content

Instantly share code, notes, and snippets.

View jrwren's full-sized avatar
💭
🤯💯👍🔥🎉🤷‍♀️😍😕🕴🏽😵😞🤕🤮

Jay R. Wren jrwren

💭
🤯💯👍🔥🎉🤷‍♀️😍😕🕴🏽😵😞🤕🤮
View GitHub Profile
@jrwren
jrwren / gist:638625
Created October 21, 2010 15:02 — forked from trek/gist:638615
def some_method(a, b, c=5, *p, q)
if (q) c=7
other_method(a,b,c,p,q)
end
def other_method(a, b, c=4, *p, q)
end
@jrwren
jrwren / gist:1040405
Created June 22, 2011 15:51
trying to get dispatcher to run in nunit test :[
[TestFixture]
public class DispatcherObjectIsAJerk
{
[SetUp]
public void Setup()
{
var task = System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Windows.Threading.Dispatcher.Run();
});
@jrwren
jrwren / gist:1043608
Created June 23, 2011 20:54
nasty DP hax for databinding
void GlobalVariablesGrid_ColumnFix()
{
foreach (var column in GlobalVariablesGrid.Columns)
{
if ("Name".Equals(column.Header))
{
var dpd = System.ComponentModel.DependencyPropertyDescriptor.FromProperty(DataGridColumn.WidthProperty, typeof(DataGridColumn));
if (dpd != null)
{
@jrwren
jrwren / gist:1045322
Created June 24, 2011 18:04
You are stupid exception.
/// <summary>
/// The exception that is thrown when you are stupid.
/// </summary>
[Serializable]
public class YouAreStupidException : Exception
{
// constructors...
#region YouAreStupidException()
/// <summary>
/// Constructs a new YouAreStupidException.
@jrwren
jrwren / gist:1051362
Created June 28, 2011 15:16
not smart I.f so i can => I.f( pred, do)
public static class I { public static void f(Func<bool> pred, Action a) { if (pred()) a(); } }
// so that I can use it like this:
dg.CurrentCellChanged += (_, __) =>
I.f(()=>rowBeingEdited!=null, ()=>rowBeingEdited.EndEdit())
using System;
using NUnit.Framework;
namespace scratch
{
[TestFixture()]
public class Test
{
[Test()]
public void TestCase ()
{
@jrwren
jrwren / gist:1136018
Created August 10, 2011 03:16
dynamic
public static class DynamicExt
{
public static Dictionary<object, DynamicObject> registry = new Dictionary<object, DynamicObject>();
public static dynamic AsDynamic(this object source)
{
if (!registry.ContainsKey(source))
registry[source] = new DynamicObject(source);
return registry[source];
}
}
@jrwren
jrwren / gist:1137431
Created August 10, 2011 17:03
unfold a datareader.
public virtual List<CreditUnion> ExecuteF(Func<System.Data.IDataReader, CreditUnion> map)
{
var command = _database.GetStoredProcCommand("GETALLA2A");//ENTLIB?
_database.AddInParameter(command, "mode", System.Data.DbType.String, "M");
var list = new List<CreditUnion>();
using (var reader = _database.ExecuteReader(command))
//turn Read into a generator... e.i unfold
@jrwren
jrwren / gist:1149398
Created August 16, 2011 15:49
why not have some helpful two way XElement, strings maps :)
public static IEnumerable<System.Xml.Linq.XElement> ToXElement(this IEnumerable<string> source, string tag = "Value")
{
return source.Select(s => new System.Xml.Linq.XElement(tag, s));
}
public static IEnumerable<string> ToStrings(this System.Xml.Linq.XElement source, string tag = "Value")
{
return source.Elements("Value").Select(e => (string)e);
}
@jrwren
jrwren / gist:1149419
Created August 16, 2011 15:59
I just want to write pretty code... NullToEmpty
public static IEnumerable<T> NullToEmpty<T>(this IEnumerable<T> source)
{
if (source==null)
return new T[]{};
return source;
}