Skip to content

Instantly share code, notes, and snippets.

View controlflow's full-sized avatar

Alexander Shvedov controlflow

View GitHub Profile
@controlflow
controlflow / gist:2868357
Created June 4, 2012 13:25 — forked from leppie/gist:2868328
CallWithEscapeContinuation
using System;
class Program
{
sealed class EscapeContinuation<T> : Exception
{
public T Value { get; private set; }
public void Raise(T value)
{
@controlflow
controlflow / gist:6206209
Last active December 20, 2015 22:38
99 Prolog problems :: solutions 1.01 - 1.28
% problem 1.01
my_last(X, [X]).
my_last(X, [_|TL]) :- my_last(X, TL).
% problem 1.02
last_but_one(X, [X, _]).
last_but_one(X, [_,Y|TL]) :- last_but_one(X, [Y|TL]).
% problem 1.03
element_at(X, [X|_], 1).
@controlflow
controlflow / gist:6418329
Last active December 22, 2015 04:38
WCF Data Services Task-based async query API-extension
using System;
using System.Collections.Generic;
using System.Data.Services.Client;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace Blah
{
using System;
using System.Collections.Generic;
using System.Linq;
static class Program {
static void Main() {
var xs = EnumerableEx.Create<int>(async yield => {
try {
await yield.Return(42);
} finally {
@controlflow
controlflow / gist:7804901
Created December 5, 2013 13:10
How C# lambdas with a single ref-type immutable closure can be optimized
using System;
static class LiftingClosureToDelegateTarget {
static void Main() {
// normal lambda
{
var str = GetString();
Func<string> f = () => str;
Console.WriteLine(f());
}
@controlflow
controlflow / gist:7846397
Last active December 30, 2015 15:09
Boolean solver via C# overload resolution
static class BooleanSolver {
class T {
public static T operator |(T x, T y) => null;
public static T operator |(T x, F y) => null;
public static T operator &(T x, T y) => null;
public static F operator &(T x, F y) => null;
public static F operator !(T x) => null;
}
class F {
@controlflow
controlflow / gist:8072635
Last active January 1, 2016 01:28
Primary ctors
class ReverseForLookupItem : ForLookupItemBase
{
public ReverseForLookupItem([NotNull] PrefixExpressionContext context,
[NotNull] LiveTemplatesManager templatesManager,
[CanBeNull] string lengthPropertyName)
: base("forR", context, templatesManager, lengthPropertyName) { }
protected override IForStatement CreateStatement(CSharpElementFactory factory, ICSharpExpression expression)
{
...
class C
{
void M(int[] xs)
{
var firstTime = true;
foreach (var x in xs)
{
// меня так раздражает тратить столько строк и целый блок на такую конструкцию
if (firstTime)
{
@controlflow
controlflow / gist:8214142
Created January 2, 2014 02:34
Value type + readonly field...
using System;
public struct S {
int _value;
public S(int value) { _value = value; }
public int Value { get { return _value; } }
public void Mutate() { _value++; }
}
public class C {
@controlflow
controlflow / YourProjectFileName.csproj.DotSettings
Last active January 3, 2016 03:09
YourProjectFileName.csproj.DotSettings
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ExpressionIsAlwaysNull/@EntryIndexedValue">DO_NOT_SHOW</s:String>
</wpf:ResourceDictionary>