Skip to content

Instantly share code, notes, and snippets.

View markryd's full-sized avatar

Mark Rydstrom markryd

  • Brisbane, Australia
View GitHub Profile
@markryd
markryd / shiftkeytraingwheels.ahk
Created October 14, 2012 12:11
Shift key training wheels as per http://stevelosh.com/blog/2012/10/a-modern-space-cadet/ using Autohotkey
<+q::RETURN
<+w::RETURN
<+e::RETURN
<+r::RETURN
<+t::RETURN
<+a::RETURN
<+s::RETURN
<+d::RETURN
<+f::RETURN
<+g::RETURN
$LShift::
$RShift::
Key := SubStr(A_ThisHotkey,2)
Send, {%Key% Down}
KeyWait, %Key%
Send, {%Key% Up}
If ( A_PriorHotkey == A_ThisHotkey )
SendRaw, % InStr(Key,"L") ? "(" : ")"
Return
@markryd
markryd / Reactive Extensions
Last active December 16, 2015 12:08
Reactive Extensions
Observable
.FromEventPattern<PropertyChangedEventArgs>(this, "PropertyChanged")
.Where(e => e.EventArgs.PropertyName == "FilterText")
.Throttle(TimeSpan.FromMilliseconds(500))
.Subscribe(e => FilterItems());
@markryd
markryd / Building expressions
Last active December 16, 2015 19:29
Building expressions
//Original
var param = Expression.Parameter(typeof(string), "p");
var len = Expression.PropertyOrField(param, "Length");
var body = Expression.Equal(
len, Expression.Constant(5));
var lambda = Expression.Lambda<Func<string, bool>>(
body, param);
//Updated
@markryd
markryd / memprofiling.md
Last active August 22, 2016 18:36
Memory profiling with windbg
  • Start up windbg and attach (F6).
  • Make sure you pick the right version (x86/x64) and run as admin if your app is running as admin.
  • Make sure you have the microsoft symbol servers turned on in Visual Studio -> tools -> options -> debugging -> symbols

Load

.loadby sos clr

Dump the heap

@markryd
markryd / Rx events
Created August 5, 2013 00:45
Build and filter an event stream using Rx
Items = new List<FacetViewModel<T>>(names.Select(n => CreateFacetViewModel(n, displayExpression, filterExpression)));
var negatedName = Framework.Common.Extensions.ExpressionExtensions.GetPropertyName<FacetWidget<T>, bool>(f => f.Negate);
var isCheckedName = Framework.Common.Extensions.ExpressionExtensions.GetPropertyName<FacetViewModel<T>, bool>(f => f.IsChecked);
//get isChecked change event from all items
var itemIsCheckedEvents = Items.Select(
i => Observable.FromEventPattern<PropertyChangedEventHandler, PropertyChangedEventArgs>
(h => i.PropertyChanged += h, h => i.PropertyChanged -= h)
.Where(p => p.EventArgs.PropertyName == isCheckedName));
@markryd
markryd / lol.xaml
Created September 11, 2013 03:26
These basically do the same thing
<Border Background="Red" BorderThickness="1" BorderBrush="LightGreen"/>
<Rectangle Fill="Red" StrokeThickness="1" Stroke="LightGreen"/>
@markryd
markryd / RxPropertyChanged.cs
Created September 17, 2013 23:47
Rx property changed
ColumnSettings.Values.Select(c => Observable.FromEventPattern<PropertyChangedEventHandler, PropertyChangedEventArgs>
(h => c.PropertyChanged += h, h => c.PropertyChanged -= h))
.Merge()
.Throttle(TimeSpan.FromMilliseconds(1000))
.Subscribe(e => _updateSettingsAction.Execute(null));
@markryd
markryd / composition.cs
Created February 17, 2014 00:20
Mapping from the domain with expressions and function composition
void Main()
{
var h = Compose(Domain.ToContract, Herp.FromContract);
var mapped = Contacts.Select(h);
mapped.Dump();
}
public class Domain
{
//maintain a mapping to our public contract classes
@markryd
markryd / spinner.xaml
Created July 23, 2014 10:23
A Xaml spinner template with a polar gradient
<ControlTemplate x:Key="BusyIndicatorProgressBarControlTemplate" TargetType="telerik:RadProgressBar">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Determinate"/>
<VisualState x:Name="Indeterminate">
<Storyboard RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="IndeterminateDonut" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)">
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="360"/>
</DoubleAnimationUsingKeyFrames>