Skip to content

Instantly share code, notes, and snippets.

@a-h
a-h / OxyPlotExtensions.cs
Last active August 29, 2015 14:13
OxyPlot Extension Methods
public static class OxyPlotExtensions
{
public static void AddScatterSeries(this PlotModel model, IEnumerable<double> xSeries, IEnumerable<double> ySeries)
{
model.AddScatterSeries(xSeries, ySeries, OxyColors.Automatic);
}
public static void AddScatterSeries(this PlotModel model, IEnumerable<double> xSeries, IEnumerable<double> ySeries, OxyColor color)
{
var scatterSeries = new ScatterSeries()
@a-h
a-h / ExampleUsage.cs
Created January 16, 2015 09:54
OxyPlotExtensions Example Usag
void Main()
{
var model = new PlotModel { Title = "Test" };
var xseries = new double[] { 1, 2, 3 };
var yseries1 = new double[] { 1, 2, 3 };
var yseries2 = new double[] { 0.5, 1, 1.5 };
model.AddScatterSeries(xseries, yseries1, OxyColors.Red);
model.AddHighlightedPoint(2.5, 2.5, OxyColors.Blue);
@a-h
a-h / TermFrequencyInverseDocumentFrequency.cs
Created January 28, 2015 11:33
Term Frequency - Inverse Document Frequency (Tf-Idf)
using LemmaSharp;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
@a-h
a-h / NinjectWebCommon.cs
Created March 17, 2015 10:35
How to get better performance when creating WCF clients using ChannelFactory<T>
private static void RegisterServices(IKernel kernel)
{
// The ProxyGenerator is part of Castle and will emit code at runtime. This code needs to be cached
// or there will be zero improvement in performance. It's cached by default, per instance of the
// ProxyGenerator.
kernel.Bind<ProxyGenerator>()
.ToConstant(new ProxyGenerator());
// The ChannelFactoryCache will cache the creation of the ChannelFactory, which is slow because it
// requires the use of reflection.
@a-h
a-h / ToWcfClientExtensions.cs
Created March 17, 2015 10:42
ChannelFactory Cache and the Ninject Binding Extension Method
// Modified from examples at luisfsgoncalves.wordpress.com/2012/02/28/mixin-up-ninject-castle-dynamic-proxy-and-wcf-part-iii/
// to use a channel factory cache.
public static class ToWcfClientExtensions
{
public static IBindingWhenInNamedWithOrOnSyntax<T> ToWcfClient<T>(this IBindingToSyntax<T> syntax) where T : class
{
return syntax.ToMethod(ctx => ctx.Kernel
.Get<ProxyGenerator>()
.CreateInterfaceProxyWithoutTarget<T>(new WcfProxyWithDisposalInterceptor<T>()));
}
@a-h
a-h / PerlinNoise.cs
Created March 27, 2015 14:36
Perlin Noise LinqPad Script
void Main()
{
// Uses Oxyplot.WindowsForms.
var noise = new PerlinNoise();
var results = new List<double>();
for(double i = 0.0d; i < 100; i += 0.01d)
{
results.Add(noise.Noise(i));
}
@a-h
a-h / SparkLinesHub.cs
Created April 19, 2015 14:33
Caching Data in a SignalR Hub and Limiting Publisher Rights by Using a Password
namespace SparkLines.Hubs
{
public class SparklinesHub : Hub
{
static ConcurrentDictionary<string, List<int>> Values = new ConcurrentDictionary<string, List<int>>();
static int maximumValues = 49;
public void PublishMetric(string name, int value)
{
@a-h
a-h / SignalR.js
Created April 19, 2015 14:36
SignalR Client-Side Publishing Code
$.connection.hub.proxies.sparklineshub.server.publishMetric("noise", 1000)
@a-h
a-h / gist:437d5e7846126be91768
Last active August 29, 2015 14:20
Migrating from Ninject to Simple Injector (WCF)
// Ninject
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
// Singleton
kernel.Bind<ILog>().ToMethod(c => LogManager.GetLogger(typeof(ProjectService))).InSingletonScope();
// WCF Scope
@a-h
a-h / NinjectWebCommon.cs
Last active August 29, 2015 14:20
Ninject to Simple Injector
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(Service.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(Service.App_Start.NinjectWebCommon), "Stop")]
// Once it's building, rename the class away from Ninject.
public static class NinjectWebCommon
{
// -- Ninject
// private static readonly Bootstrapper bootstrapper = new Bootstrapper();
public static void Start()