Skip to content

Instantly share code, notes, and snippets.

@shiftkey
shiftkey / gist:770803
Created January 8, 2011 12:45
Thought - Simpler XAML Markup
# place to put click handlers
@Code Application.Views.MainView
# by default, textblocks use this style and do TextWrapping="Wrap"
@Default TextBlock Style="{DefaultFontStyle}" Wrap
# by default, Button uses this style
@Default Button Style="{DefaultButtonStyle}"
# tab indent represents child items
PhoneApplicationPage
Grid
@shiftkey
shiftkey / WP7 - Memory Profiling Hijinks
Created February 4, 2011 01:50
Investigating memory usage of a trivial Panorama-based WP7 application.
// Scenario:
// Start with default WP7 Panorama application, two tabs each with listbox
// Added child page with panorama control, two tabs each with listbox
// Two ViewModels (Main and Child), each has a list of 270+ items
// No relationship between the ViewModels. Lazy-loaded data in-memory
Main - OnNavigatedTo - ApplicationCurrentMemoryUsage: 8036352
Main - OnNavigatedTo - ApplicationPeakMemoryUsage: 8048640
Main - Loaded - ApplicationCurrentMemoryUsage: 39870464
@shiftkey
shiftkey / Memory Usage for WP7 App
Created February 5, 2011 03:37
A longer running test for navigating between two screens of a WP7 app
Main - OnNavigatedTo - ApplicationCurrentMemoryUsage: 8036352
Main - OnNavigatedTo - ApplicationPeakMemoryUsage: 8048640
Main - Loaded - ApplicationCurrentMemoryUsage: 39862272
Main - Loaded - ApplicationPeakMemoryUsage: 39899136
Main - OnNavigatedFrom - ApplicationCurrentMemoryUsage: 51990528
Main - OnNavigatedFrom - ApplicationPeakMemoryUsage: 52760576
Child - OnNavigatedTo - ApplicationCurrentMemoryUsage: 51990528
// here's the C# code we have to use
namespace Application
{
public class Factory
{
public T Get<T>(string parameter) where T : Proxy
{
return default(T);
}
@shiftkey
shiftkey / ObservableCollection Overloads
Created April 19, 2011 11:18
Comparing the behaviour between IEnumerable<T> and List<T>
public ObservableCollection(IEnumerable<T> collection)
{
this._monitor = new SimpleMonitor<T>();
if (collection == null)
{
throw new ArgumentNullException("collection");
}
this.CopyFrom(collection);
}
@shiftkey
shiftkey / WAVEHDR
Created June 18, 2011 10:29
Example of a struct implemented as a class in C#
// Example of a struct implementation for passing in information about a WAVE file
// http://msdn.microsoft.com/en-us/library/aa446573.aspx
/// <summary>
/// This structure defines the header used to identify a waveform-audio buffer.
/// typedef struct
/// {
/// LPSTR lpData;
/// DWORD dwBufferLength;
/// DWORD dwBytesRecorded;
@shiftkey
shiftkey / SessionService.cs
Created July 4, 2011 05:20
Faking a service call using Caliburn Micro Coroutines
using System;
using System.ComponentModel.Composition;
using System.Windows.Threading;
using Caliburn.Micro;
namespace CaliburnMicroSample.Services
{
[Export(typeof(ISessionService))]
public class SessionService : ISessionService
{
@shiftkey
shiftkey / Program.cs
Created August 9, 2011 04:02
This is how you use TPL to crash your host process - don't ask me why you would use it in this way....
static void Main(string[] args)
{
try
{
var factory = new TaskFactory();
var task = factory.StartNew(() => { throw new Exception(); });
task.Wait();
}
catch (Exception ex)
{
@shiftkey
shiftkey / gist:1161138
Created August 21, 2011 20:51
Some Tools
Visual Studio 2010 SP1
http://www.microsoft.com/download/en/details.aspx?id=23691
Fiddler
http://www.getfiddler.com/dl/Fiddler2BetaSetup.exe
Silverlight Spy
http://firstfloorsoftware.com/silverlightspy/download-silverlight-spy
Expression Blend
@shiftkey
shiftkey / gist:1178225
Created August 29, 2011 11:32
Enumerating Fun and Games in Ruby
# all i wanted to do was this with what I thought was
# an Enumerable set of posts using Jekyll
{% for ps in site.posts.skip(3) %}
<!-- partial view -->
{% endfor %}
# but i couldn't work out what type site.posts was at runtime
# ( using .class didn't output anything
# i stumbled (literally) across this alternate syntax which works