Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexander Shvedov controlflow

View GitHub Profile
@controlflow
controlflow / gist:2868357
Created Jun 4, 2012 — forked from leppie/gist:2868328
CallWithEscapeContinuation
View gist:2868357
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 Dec 20, 2015
99 Prolog problems :: solutions 1.01 - 1.28
View gist:6206209
% 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 Dec 22, 2015
WCF Data Services Task-based async query API-extension
View gist:6418329
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
{
View gist:7661990
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 Dec 5, 2013
How C# lambdas with a single ref-type immutable closure can be optimized
View gist:7804901
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 Dec 30, 2015
Boolean solver via C# overload resolution
View gist:7846397
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 {
View gist:8072635
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)
{
...
View gist:8212650
class C
{
void M(int[] xs)
{
var firstTime = true;
foreach (var x in xs)
{
// меня так раздражает тратить столько строк и целый блок на такую конструкцию
if (firstTime)
{
@controlflow
controlflow / gist:8214142
Created Jan 2, 2014
Value type + readonly field...
View gist:8214142
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 Jan 3, 2016
YourProjectFileName.csproj.DotSettings
View 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>