Skip to content

Instantly share code, notes, and snippets.

View akimboyko's full-sized avatar
🙃

Akim Boyko akimboyko

🙃
View GitHub Profile
@akimboyko
akimboyko / gist:4538388
Created January 15, 2013 12:45
Ninject Contextual Binding for different environments
void Main()
{
// create kernel with conventions
using(var kernel = InitializeKernel())
{
var backend = kernel.Get<IBackend>();
Assert.That(backend, Is.Not.InstanceOfType(typeof(ProdBackend))
.And.InstanceOfType(typeof(TestBackend)));
}
@akimboyko
akimboyko / gist:4258647
Created December 11, 2012 13:41
PowerShell exception re-throwing sample
Write-Host 'throw'
try
{
try
{
throw "exception"
}
catch
{
@akimboyko
akimboyko / 01_SayHello.fsx
Last active May 28, 2023 13:00
Samples from "Actor-based Concurrency with F# and Akka.NET" http://bit.ly/FSharpAkkaNET
#time "on"
#load "Bootstrap.fsx"
open System
open Akka.Actor
open Akka.Configuration
open Akka.FSharp
open Akka.TestKit
// #Using Actor
@akimboyko
akimboyko / gist:4622557
Last active February 23, 2022 07:11
Custom scope for Ninject that returns same instance based on first constructor argument. Using both kernel and factory
void Main()
{
using(var kernel = new StandardKernel(new Module()))
{
kernel.Load<FuncModule>(); // for sake of LinqPAD
var instance1 = kernel.Get<MyClass>(new ConstructorArgument("myArg", "test"));
var instance2 = kernel.Get<MyClass>(new ConstructorArgument("myArg", "test"));
Assert.That(instance1, Is.Not.Null.And.SameAs(instance2));
@akimboyko
akimboyko / simple_tcp_server_with_SO_REUSEPORT.py
Last active April 23, 2019 17:29
Let's play with a simple TCP server with SO_REUSEPORT
import socket
import sys
from contextlib import contextmanager
import click
so_reuseport = socket.SO_REUSEPORT
@contextmanager
@akimboyko
akimboyko / FsCheckSamples.fsx
Last active March 27, 2019 08:04
Samples for Property-based testing using FsCheck for F# and C# talk for Kiev Alt.NET
#I @".\packages\FsCheck.0.9.2.0\lib\net40-Client\"
#r @"FsCheck.dll"
// #time "on"
open FsCheck
// simple example
let revRevIsOrig (xs:list<int>) = List.rev(List.rev xs) = xs
Check.Quick revRevIsOrig;;
@akimboyko
akimboyko / gist:4457261
Created January 4, 2013 21:47
AOP: handwritten tracing decorator
void Main()
{
TraceDecorator.Aspect(() => StaticLogic.SuccessfulCall());
TraceDecorator.Aspect(() => StaticLogic.ExceptionCall());
TraceDecorator.Aspect(() => StaticLogic.SuccessfulCallWithReturn(42)).Dump();
TraceDecorator.Aspect(() => StaticLogic.ExceptionCallWithReturn(42)).Dump();
}
public static class TraceDecorator
{
@akimboyko
akimboyko / Howto.md
Last active February 2, 2019 00:02
Scripting: `eval()`-like for C# using Roslyn and ScriptCS
  • Install Chocolatey
  • Reopen console application (for example cmd.exe) to update %PATH% and other environment variables
  • Install ScriptCs using chocolatey
  • Save both Roslyn-EvalSample.csx and packages.config
  • Install dependencies using scriptcs -install
  • Run scriptcs .\Roslyn-EvalSample.csx
@akimboyko
akimboyko / 1readme.md
Last active October 22, 2018 08:45
ScriptCs as embedded scripting engine for .Net application with NuGet support

ScriptCs as embedded scripting engine for .Net application with NuGet support

This gist contains:

  • ExecuteScriptCs.cs — class that are able to execute ScriptCs from another .Net application
  • ScriptModule.cs — AutoFac configuration for ScriptCs/NuGet dependencies
  • Program.cs — command-line example
  • Sample.csx — sample ScriptCs script
  • packages.config — NuGet packages configuration
@akimboyko
akimboyko / gist:4530162
Created January 14, 2013 13:48
How to intercept method with custom attribute using DynamicProxy
void Main()
{
ProxyGenerator proxyGenerator = CreateProxyGenerator();
IService proxy =
proxyGenerator
.CreateInterfaceProxyWithTargetInterface(new Service() as IService, new TracingInterceptorAspect());
proxy.ProcessRequest();