Skip to content

Instantly share code, notes, and snippets.

View ntr's full-sized avatar

Nikita Trush ntr

  • google
  • Seattle, WA
View GitHub Profile
@ntr
ntr / x.fs
Last active August 29, 2015 14:08
type Header = All | None
type Includer = Incl | Excl
type RuleSet =
| BeginWith of Header
| Rule of Includer*(string -> bool)
| Combine of RuleSet * RuleSet
let inline (+?) x y = Combine(x, Rule(Incl,y))
let inline (-?) x y = Combine(x, Rule(Excl,y))
[<EntryPoint>]
let main argv =
let text = "awesome great this text is so exciting! this is disgusting sentence number two.";
let modelsDir = @"C:\tmp\stanford-corenlp-full-2014-06-16\models";
let analyzer = makeSentimentAnalyzer modelsDir
printfn "%A" (analyzer text)
0 // return an integer exit code
open System
open System.IO
open edu.stanford.nlp.ling
open edu.stanford.nlp.neural.rnn
open edu.stanford.nlp.sentiment
open edu.stanford.nlp.trees
open edu.stanford.nlp.util
open java.util
open edu.stanford.nlp.pipeline
@ntr
ntr / gettingFunctionName.fs
Last active August 29, 2015 14:02
Getting function name
let getFunctionName f =
let type' = f.GetType()
let method' = type'.GetMethods() |> Array.find (fun m -> m.Name="Invoke")
let il = method'.GetMethodBody().GetILAsByteArray()
let methodCodes = [byte OpCodes.Call.Value;byte OpCodes.Callvirt.Value]
let position = il |> Array.findIndex(fun x -> methodCodes |> List.exists ((=)x))
let metadataToken = BitConverter.ToInt32(il, position+1)
let actualMethod = type'.Module.ResolveMethod metadataToken
public static IContainer ConfigureContainer()
{
var builder = new ContainerBuilder();
builder.RegisterType<Worker>();
builder.RegisterModule(new TypedLoggersInjector(new LogFactory()));
return builder.Build();
}
public static void TestInjection()
{
public class TypedLoggersInjector : Module
{
private readonly LogFactory logFactory_;
public TypedLoggersInjector(LogFactory logFactory)
{
logFactory_ = logFactory;
}
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
@ntr
ntr / container.cs
Created February 26, 2013 18:27
autof_container
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class TypedLoggerAttribute : Attribute
{
}
[TypedLogger]
public class Worker
{
private readonly Logger logger_;
@ntr
ntr / test2.cs
Created December 10, 2012 11:16
test2
private static SyntaxNode GetListCollectionInitializerElements(ElementAccessExpressionSyntax node)
{
return null;
}
@ntr
ntr / test.cs
Created December 10, 2012 11:15
test
public static List<ExpressionSyntax> GetListCollectionInitializerElements(ElementAccessExpressionSyntax node)
{
}
@ntr
ntr / fslist.fs
Created December 2, 2012 17:05
f# list
let myList = [1;2;3]