Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using LangExt;
namespace LangExt.Guard
{
public static class Control
{
public static int[] QuickSort(int[] arr)
{
if (!arr.Any()) return new int[] { };
var p = arr.First();
var xs = arr.Skip(1);
var lesser = xs.Where(x => x < p).ToArray();
var greater = xs.Where(x => x >= p).ToArray();
return (QuickSort(lesser).Concat(new[] { p }).Concat(QuickSort(greater))).ToArray();
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace Option2
{
public class Placeholder
{
@otf
otf / Processor.cs
Created April 16, 2013 11:30
最適化されたAndAlsoとOrElseを正しく解釈する
Instruction ConditionalBranch(Instruction instruction, Func<Expression, BinaryExpression> condition)
{
var val1 = stack.Pop();
var test = condition(val1);
var left = (Instruction)instruction.Operand;
var right = instruction.Next;
Instruction common = GetJoinPoint(left, right);
@otf
otf / il.md
Last active December 16, 2015 06:58
こんな感じの関数```return FirstName != null && IsActive;```

Debug時

{IL_0000: nop}
{IL_0001: ldarg.0}
{IL_0002: call System.String get_FirstName()}
{IL_0007: brfalse.s IL_0011}
{IL_0009: ldarg.0}
{IL_000a: call Boolean get_IsActive()}
{IL_000f: br.s IL_0012}
{IL_0011: ldc.i4.0}
@otf
otf / checknullable.cs
Last active December 15, 2015 18:59
型がnull許容かどうかしらべる
Expression.Lambda<Func<object>>(Expression.Convert(Expression.Default(t),typeof (object))).Compile()() == null
-- disable referential integrity
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
GO
EXEC sp_MSForEachTable 'TRUNCATE TABLE ?'
GO
-- enable referential integrity again
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
GO
let rec move (x, y) r g n =
if x < 0 || y < 0 || x > g || y > g then n
elif (x,y) = (g, g) then n + 1
else match List.tryFind ((=) (x, y)) r with
| Some _ -> n
| None ->
[(x + 1, y); (x, y + 1); (x - 1, y); (x, y - 1)]
|> List.map (fun xy -> move xy ((x, y)::r) g)
|> List.fold (|>) n
type LogicalCallContextEvent<'T>() =
let id = Guid.NewGuid()
member this.Publish = this :> IDelegateEvent<Handler<'T>>
member this.Trigger(arg:'T) =
if CallContext.LogicalGetData(id.ToString()) <> null then
(CallContext.LogicalGetData(id.ToString()) :?> Handler<'T>).Invoke(this, arg)
interface IDelegateEvent<Handler<'T>> with
@otf
otf / gist:3586997
Created September 1, 2012 20:55
ThreadLocalEvent
type ThreadLocalEvent<'T>() =
let handlers = new ThreadLocal<Handler<'T>>()
member this.Publish = this :> IDelegateEvent<Handler<'T>>
member this.Trigger(arg:'T) =
if handlers.Value <> null then
handlers.Value.Invoke(this, arg)
interface IDelegateEvent<Handler<'T>> with