Skip to content

Instantly share code, notes, and snippets.

Testing cached delegate wireup Event Handler Performance with 1,000,000 iterations
Time to build handler cache 3 ms or 6,548 ticks
Completed 1,000,000 iterations in 7,434 ms
Average Time is 0 ms or 14 ticks
Press enter to exit
public void SkipObject(Stream stream)
{
var reader = new BinaryReader(stream);
stream.Position += reader.ReadInt32();
}
@caleb-vear
caleb-vear / badway.cs
Created February 19, 2011 11:35
Put your behaviour where it belongs
// This could just as easily be a command handler in a view model
private void AcceptButton_Clicked(object sender, EventArgs e)
{
if (CurrentNetWeight <= 0)
throw new Exception("Can not accept weights that <= 0");
Load.GrossWeight = GrossWeight;
Load.TareWeight = TareWeight;
Load.NetWeight = CurrentNetWeight;
Load.WeightAcceptedTime = DateTime.Now;
@caleb-vear
caleb-vear / ExampleConfig.xml
Created April 7, 2011 02:30
Sample code for a blog post I wrote about: WPF Bindings Not Updating When PropertyChanged Raised When Bound Against a Proxy Object
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="YourAppName">
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.connection_string">
Server=(local);initial catalog=nhibernate;Integrated Security=SSPI
</property>
<property name="proxyfactory.factory_class"> YouProjectNameSpace.FixDataBindingProxyFactoryFactory, YourProjectAssembly</property>
</session-factory>
</hibernate-configuration>
@caleb-vear
caleb-vear / debugblock.cs
Created April 20, 2011 00:37
Just found and removed this from a method I was investigating the performance of.
// debug block
try
{
compiledTransform.Load(doc);
}
catch (Exception ex)
{
string msg = ex.Message
}
@caleb-vear
caleb-vear / Output
Created August 21, 2011 06:30
Sample of GuessWho c# library
First 2 male names
Steve Ashcraft
Christopher Timothy Bischoff
First 2 female names
Denise Jan Dellinger
Brigida Carpenter
First 2 all names
Ivan Brent Duffey
@caleb-vear
caleb-vear / RunWithElevatedPrivilegesExample.cs
Created August 28, 2011 09:41
Example of SPSecurity.RunWithElevatedPrivileges
public void YourMethod()
{
SPSecurity.RunWithElevatedPrivileges(() =>
{
using (var site = new SPSite(Request.Url.ToString()))
{
// Your work goes here...
}
});
}
@caleb-vear
caleb-vear / Codebehind.cs
Created August 28, 2011 10:01
Custom SharePoint site menu
protected readonly List<SubSite> SubSites = new List<SubSite>();
protected void Page_PreRender(object sender, EventArgs e)
{
var siteMap = PortalSiteMapProvider.GlobalNavSiteMapProvider;
var rootNode = siteMap.TryGetRootNode;
SubSites.Add(new SubSite()
{
@caleb-vear
caleb-vear / rx.cs
Created September 19, 2011 23:37
RX Example
public IDisposable SubscribeToK2WorkflowUpdatesFor<T>(
IEnumerable<T> data,
Action<T, K2Activity> activitySetter,
Func<T, string> k2ProcessIdSelector,
int interval)
{
var itemsToRefresh = Observable
.Interval(TimeSpan.FromSeconds(interval), Scheduler.ThreadPool)
.SelectMany(l => data)
.Synchronize()
@caleb-vear
caleb-vear / example-with-comma.patch
Created September 27, 2011 08:29
Always user a comma
var array = new []
{
"Hello",
+ "World",
};