Skip to content

Instantly share code, notes, and snippets.

@khellang
khellang / ScrollViewer.xaml
Created June 4, 2012 13:22
ScrollViewerMaxSizeBehavior
<ScrollViewer Style="{StaticResource AppHost_ScrollViewer}">
<Interactivity:Interaction.Behaviors>
<custom:ScrollViewerMaxSizeBehavior MinContentWidth="600"
MinContentHeight="500"/>
</Interactivity:Interaction.Behaviors>
<!-- content -->
</ScrollViewer>
public class DecimalModelBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var valueResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
var modelState = new ModelState { Value = valueResult };
object actualValue = null;
if (string.IsNullOrEmpty(valueResult.AttemptedValue))
@khellang
khellang / WpfScriptPackSamples.cs
Last active December 15, 2015 23:29
Sample usage for WPF Script Pack
// --- First example
public class MyApplication : Application
{
private readonly Window _mainWindow;
public MyApplication(Window mainWindow)
{
_mainWindow = mainWindow;
}
@khellang
khellang / gruntFile.js
Created May 11, 2013 15:29
Example GruntFile
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-recess');
grunt.loadNpmTasks('grunt-testacular');

With the following files in bin:

  • ScriptCs.FooPack.dll
  • ScriptCs.Contracts.dll

Yields the following output:

INFO : Starting to create execution components
INFO : Starting execution
Hello from Foo!
INFO : Finished execution

if (!pipelines.AfterRequest.PipelineItems.Any(x => x.Name.Equals(SaveAndDisposeItemName)))
{
pipelines.AfterRequest.AddItemToEndOfPipeline(
new PipelineItem<Action<NancyContext>>(
SaveAndDisposeItemName,
ctx => DisposeSession(container)));
}
public class Bootstrapper : DefaultNancyBootstrapper
{
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
{
pipelines.OnError.AddItemToEndOfPipeline((ctx, ex) =>
{
var exception = ex.GetRootException();
return ctx.Negotiate().WithModel(new Error
{
public static class NegotiateExtensions
{
public static Negotiator WithCrazyModel(this Negotiator negotiator, object model)
{
return negotiator
.WithMediaRangeModel(MediaRange.FromString("application/foo"), new FooWrapper(model))
.WithMediaRangeModel(MediaRange.FromString("application/bar"), new BarWrapper(model));
}
}
using System.Text.RegularExpressions;
private const string DelimiterRegex = @"\[(.*?)\]";
public int Add(string numbers)
{
if (string.IsNullOrEmpty(numbers)) return 0;
var delimiters = new List<string> { "," };
protected override void RequestStartup(ILifetimeScope container, IPipelines pipelines, NancyContext context)
{
pipelines.AfterRequest.AddItemToEndOfPipeline(ctx =>
{
if (ctx.Response.StatusCode != HttpStatusCode.InternalServerError)
{
container.Resolve<DbContext>().SaveChanges();
}
});
}