Skip to content

Instantly share code, notes, and snippets.

View akimboyko's full-sized avatar
🙃

Akim Boyko akimboyko

🙃
View GitHub Profile
@akimboyko
akimboyko / IronPythonScript.cs
Last active April 19, 2016 13:50
Simple performance and readability test: RoslynScript vs. IronPython from C# Performance ratio 1:2,7-3 Readability: both scripting engines required some knowledge about underlying APIs
async void Main()
{
GetType().Assembly.FullName.Dump();
IEnumerable<Model.ProcessingModel> models =
Enumerable.Range(0, 1000000)
.Select(n => new Model.ProcessingModel { InputA = n, InputB = n * 0.5M, Factor = 0.050M });
var sw = Stopwatch.StartNew();
using System;
using System.Collections.Generic;
using Autofac;
using Nancy;
using Nancy.Bootstrapper;
using Nancy.Bootstrappers.Autofac;
using Nancy.Hosting.Self;
using Nancy.Routing;
public class Bootstrapper : AutofacNancyBootstrapper
@akimboyko
akimboyko / NinjectNamedConventionOverConfiguration.cs
Last active December 15, 2015 23:09
Ninject Convention-over-configuration: find all implementations of interface in assembly and bind them by name Answer to http://stackoverflow.com/questions/15868820/ninject-conventions-with-ninject-factory-extension-to-bind-multiple-types-to-one
void Main()
{
using(var kernel = new StandardKernel(new CarModule()))
{
kernel.Load<FuncModule>(); // for sake of LinqPAD
var factory = kernel.Get<ICarFactory>();
Assert.That(factory, Is.Not.Null);
@akimboyko
akimboyko / DlrExpressionTreeIL
Created April 10, 2013 06:48
IL generated by RoslynCTP and by DLR expression trees
IL_0037: ldtoken Model.ProcessingModel
IL_003C: call System.Type.GetTypeFromHandle
IL_0041: call System.Linq.Expressions.Expression.Parameter
IL_0046: stloc.2 // modelParameter
IL_0047: ldtoken Model.ReportModel
IL_004C: call System.Type.GetTypeFromHandle
IL_0051: call System.Linq.Expressions.Expression.Parameter
IL_0056: stloc.3 // resultExpression
IL_0057: ldc.i4.4
IL_0058: newarr System.Linq.Expressions.Expression
@akimboyko
akimboyko / JsEvalSample.html
Created April 16, 2013 22:13
#Metaprogramming via scripting JavaScropt sample from 'Metaprogramming in .NET' by Kevin Hazzard and Jason Bock and C# script eval using Roslyn CTP
<!DOCTYPE html>
<!--
Metaprogramming via scripting
from book 'Metaprogramming in .NET'
by Kevin Hazzard and Jason Bock
http://www.manning.com/hazzard/
-->
<html>
<head>
<script type="text/javascript">
@akimboyko
akimboyko / CallingMethodDynamicaly.cs
Last active December 16, 2015 08:29
Analyze using RoslynCTP DLR 'dynamic' and CallSites. See readme.md for description
// assume I have somewhere 'dynamic' code like,
dynamic x = 10;
// … some code …
Console.WriteLine(Math.Sqrt(x)); // DLR call site is not expected in current solution
@akimboyko
akimboyko / JavaScriptEval.html
Created April 21, 2013 09:12
JavaScript eval() vs. Roslyn.Scripting
<!DOCTYPE html>
<!--
Metaprogramming via scripting
from book 'Metaprogramming in .NET'
by Kevin Hazzard and Jason Bock
http://www.manning.com/hazzard/
-->
<html>
<head>
<script type="text/javascript">
void Main()
{
var mapping = new AutoMapperConfiguration();
mapping.SelfTest();
mapping.Map<Person, PersonDTO>(new Person { FullName = "Ola Hansen" }).Dump();
mapping.Map<Turtle, TurtleDTO>(new Turtle { NickName = "Tortilla" }).Dump();
}
public class AutoMapperConfiguration
@akimboyko
akimboyko / GameOfLife.cs
Created May 1, 2013 19:30
Yet another Conway's Game of Life implementation using immutable collection from `Microsoft.Bcl.Immutable` and all game related algorithms are implemented using `LINQ to Objects`. See details https://github.com/akimboyko/DojoConwaysGameOfLife
public static ImmutableHashSet<Cell> Next(ImmutableHashSet<Cell> generation)
{
return ImmutableHashSet.Create(
generation
.AsParallel()
.AsUnordered()
.SelectMany(cell =>
new[]
{
new { alive = false, x = cell.X - 1, y = cell.Y - 1, density = 1 },
@akimboyko
akimboyko / AppDomainNCrunch.json
Last active December 17, 2015 04:59
Compare AppDomain settings between NCrunch and ReSharper test runners
Expected: null
But was: "{
"DomainManager": null,
"Evidence": [
{
"SecurityZone": 0
},
{
"Value": "file:///C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/IDE/Extensions/Remco Software/NCrunch for Visual Studio 2012/nCrunch.TaskRunner.DLL"
}