Skip to content

Instantly share code, notes, and snippets.

View svick's full-sized avatar

Petr Onderka svick

View GitHub Profile
@svick
svick / CallerInfoAttibuteNet4.cs
Created October 9, 2014 08:29
How to use caller info attributes on .Net 4.0
using System;
using System.Runtime.CompilerServices;
namespace System.Runtime.CompilerServices
{
class CallerMemberNameAttribute : Attribute
{ }
}
namespace ConsoleApplication1
@svick
svick / Program.cs
Last active August 29, 2015 14:08
Proving that the Task dispatching loop doesn't wait for thread scheduling quantum
using System;
using System.Diagnostics;
using System.Threading.Tasks;
class Program
{
private static void Main()
{
MainAsync().Wait();
}
@svick
svick / any.cpp
Last active August 29, 2015 14:10
Any
any_of(list.begin(), list.end(), [](SomeType x){ return predicate(x); })
@svick
svick / TimeUnits.cs
Last active August 29, 2015 14:10
C# 6.0 simple time units
using System;
using TimeUnits;
public static class Program
{
public void Main()
{
Console.WriteLine(70.5 * s);
}
}
@svick
svick / Action.il
Created February 7, 2015 23:59
Delegate with static member
.assembly ActionTest {}
.assembly extern mscorlib
{
.ver 4:0:0:0
.publickeytoken = (B7 7A 5C 56 19 34 E0 89)
}
.namespace Test
{
using System;
static class Program
{
private static void Main()
{
Intermediary<C>();
Console.WriteLine();
Intermediary<S>();
}
@svick
svick / Program.cs
Created March 9, 2015 20:20
C# 6.0 FormattableString on .Net 4.0
using System;
using System.Globalization;
static class Program
{
private static void Main()
{
double d = 3.14;
IFormattable s = $"{d}";
Console.WriteLine(s.ToString(null, CultureInfo.GetCultureInfo("cs-cz")));
@svick
svick / gist:8c2696222800aa031450
Last active August 29, 2015 14:20
It's not safe to call ToList on IsReadOnly collection
var cdict = new ConcurrentDictionary<int, int>();
var t = Task.Run(() => {
for (int i = 0; i < 100000; i++)
cdict[i] = i;
});
IEnumerable<KeyValuePair<int, int>> kvps = new ReadOnlyDictionary<int, int>(cdict);
((ICollection<KeyValuePair<int, int>>)kvps).IsReadOnly.Dump(); // true
@svick
svick / Program.cs
Created May 5, 2015 18:46
Improved Activator
using System;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection.Emit;
namespace ConsoleApplication1
{
class Program
{
@svick
svick / Program.cs
Created May 13, 2015 23:08
Incorrect compiler error for method with async/non-async delegate overloads
using System;
using System.Threading.Tasks;
class Program
{
static void M(Func<Task<int>> f, int i)
{ }
static void M(Func<int> f, int i)
{ }