Skip to content

Instantly share code, notes, and snippets.

View tpetrina's full-sized avatar
🐜
ant is a hard-working bug. be like ant queen - spawn more workers!

Toni Petrina tpetrina

🐜
ant is a hard-working bug. be like ant queen - spawn more workers!
View GitHub Profile
@tpetrina
tpetrina / extensions.cs
Created September 13, 2012 12:48
Similar to SelectMany method, only projects members
public static IEnumerable<U> SelectProjections<T, U>(this IEnumerable<T> @this, params Func<T, U>[] projections)
{
if (@this == null)
throw new NullReferenceException();
if (projections == null || !projections.Any())
yield break;
foreach (var item in @this)
{
foreach (var projection in projections)
@tpetrina
tpetrina / DirectXHelper.h
Created July 30, 2012 21:02
Asynchronous file loading for Metro styled applications using DirectX/C++
inline Concurrency::task<Platform::String^> ReadStringAsync(Platform::String^ filename)
{
using namespace Windows::Storage;
using namespace Concurrency;
auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
task<StorageFile^> getFileTask(folder->GetFileAsync(filename));
auto readBufferTask = getFileTask.then([] (StorageFile^ f)
@tpetrina
tpetrina / DataServiceAsyncExtensions
Created April 1, 2012 17:28
Wrappers for asynchronous operations exposed by DataServiceQuery<T> and DataServiceContext
// Use in VS11 and .NET 4.5 or in VS10 with the Async CTP installed
//
namespace DataServiceAsyncExtensions
{
using System;
using System.Collections.Generic;
using System.Data.Services.Client;
using System.Threading.Tasks;
@tpetrina
tpetrina / CompilerServicesExtensions
Created March 30, 2012 19:45
Attribute types definitions for using C# 5 caller info attributes in projects targeting earlier frameworks i.e. before .NET 4.5
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
public sealed class CallerMemberNameAttribute : Attribute
{
public CallerMemberNameAttribute()
{ }
}
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]